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 api_v1_get_playergames_by_rank(session=None): if 'days' in request.args: days = int(request.args['days']) else: days = 3 * 30 builder = QueryFilterBuilder().with_stat_query([PlayerGame]).with_relative_start_time(days) QueryFilterBuilder.apply_arguments_to_query(builder, request.args) games = builder.build_query(session).order_by(func.random())[:1000] columns = [c.name for c in games[0].__table__.columns] data = { 'data': [[getattr(g, c.name) for c in g.__table__.columns] for g in games], 'columns': columns } return jsonify(data)
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