Exemplo n.º 1
0
def get_all_data():
    from rocketleaguereplayanalysis.data.object_numbers import \
        get_player_info
    from rocketleaguereplayanalysis.parser.frames import get_frames
    from rocketleaguereplayanalysis.util.extra_info import get_field_dimensions

    from rocketleaguereplayanalysis.data.object_numbers import team0, team1, \
        get_team_color, get_team_name
    return {
        'team_info': {
            'number': {
                'team0': team0,
                'team1': team1
            },
            'name': {
                'note': 'Not Fully Implemented Yet',
                'team0': get_team_name(team0),
                'team1': get_team_name(team1),
            },
            'color': {
                'note': 'Not Fully Implemented Yet',
                'team0': get_team_color(team0),
                'team1': get_team_color(team1),
            }
        },
        'player_info': get_player_info(),
        'field_size': get_field_dimensions(),
        'frames': get_frames()
    }
def render_video(render_type, out_frame_rate=30, overlay=None, extra_cmd=None):
    import os
    import subprocess

    from rocketleaguereplayanalysis.render.do_render import get_video_prefix
    from rocketleaguereplayanalysis.parser.frames import get_frames
    from rocketleaguereplayanalysis.util.sync import get_sync_time_type

    video_prefix = get_video_prefix()

    cmd = [
        'ffmpeg', '-loop', '1', '-i',
        os.path.join('assets', overlay + '.png'), '-t',
        str(get_frames()[-1]['time'][get_sync_time_type()])
    ]

    cmd += extra_cmd

    cmd += [
        '-r',
        str(out_frame_rate), '-crf', '18', '-pix_fmt', 'yuv420p', '-movflags',
        '+faststart', render_type + '.mp4', '-y'
    ]

    print('FFmpeg Command:', cmd)

    p = subprocess.Popen(cmd, cwd=video_prefix, stderr=subprocess.STDOUT)

    p.communicate()
def fix_pressure_possession_values():
    from rocketleaguereplayanalysis.parser.frames import get_frames

    frames = get_frames()

    for i, frame in enumerate(frames):
        max_pressure = (frames[i]['pressure']['team0'] +
                        frames[i]['pressure']['team1'])

        max_possession = (frames[i]['possession']['team0'] +
                          frames[i]['possession']['team1'])

        if max_pressure > 0:
            frames[i]['pressure']['team0'] = (frames[i]['pressure']['team0'] /
                                              max_pressure)
            frames[i]['pressure']['team1'] = (frames[i]['pressure']['team1'] /
                                              max_pressure)
        else:
            frames[i]['pressure']['team0'] = .5
            frames[i]['pressure']['team1'] = .5

        if max_possession > 0:
            frames[i]['possession']['team0'] = (
                    frames[i]['possession']['team0'] /
                    max_possession)
            frames[i]['possession']['team1'] = (
                    frames[i]['possession']['team1'] /
                    max_possession)
        else:
            frames[i]['possession']['team0'] = .5
            frames[i]['possession']['team1'] = .5
Exemplo n.º 4
0
def data_loop_mode():
    from pprint import pprint
    from rocketleaguereplayanalysis.parser.frames import get_frames

    print('===== Entering Loop Mode =====')
    print('To exit, type exit.')
    user_input2 = input('Press Enter to Continue > ')
    parsed_user_input2 = user_input2.split(' ')

    frames = get_frames()

    if parsed_user_input2 != 'exit':
        for i, frame in enumerate(frames):
            if parsed_user_input2 != 'exit':
                print('=====')
                print('Frame:', i)
                print('=====')

                pprint(frame)

                user_input2 = input('Press Enter to Continue > ')
                parsed_user_input2 = user_input2.split(' ')

                if parsed_user_input2 == 'exit':
                    return
            else:
                return
    else:
        return
def parse_total_boost():
    from rocketleaguereplayanalysis.parser.frames import get_frames
    from rocketleaguereplayanalysis.data.object_numbers import \
        get_player_team_id, get_player_info

    frames = get_frames()
    team0_mod = 0
    team1_mod = 0

    for player_id in get_player_info():
        if get_player_team_id(player_id) == 'team0':
            team0_mod += 1
        elif get_player_team_id(player_id) == 'team1':
            team1_mod += 1

    for i, frame in enumerate(frames):
        frame['total_boost'] = {'team0': 0, 'team1': 0}
        for player_id in frame['cars']:
            if get_player_team_id(player_id):
                frame['total_boost'][get_player_team_id(player_id)] += \
                    frame['cars'][player_id]['boost']

        if team0_mod:
            frame['total_boost']['team0'] = frame['total_boost'][
                                                'team0'] / team0_mod
        if team1_mod:
            frame['total_boost']['team1'] = frame['total_boost'][
                                                'team1'] / team1_mod
