def data_loop_mode(): from pprint import pprint from player.parser.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 fix_pressure_possession_values(): from player.parser.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
def parse_total_boost(): from player.parser.parser.frames import get_frames from player.parser.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 player.parser.parser.frames import get_frames from player.parser.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 player.parser.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 render_video(render_type, out_frame_rate=30, overlay=None, extra_cmd=None): import os import subprocess from player.parser.render.do_render import get_video_prefix from player.parser.parser.frames import get_frames from player.parser.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 parse_pressure(): from player.parser.parser.frames import get_frames from player.parser.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 data_explorer_cli(): from pprint import pprint from player.parser.data.data_loader import get_data from player.parser.data.actor_data import get_actor_data from player.parser.data.object_numbers import \ get_player_info, team0, team1 from player.parser.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)