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
 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
Exemple #3
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}
Exemple #4
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
 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]