def parse_possession():
    from rocketleaguereplayanalysis.parser.frames import get_frames
    from rocketleaguereplayanalysis.util.sync import \
        get_sync_delta_type

    frames = get_frames()

    frames[0]['possession'] = {'team0': 0, 'team1': 0}

    for i, frame in enumerate(frames):
        if frame['ball']['last_hit'] == 0:
            frame['possession'] = {
                'team0': (frames[i - 1]['possession']['team0'] +
                          frame['time'][get_sync_delta_type()]),
                'team1': frames[i - 1]['possession']['team1']}

        elif frame['ball']['last_hit'] == 1:
            frame['possession'] = {
                'team0': frames[i - 1]['possession']['team0'],
                'team1': (frames[i - 1]['possession']['team1'] +
                          frame['time'][get_sync_delta_type()])
            }
        else:
            if i > 0:
                frame['possession'] = {
                    'team0': frames[i - 1]['possession']['team0'],
                    'team1': frames[i - 1]['possession']['team1']
                }
            else:
                frame['possession'] = {'team0': 0, 'team1': 0}
def get_field_dimensions():
    from rocketleaguereplayanalysis.parser.frames import get_frames

    frames = get_frames()

    ball_loc = {'x': [], 'y': []}

    for frame in frames:
        ball_loc['x'].append(frame['ball']['loc']['x'])
        ball_loc['y'].append(frame['ball']['loc']['y'])

    center_x = ball_loc['x'][0]
    center_y = ball_loc['y'][0]

    max_x = max(ball_loc['x'])
    min_x = min(ball_loc['x'])
    x_w = max(max_x - center_x, center_x - min_x) * 2

    max_y = max(ball_loc['y'])
    min_y = min(ball_loc['y'])
    y_w = max(max_y - center_y, center_y - min_y) * 2

    return {
        'ball_loc': ball_loc,
        'center_x': center_x,
        'center_y': center_y,
        'min_x': min_x,
        'min_y': min_y,
        'max_x': max_x,
        'max_y': max_y,
        'x_size': x_w,
        'y_size': y_w,
    }
def write_to_file(file,
                  name,
                  frame_num,
                  filter_type,
                  reinit,
                  value,
                  modify=None):
    from rocketleaguereplayanalysis.parser.frames import get_frames
    from rocketleaguereplayanalysis.data.object_numbers import \
        get_team_color
    from rocketleaguereplayanalysis.util.sync import get_sync_time_type

    file.write(
        str(get_frames()[frame_num]['time'][get_sync_time_type()]) + " " +
        filter_type + "@" + name + " reinit '")

    if reinit:
        for i, reinit_what in enumerate(reinit.keys(), start=1):
            mod_value = value
            if modify:
                for modify_style in modify.keys():
                    if modify_style == 'add':
                        mod_value = mod_value + modify[modify_style]
                    elif modify_style == 'subtract':
                        mod_value = mod_value - modify[modify_style]
                    elif modify_style == 'multiply':
                        mod_value = mod_value * modify[modify_style]
                    elif modify_style == 'divide':
                        mod_value = mod_value / modify[modify_style]
                    elif modify_style == 'mod':
                        mod_value = mod_value % modify[modify_style]
                    elif modify_style == 'replace':
                        for check in modify[modify_style].keys():
                            if check == str(mod_value):
                                mod_value = modify[modify_style][check]
                                break
                    elif modify_style == 'replace_color':
                        mod_value = get_team_color(mod_value)

            file.write(reinit_what + '=' +
                       reinit[reinit_what].format(mod_value))
            if i != len(reinit):
                file.write(":")
            else:
                file.write("';")

        file.write("\n")
def parse_pressure():
    from rocketleaguereplayanalysis.parser.frames import get_frames
    from rocketleaguereplayanalysis.util.sync import \
        get_sync_delta_type

    field_dimensions = get_field_dimensions()
    frames = get_frames()

    frames[0]['pressure'] = {'team0': 0, 'team1': 0}

    for i, frame in enumerate(frames):
        if field_dimensions['ball_loc']['y'][i] > \
                field_dimensions['center_y']:

            frame['pressure'] = {
                'team0': (frames[i - 1]['pressure']['team0'] +
                          frame['time'][get_sync_delta_type()]),
                'team1': frames[i - 1]['pressure']['team1']
            }

        elif field_dimensions['ball_loc']['y'][i] < \
                field_dimensions['center_y']:
            frame['pressure'] = {
                'team0': frames[i - 1]['pressure']['team0'],
                'team1': (frames[i - 1]['pressure']['team1'] +
                          frame['time'][get_sync_delta_type()])
            }

        else:
            if i > 0:
                frame['pressure'] = {
                    'team0': frames[i - 1]['pressure']['team0'],
                    'team1': frames[i - 1]['pressure']['team1']
                }
            else:
                frame['pressure'] = {
                    'team0': 0,
                    'team1': 0
                }
