def load_replay(replay):
    try:
        protobuf_game = FileManager.get_proto(replay)
        data_frame = FileManager.get_pandas(replay)
        return protobuf_game, data_frame
    except:
        return None, None
Esempio n. 2
0
    def create_from_id(id_: str) -> 'ReplayHeatmaps':
        df = FileManager.get_pandas(id_)
        protobuf_game = FileManager.get_proto(id_)

        id_to_name_map = {p.id.id: p.name for p in protobuf_game.players}
        if protobuf_game.teams[0].is_orange:
            orange_team = protobuf_game.teams[0]
        else:
            orange_team = protobuf_game.teams[1]
        orange = [id_to_name_map[pl.id] for pl in orange_team.player_ids]
        counts = [[] for a in range(FULL_BOOST_POSITIONS.shape[0])]
        players = list(df.columns.levels[0])
        players.remove("ball")
        players.remove("game")
        for player in players:
            player_df = df[player]
            boost_pickup_frames = player_df[player_df.boost_collect ==
                                            True].index.values
            for frame in boost_pickup_frames:
                try:
                    position = player_df.iloc[frame].loc[['pos_x', 'pos_y']]
                except:
                    continue
                distances_from_boosts = np.sqrt(
                    np.square(FULL_BOOST_POSITIONS - position.values).sum(
                        axis=1, dtype=np.float32))
                idx: int = np.argmin(distances_from_boosts)
                counts[idx].append(
                    BoostPickup(player, int(player in orange),
                                int(frame)).__dict__)
        return counts
Esempio n. 3
0
def api_v1_get_replay_info(id_):
    proto = FileManager.get_proto(id_)

    response = Response(response=convert_proto_to_json(proto),
                        status=200,
                        mimetype='application/json')

    return response

    game = session.query(Game).filter(Game.hash == id_).first()
    data = {
        'datetime': proto.datetime,
        'map': proto.map,
        'mmrs': game.mmrs,
        'ranks': game.ranks,
        'name': proto.name,
        'hash': game.hash,
        'version': proto.replay_version,
        'id': proto.id,
        'frames': len(proto.frames)
    }
    data = player_interface(data, proto, game.mmrs, game.ranks)
    data = team_interface(data, proto)
    data = score_interface(data, proto)
    data = goals_interface(data, proto)
    return jsonify(data)
 def get_protobuf_stats(self, id_: str) -> List[DatabaseObjectDataPoint]:
     game_proto = FileManager.get_proto(id_)
     players = game_proto.players
     stat_output = []
     for player in players:
         player_stats = get_proto_values(player.stats,
                                         self.soccer_player_stats)
         stat_output.append(
             DatabaseObjectDataPoint(
                 player.id.id, player.name, player.is_orange,
                 dict(zip(self.soccer_field_names, player_stats))))
     return stat_output
    def create_from_id(id_: str, query_params=None) -> 'ReplayPositions':
        filter_frames = None
        filter_frame_start = None
        filter_frame_count = None
        if query_params is not None and 'frame' in query_params:
            filter_frames = query_params['frame']
        if query_params is not None and 'frame_start' in query_params and 'frame_count' in query_params:
            filter_frame_start = query_params['frame_start']
            filter_frame_count = query_params['frame_count']

        data_frame = FileManager.get_pandas(id_)
        if filter_frames is not None:
            data_frame = ReplayPositions.filter_frames(filter_frames, data_frame)
        if filter_frame_start is not None and filter_frame_count is not None:
            data_frame = ReplayPositions.filter_frames_range(filter_frame_start, filter_frame_count, data_frame)
        protobuf_game = FileManager.get_proto(id_)

        cs = ['pos_x', 'pos_y', 'pos_z']
        rot_cs = ['rot_x', 'rot_y', 'rot_z']

        ball = data_frame['ball']
        ball_df = ball[cs].fillna(-100)

        players = protobuf_game.players
        names = [player.name for player in players]

        def process_player_df(game) -> List[ReplayPlayer]:
            player_data = []
            for player in names:
                data_frame[player].loc[:, rot_cs] = data_frame[player][rot_cs] / 65536.0 * 2 * 3.14159265
                data_frame[player].loc[:, 'pos_x'] = data_frame[player]['pos_x']
                data_frame[player].loc[:, 'pos_y'] = data_frame[player]['pos_y']
                data_frame[player].loc[:, 'pos_z'] = data_frame[player]['pos_z']
                player_positions = data_frame[player][cs + rot_cs + ['boost_active']].fillna(-100)
                player_data.append(player_positions.values.tolist())
            return player_data

        players_data = process_player_df(protobuf_game)
        game_frames = data_frame['game'][['delta', 'seconds_remaining', 'time']].fillna(-100)

        return ReplayPositions(
            id_=id_,
            ball=ball_df.values.tolist(),
            players=players_data,
            colors=[player.is_orange for player in players],
            names=[player.name for player in players],
            frames=game_frames.values.tolist()
        )
