Ejemplo n.º 1
0
import os
import json

_json_name = output_path = sys.argv[2] + '.tmp'

_json = carball.decompile_replay(sys.argv[1], _json_name, overwrite=True)

game = Game()
game.initialize(loaded_json=_json)

analysis = AnalysisManager(game)
analysis.create_analysis(calculate_intensive_events=False)

_output_tmp_name = sys.argv[2] + "-" + 'tmp' + ".json"
with open(_output_tmp_name, 'w') as out:
    analysis.write_json_out_to_file(out)

with open(_output_tmp_name) as tmp:
    data = json.load(tmp)
    time = data['gameMetadata']['time']
    _output_name = sys.argv[2] + "-" + time + ".json"

os.rename(_output_tmp_name, _output_name)

if os.path.exists(_json_name):
    os.remove(_json_name)
else:
    print("The file do not exist")

print(_output_name)
Ejemplo n.º 2
0
 def test(analysis: AnalysisManager):
     with NamedTemporaryFile(mode='w') as f:
         analysis.write_json_out_to_file(f)
Ejemplo n.º 3
0
 def test(analysis: AnalysisManager):
     with NamedTemporaryFile(mode='wb') as f:
         with pytest.raises(IOError):
             analysis.write_json_out_to_file(f)
Ejemplo n.º 4
0
def main(program_args=None):
    parser = argparse.ArgumentParser(
        description='Rocket League replay parsing and analysis.')
    parser.add_argument(
        '-i',
        '--input',
        type=str,
        required=True,
        help=
        'Path to replay file that will be analyzed. Carball expects a raw replay file unless '
        '--skip-decompile is provided.')
    parser.add_argument(
        '--proto',
        type=str,
        required=False,
        help=
        'The result of the analysis will be saved to this file in protocol buffers format.'
    )
    parser.add_argument(
        '--json',
        type=str,
        required=False,
        help=
        'The result of the analysis will be saved to this file in json file format. This is not '
        'the decompiled replay json from rattletrap.')
    parser.add_argument(
        '--gzip',
        type=str,
        required=False,
        help=
        'The pandas data frame containing the replay frames will be saved to this file in a '
        'compressed gzip format.')
    parser.add_argument(
        '-sd',
        '--skip-decompile',
        action='store_true',
        default=False,
        help=
        'If set, carball will treat the input file as a json file that Rattletrap outputs.'
    )
    parser.add_argument(
        '-v',
        '--verbose',
        action='count',
        default=0,
        help=
        'Set the logging level to INFO. To set the logging level to DEBUG use -vv.'
    )
    parser.add_argument('-s',
                        '--silent',
                        action='store_true',
                        default=False,
                        help='Disable logging altogether.')
    parser.add_argument(
        '-dr',
        '--dry-run',
        action='store_true',
        default=False,
        help=
        'Explicitly notifying that there is not going to be any output to be saved'
    )
    if program_args is not None:
        args = parser.parse_args(program_args)
    else:
        args = parser.parse_args()

    if not args.proto and not args.json and not args.gzip and not args.dry_run:
        parser.error(
            'at least one of the following arguments are required: --proto, --json, --gzip'
        )

    log_level = logging.WARNING

    if args.verbose == 1:
        log_level = logging.INFO
    elif args.verbose >= 2:
        log_level = logging.DEBUG

    if args.silent:
        logging.basicConfig(handlers=[logging.NullHandler()])
    else:
        logging.basicConfig(handlers=[logging.StreamHandler()],
                            level=log_level)

    if args.skip_decompile:
        game = Game()
        game.initialize(loaded_json=args.input)
        manager = AnalysisManager(game)
        manager.create_analysis()
    else:
        manager = carball.analyze_replay_file(args.input)

    if args.proto:
        with open(args.proto, 'wb') as f:
            manager.write_proto_out_to_file(f)
    if args.json:
        with open(args.json, 'w') as f:
            manager.write_json_out_to_file(f)
    if args.gzip:
        with gzip.open(args.gzip, 'wb') as f:
            manager.write_pandas_out_to_file(f)