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
예제 #2
0
def process_loadout_to_obj(game: game_pb2) -> List[Loadout]:
    replay_id = game.game_metadata.match_guid
    if replay_id == '' or replay_id is None:
        replay_id = game.game_metadata.id
    player_objs = game.players

    loadouts = []
    for p in player_objs:
        fields = create_and_filter_proto_field(p, ['name', 'title_id', 'is_orange'],
                                               ['api.metadata.CameraSettings',
                                                'api.PlayerId'], Loadout)
        values = get_proto_values(p, fields)
        kwargs = {k.field_name: v for k, v in zip(fields, values)}
        loadouts.append(Loadout(game=replay_id, player=str(p.id.id)[:40], **kwargs))

    return loadouts
예제 #3
0
def convert_pickle_to_db(
        game: game_pb2,
        offline_redis=None) -> (Game, list, list, List[Loadout]):
    """
    Converts pickled games into various database objects.

    :param game: Pickled game to process into Database object
    :return: Game db object, PlayerGame array, Player array
    """
    teamsize = max(len(game.teams[0].player_ids),
                   len(game.teams[1].player_ids))
    player_objs = game.players
    ranks = get_rank_batch([p.id.id for p in player_objs],
                           offline_redis=offline_redis)
    rank_list = []
    mmr_list = []
    for player, rank in ranks.items():
        r = get_rank_obj_by_mapping(rank, playlist=game.game_metadata.playlist)
        rank_list.append(r['tier'])
        mmr_list.append(r['rank_points'])
    replay_id = game.game_metadata.match_guid
    if replay_id == '' or replay_id is None:
        replay_id = game.game_metadata.id
    team0poss = game.teams[0].stats.possession
    team1poss = game.teams[1].stats.possession
    match_date = datetime.datetime.fromtimestamp(game.game_metadata.time)
    match_name = game.game_metadata.name
    g = Game(hash=replay_id,
             players=[str(p.id.id) for p in player_objs],
             ranks=rank_list,
             mmrs=mmr_list,
             map=game.game_metadata.map,
             team0score=game.game_metadata.score.team_0_score,
             team1score=game.game_metadata.score.team_1_score,
             teamsize=teamsize,
             match_date=match_date,
             team0possession=team0poss.possession_time,
             team1possession=team1poss.possession_time,
             name='' if match_name is None else match_name,
             frames=game.game_metadata.frames,
             length=game.game_metadata.length,
             playlist=game.game_metadata.playlist,
             game_server_id=0 if game.game_metadata.game_server_id == '' else
             game.game_metadata.game_server_id,
             server_name=game.game_metadata.server_name,
             replay_id=game.game_metadata.id,
             primary_player=game.game_metadata.primary_player.id)

    player_games = []
    players = []
    teamstats = []
    # print('iterating over players')
    for team in game.teams:
        fields = create_and_filter_proto_field(team,
                                               ['id', 'name', 'is_orange'], [],
                                               TeamStat)
        values = get_proto_values(team, fields)
        kwargs = {k.field_name: v for k, v in zip(fields, values)}
        for k in kwargs:
            if kwargs[k] == 'NaN' or math.isnan(kwargs[k]):
                kwargs[k] = 0.0
        t = TeamStat(game=replay_id, is_orange=team.is_orange, **kwargs)
        teamstats.append(t)

    for p in player_objs:  # type: GamePlayer
        fields = create_and_filter_proto_field(
            p, ['name', 'title_id', 'is_orange'], [
                'api.metadata.CameraSettings', 'api.metadata.PlayerLoadout',
                'api.PlayerId'
            ], PlayerGame)
        values = get_proto_values(p, fields)
        kwargs = {k.field_name: v for k, v in zip(fields, values)}
        for k in kwargs:
            if kwargs[k] == 'NaN' or math.isnan(kwargs[k]):
                kwargs[k] = 0.0
        camera = p.camera_settings
        loadout = p.loadout
        field_of_view = camera.field_of_view
        transition_speed = camera.transition_speed
        pitch = camera.pitch
        swivel_speed = camera.swivel_speed
        stiffness = camera.stiffness
        height = camera.height
        distance = camera.distance
        blue_score = game.game_metadata.score.team_0_score
        orange_score = game.game_metadata.score.team_1_score
        is_orange = p.is_orange

        pid = str(p.id.id)
        rank = None
        mmr = None
        division = None
        if pid in ranks:
            try:
                r = get_rank_obj_by_mapping(
                    ranks[pid], playlist=game.game_metadata.playlist)
                rank = r['tier']
                division = r['division']
                mmr = r['rank_points']
            except:
                rank = 0
                division = 0
                mmr = 0

        if is_orange:
            win = orange_score > blue_score
        else:
            win = blue_score > orange_score
        pg = PlayerGame(player=pid,
                        name=p.name,
                        game=replay_id,
                        field_of_view=field_of_view,
                        transition_speed=transition_speed,
                        pitch=pitch,
                        swivel_speed=swivel_speed,
                        stiffness=stiffness,
                        height=height,
                        distance=distance,
                        car=-1 if loadout is None else loadout.car,
                        is_orange=p.is_orange,
                        rank=rank,
                        division=division,
                        mmr=mmr,
                        win=win,
                        **kwargs)
        player_games.append(pg)
        if len(str(pid)) > 40:
            pid = pid[:40]
        p = Player(platformid=pid,
                   platformname=p.name,
                   avatar="",
                   ranks=[],
                   groups=[])
        players.append(p)

    loadouts = process_loadout_to_obj(game)
    return g, player_games, players, teamstats, loadouts