Пример #1
0
    def create_with_filters(page: int,
                            limit: int,
                            session=None,
                            **kwargs) -> 'MatchHistory':
        tags = JsonTag.get_tags_from_query_params(**kwargs, session=session)

        builder = QueryFilterBuilder().as_game()

        if len(tags) > 0:
            builder.with_tags([tag.id for tag in tags])

        QueryFilterBuilder.apply_arguments_to_query(builder, kwargs)
        query = builder.build_query(session)

        if 'min_length' in kwargs:
            query = query.filter(Game.length > kwargs['min_length'])
        if 'max_length' in kwargs:
            query = query.filter(Game.length < kwargs['max_length'])
        if 'map' in kwargs:
            query = query.filter(Game.map == kwargs['map'])
        count = query.count()
        games = query.order_by(desc(Game.match_date))[page * limit:(page + 1) *
                                                      limit]
        matches = MatchHistory(
            count, [Replay.create_from_game(game) for game in games])
        return matches
Пример #2
0
 def create(cls, obj, descendant_count=0):
     return cls(uuid=obj.uuid,
                owner=Player.create_from_id(obj.owner).__dict__,
                name=obj.name,
                game=obj.game,
                game_object=Replay.create_from_id(obj.game).__dict__
                if obj.game is not None else None,
                type=obj.type.value,
                parent=obj.parent.uuid if obj.parent is not None else None,
                descendant_count=descendant_count)
Пример #3
0
 def create_from_id(id_: str,
                    page: int,
                    limit: int,
                    session=None) -> 'MatchHistory':
     games = player_wrapper.get_games_paginated(session, id_, page, limit)
     total_count = player_wrapper.get_total_games(session,
                                                  id_,
                                                  filter_private=True)
     match_history = MatchHistory(
         total_count,
         [Replay.create_from_game(game, full=False) for game in games])
     return match_history
Пример #4
0
 def create_pack_response(packs_list, count, session):
     # gets list of games from each pack
     games = [[shot['game'] for shot in p.shots] for p in packs_list]
     # flatten the list and remove duplicates
     games = list(set([val for sublist in games for val in sublist]))
     # get all of these games only once
     game_list = session.query(Game).filter(Game.hash.in_(games)).all()
     # create a map for the frontend to deal with
     game_map = {game.hash: Replay.create_from_game(game).__dict__ for game in game_list}
     return {'games': game_map,
             'packs': [
                 {
                     'guid': p.guid,
                     'shots': p.shots,
                     'date': p.creation_date,
                     'name': p.name,
                     'link': f'https://storage.googleapis.com/{TRAINING_PACK_BUCKET}/{p.guid}.Tem'
                 } for p in packs_list
             ],
             'totalCount': count}
Пример #5
0
    def create_with_filters(page: int,
                            limit: int,
                            session=None,
                            **kwargs) -> 'MatchHistory':
        # TODO: move this somewhere else and make it reusable
        if limit > 100:
            limit = 100
        builder = QueryFilterBuilder().as_game().with_stat_query([Game])
        QueryFilterBuilder.apply_arguments_to_query(builder, kwargs)
        query = builder.build_query(session)

        if 'min_length' in kwargs:
            query = query.filter(Game.length > kwargs['min_length'])
        if 'max_length' in kwargs:
            query = query.filter(Game.length < kwargs['max_length'])
        if 'map' in kwargs:
            query = query.filter(Game.map == kwargs['map'])
        count = query.count()
        games = query.order_by(desc(Game.match_date))[page * limit:(page + 1) *
                                                      limit]
        matches = MatchHistory(
            count, [Replay.create_from_game(game) for game in games])
        return matches
Пример #6
0
def api_get_replay_data(id_):
    replay = Replay.create_from_id(id_)
    return better_jsonify(replay)
Пример #7
0
 def get_recent_replays(session=None):
     replays = session.query(Game).order_by(desc(Game.match_date))[:5]
     return [Replay.create_from_game(r).__dict__ for r in replays]