Exemplo n.º 1
0
def convert_replay(replay_path: str, out_folder: str) -> Dict:
    '''
    Parses the replay file intro proto and pandas. 
    
    Returns a dictionary with keys ['proto', 'pandas'] with the paths
    to each file.
    '''
    id = os.path.splitext(os.path.basename(replay_path))[0]
    proto_path = os.path.join(out_folder, '{}.pts'.format(id))
    pandas_path = os.path.join(out_folder, '{}.gzip'.format(id))

    temp_path = tempfile.mktemp(suffix='.json')

    _json = carball.decompile_replay(replay_path, temp_path)

    game = Game()
    game.initialize(loaded_json=_json)
    analysis = AnalysisManager(game)
    analysis.create_analysis()

    with open(proto_path, 'wb') as f:
        analysis.write_proto_out_to_file(f)

    with open(pandas_path, 'wb') as f:
        analysis.write_pandas_out_to_file(f)

    return {'proto': proto_path, 'pandas': pandas_path}
def write_replay_to_disk(analysis_manager: AnalysisManager, parsed_data_path: str):
    # Temp write file to the original filename location
    if not os.path.isdir(os.path.dirname(parsed_data_path)):
        os.makedirs(os.path.dirname(parsed_data_path))
    with open(parsed_data_path + '.pts', 'wb') as fo:
        analysis_manager.write_proto_out_to_file(fo)
    with gzip.open(parsed_data_path + '.gzip', 'wb') as fo:
        analysis_manager.write_pandas_out_to_file(fo)
Exemplo n.º 3
0
def main():
    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.')
    args = parser.parse_args()

    if not args.proto and not args.json and not args.gzip:
        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:
        proto_game = manager.get_protobuf_data()
        with open(args.json, 'w') as f:
            f.write(MessageToJson(proto_game))
    if args.gzip:
        with gzip.open(args.gzip, 'wb') as f:
            manager.write_pandas_out_to_file(f)
Exemplo n.º 4
0
 def test(analysis: AnalysisManager):
     with NamedTemporaryFile(mode='w') as f:
         with pytest.raises(IOError):
             analysis.write_pandas_out_to_file(f)
Exemplo n.º 5
0
 def test(analysis: AnalysisManager):
     with NamedTemporaryFile(mode='wb') as f:
         analysis.write_pandas_out_to_file(f)
Exemplo n.º 6
0
 def test(analysis: AnalysisManager):
     with NamedTemporaryFile(mode='wb') as f:
         gzip_file = gzip.GzipFile(mode='wb', fileobj=f)
         analysis.write_pandas_out_to_file(gzip_file)