예제 #1
0
def get_match_info(data):
    try:
        # some files seems broken for this library when using the `Summary`.
        m = parse_match(data)
        players = [dict(name=p.name, user_id=p.profile_id, number=p.number, civilization=p.civilization) for p in m.players]

        return dict(
            map_name=m.map.name,
            game_version=f"{m.version.name} {m.version.value}",
            game_map_type=m.type,
            players=players,
            teams=m.teams,
            completed=False,
            start_time_seconds=str(m.actions[0].timestamp.seconds),
            duration_seconds=m.duration.seconds,
        )
    except RuntimeError:
        # the `parse_match` method doesn't work for restored recordings, thus, let's try with the `Summary`.
        s = Summary(data)

        return dict(
            map_name=s.get_map()['name'],
            game_version=" ".join(str(x) for x in s.get_version()),
            game_map_type=s.get_settings()['type'][1],
            players=s.get_players(),
            teams=s.get_teams(),
            completed=s.get_completed(),
            start_time_seconds=int(s.get_start_time()/1000),
            duration_seconds=int(s.get_duration()/1000),
        )
예제 #2
0
def print_info(path):
    """Print basic info."""
    with open(path, 'rb') as handle:
        header = mgz.header.parse_stream(handle)
        handle.seek(0)
        summary = Summary(handle)
        dataset = summary.get_dataset()
        print('-------------')
        print(
            tabulate(
                [
                    ['Path', path],
                    [
                        'Duration',
                        mgz.util.convert_to_timestamp(
                            summary.get_duration() / 1000)
                    ],
                    ['Completed', summary.get_completed()],
                    ['Restored', header.initial.restore_time > 0],
                    ['Postgame', bool(summary.get_postgame())],
                    ['Version', mgz.const.VERSIONS[header.version]],
                    [
                        'Dataset', '{} {}'.format(dataset['name'],
                                                  dataset['version'])
                    ],
                    ['Hash', summary.get_hash().hexdigest()],
                    ['Encoding', summary.get_encoding()],
                    ['Map', summary.get_map()['name']]  # pylint: disable=unsubscriptable-object
                ],
                tablefmt='plain'))
예제 #3
0
파일: cli.py 프로젝트: diogoalmeida/aoc-mgz
def print_info(path):
    """Print basic info."""
    with open(path, 'rb') as handle:
        header = mgz.header.parse_stream(handle)
        handle.seek(0)
        summary = Summary(handle)
        dataset = summary.get_dataset()
        print('-------------')
        print(
            tabulate(
                [
                    ['Path', path],
                    [
                        'Duration',
                        mgz.util.convert_to_timestamp(
                            summary.get_duration() / 1000)
                    ],
                    ['Completed', summary.get_completed()],
                    ['Restored', header.initial.restore_time > 0],
                    ['Postgame', bool(summary.get_postgame())],
                    ['Objects',
                     bool(summary.get_objects()['objects'])],
                    [
                        'Version', '{} ({}, {}, {})'.format(
                            header.version.name, header.game_version,
                            header.save_version, header.log_version)
                    ],
                    [
                        'Dataset', '{} {}'.format(dataset['name'],
                                                  dataset['version'])
                    ],
                    ['File Hash', summary.get_file_hash()],
                    [
                        'Match Hash',
                        summary.get_hash().hexdigest()
                        if summary.get_hash() else None
                    ],
                    ['Encoding', summary.get_encoding()],
                    ['Language', summary.get_language()],
                    [
                        'Map', '{} ({})'.format(summary.get_map()['name'],
                                                summary.get_map()['seed'])
                    ]  # pylint: disable=unsubscriptable-object
                ],
                tablefmt='plain'))
예제 #4
0
def print_info(path):
    """Print basic info."""
    with open(path, 'rb') as handle:
        summary = Summary(handle)
        dataset = summary.get_dataset()
        print('-------------')
        print(tabulate([
            ['Path', path],
            ['Duration', mgz.util.convert_to_timestamp(summary.get_duration() / 1000)],
            ['Played', datetime.utcfromtimestamp(summary.get_played()) if summary.get_played() else None],
            ['Completed', summary.get_completed()],
            ['Restored', summary.get_restored()[0]],
            ['Postgame', bool(summary.get_postgame())],
            ['Version', '{} ({}, {}, {}, {})'.format(*summary.get_version())],
            ['Dataset', '{} {}'.format(dataset['name'], dataset['version'])],
            ['File Hash', summary.get_file_hash()],
            ['Match Hash', summary.get_hash().hexdigest() if summary.get_hash() else None],
            ['Encoding', summary.get_encoding()],
            ['Language', summary.get_language()],
            ['Map', '{} ({}, {})'.format(summary.get_map()['name'], summary.get_map()['seed'], summary.get_map()['mod_id'])] # pylint: disable=unsubscriptable-object
        ], tablefmt='plain'))