def create_ffmpeg_cmd_files_from_path(path,
                                      filter_type,
                                      reinit=None,
                                      modify=None):
    import functools
    import os

    from rocketleaguereplayanalysis.data.object_numbers import \
        get_player_info
    from rocketleaguereplayanalysis.parser.frames import get_frames
    from rocketleaguereplayanalysis.util.export import get_all_data
    from rocketleaguereplayanalysis.render.do_render import get_video_prefix

    all_data = get_all_data()
    frames = get_frames()
    player_info = get_player_info()

    video_prefix = get_video_prefix()

    name = '-'.join(str(x) for x in path)
    if not os.path.exists(os.path.join(video_prefix)):
        os.makedirs(os.path.join(video_prefix))

    last_val = None

    if 'player_num' in path:
        for player in player_info.keys():

            new_path = list(replace_in_array(path, 'player_num', player))
            new_name = '-'.join(str(x) for x in new_path)

            if os.path.exists(os.path.join(video_prefix, new_name + '.txt')):
                os.remove(os.path.join(video_prefix, new_name + '.txt'))

            with open(os.path.join(video_prefix, new_name + '.txt'), 'a') as f:

                if 'frame_num' in path:
                    for i in range(0, len(frames)):
                        frame_path = list(
                            replace_in_array(new_path, 'frame_num', i))

                        curr_val = functools.reduce(lambda d, key: d[key],
                                                    frame_path, all_data)

                        if curr_val != last_val or i == 0:
                            write_to_file(f, new_name, i, filter_type, reinit,
                                          curr_val, modify)
                        last_val = curr_val
                else:
                    curr_val = functools.reduce(lambda d, key: d[key],
                                                new_path, all_data)
                    write_to_file(f, new_name, 0, filter_type, reinit,
                                  curr_val, modify)

    else:
        if os.path.exists(os.path.join(video_prefix, name + '.txt')):
            os.remove(os.path.join(video_prefix, name + '.txt'))

        with open(os.path.join(video_prefix, name + '.txt'), 'a') as f:
            if 'frame_num' in path:
                for i in range(0, len(frames)):
                    frame_path = list(replace_in_array(path, 'frame_num', i))

                    curr_val = functools.reduce(lambda d, key: d[key],
                                                frame_path, all_data)

                    if curr_val != last_val or i == 0:
                        write_to_file(f, name, i, filter_type, reinit,
                                      curr_val, modify)

                    last_val = curr_val
            else:
                curr_val = functools.reduce(lambda d, key: d[key], path,
                                            all_data)

                write_to_file(f, name, 0, filter_type, reinit, curr_val,
                              modify)
Exemplo n.º 11
0
def data_explorer_cli():
    from pprint import pprint
    from rocketleaguereplayanalysis.data.data_loader import get_data
    from rocketleaguereplayanalysis.data.actor_data import get_actor_data
    from rocketleaguereplayanalysis.data.object_numbers import \
        get_player_info, team0, team1
    from rocketleaguereplayanalysis.parser.frames import get_frames

    print()

    print('Now entering raw data explorer CLI.')
    print("""
    Help:
    
    To see keys for data point:             `keys [key...]`
    To see data for data point:             `data [key...]`
    To see actor data:                      `actor_data`
    To see player info:                     `player_info`
    To see pressure info:                   `pressure_info`
    To see possession info:                 `possession_info`
    To enter source frame loop mode:        `source_loop_mode`
    To enter parsed data frame loop mode:   `data_loop_mode`
    To exit:                                `exit`
    """)

    cont = True

    data = get_data()

    while cont:
        user_input = input('> ').split(' ')

        parsed_input = []
        for in_string in user_input:
            try:
                parsed_input.append(int(in_string))
            except:
                parsed_input.append(in_string)

        if parsed_input[0] == 'keys':
            try:
                show_data = data
                for key in parsed_input[1:]:
                    if key != '':
                        show_data = show_data[key]
                pprint(show_data.keys())
            except KeyError:
                print('Key is not in data')
            except AttributeError:
                print('Key does not have any subkeys')
        elif parsed_input[0] == 'data':
            try:
                show_data = data
                for key in parsed_input[1:]:
                    if key != '':
                        show_data = show_data[key]
                pprint(show_data)
            except KeyError:
                print('Key is not in data')
            except AttributeError:
                print('Key does not have any subkeys')
        elif parsed_input[0] == 'actor_data':
            pprint(get_actor_data())
        elif parsed_input[0] == 'player_info':
            pprint(get_player_info())
        elif parsed_input[0] == 'pressure_info':
            print('Blue:\t', get_frames()[-1]['pressure'][team0])
            print('Orange:\t', get_frames()[-1]['pressue'][team1])
        elif parsed_input[0] == 'possession_info':
            print('Blue:\t', get_frames()[-1]['possession'][team0])
            print('Orange:\t', get_frames()[-1]['possession'][team1])
        elif parsed_input[0] == 'source_loop_mode':
            source_loop_mode()
        elif parsed_input[0] == 'data_loop_mode':
            data_loop_mode()
        elif parsed_input[0] == 'exit':
            cont = False
        else:
            print('Command Not Recognized.')
            print('User Input:  ', user_input)
            print('Parsed Input:', parsed_input)