Esempio n. 6
0
    def create_from_id(self):
        protobuf_game = FileManager.get_proto(self.replay_id)
        kickoffs = protobuf_game.game_stats.kickoff_stats
        player_map = create_player_map(protobuf_game)
        kickoff_list = [
            self.get_stats_from_kickoff(kickoff, player_map)
            for kickoff in kickoffs
        ]

        player_list = {
            player.id.id: {
                "name": player.name,
                "is_orange": player.is_orange
            }
            for player in protobuf_game.players
        }

        kickoff_data = {"players": player_list, "kickoffs": kickoff_list}
        return kickoff_data
Esempio n. 7
0
    def create_from_id(id_: str,
                       type_=HeatMapType.POSITIONING) -> 'ReplayHeatmaps':
        data_frame = FileManager.get_pandas(id_)
        protobuf_game = FileManager.get_proto(id_)
        # output = generate_heatmaps(data_frame, protobuf_game, type="hits")
        width = 400 / 500
        step = 350.0
        # x_range = 4.05*10**3
        # y_range = 5.1*10**3
        x_range = 4.05 * 10**3
        y_range = 6.1 * 10**3
        x_bins = np.arange(-x_range, x_range, step)
        y_bins = np.arange(-y_range, y_range, step)

        output = generate_heatmaps(data_frame,
                                   protobuf_game,
                                   type_=type_,
                                   bins=[x_bins, y_bins])
        data = {}
        maxs = {}
        # for player in output:
        #     arr = output[player]
        #     player_data = []
        #     for x in range(len(arr[0])):
        #         for y in range(len(arr[0][x])):
        #             player_data.append({
        #                 'x': math.floor(arr[1][x] * 200 / 6000 + 250),
        #                 'y': math.floor(arr[2][y] * 200 / 6000 + 250),
        #                 'value': max(0, math.log(arr[0][x, y] + 1e-3))
        #             })
        #             max_ = max(math.log(arr[0][x, y] + 1e-3), max_)
        #     data[player] = player_data
        #     maxs[player] = max_
        if type_ == HeatMapType.HITS:
            return {'data': output, 'maxs': maxs}

        if type_ in [HeatMapType.HITS]:
            log_scale = False
        else:
            log_scale = True

        for player in output:
            max_ = 0
            arr = output[player]
            player_data = []
            for x in range(len(arr[0])):
                for y in range(len(arr[0][x])):
                    if arr[0][x, y] == 0:
                        continue
                    if log_scale:
                        value = math.log(arr[0][x, y] + 1e-3)**1.8
                    else:
                        value = arr[0][x, y]
                    player_data.append({
                        'x':
                        math.floor(arr[1][x] * width * 200 / 6000 + 130),
                        'y':
                        math.floor(arr[2][y] * width * 200 / 6000 + 180),
                        'value':
                        max(0, value)
                    })
                    max_ = max(value, max_)
            data[player] = player_data
            maxs[player] = max_

        return {'data': data, 'maxs': maxs}