コード例 #1
0
def matches_api() -> Response:
    """
    Grab a slice of results from a 0-indexed resultset of matches.
    Input:
        {
            'competitionId': <int?>,
            'page': <int>,
            'pageSize': <int>,
            'q': <str>,
            'sortBy': <str>,
            'sortOrder': <'ASC'|'DESC'>,
            'seasonId': <int|'all'?>
        }
    Output:
        {
            'page': <int>,
            'objects': [<entry>],
            'total': <int>
        }
    """
    order_by = query.matches_order_by(request.args.get('sortBy'),
                                      request.args.get('sortOrder'))
    page_size = int(request.args.get('pageSize', DEFAULT_LIVE_TABLE_PAGE_SIZE))
    page = int(request.args.get('page', 0))
    start = page * page_size
    limit = f'LIMIT {start}, {page_size}'
    q = request.args.get('q', '').strip()
    person_where = query.text_match_where(query.person_query(),
                                          q) if q else 'TRUE'
    opponent_where = query.text_match_where(query.person_query('o'),
                                            q) if q else 'TRUE'
    where = f'({person_where} OR {opponent_where})'
    try:
        competition_id = int(request.args.get('competitionId', ''))
        where += f' AND (c.id = {competition_id})'
        season_id = None
    except ValueError:
        season_id = seasons.season_id(str(request.args.get('seasonId')), None)
    entries = match.load_matches(where=where,
                                 order_by=order_by,
                                 limit=limit,
                                 season_id=season_id,
                                 show_active_deck_names=session.get(
                                     'admin', False))
    prepare_matches(entries)
    total = match.load_matches_count(where=where, season_id=season_id)
    r = {'page': page, 'total': total, 'objects': entries}
    resp = return_json(r, camelize=True)
    resp.set_cookie('page_size', str(page_size))
    return resp
コード例 #2
0
def leaderboards_api() -> Response:
    """
    Grab a slice of results from a 0-indexed resultset of leaderboard entries.
    Input:
        {
            'competitionId': <int?>,
            'competitionSeriesId': <int?>
            'page': <int>,
            'pageSize': <int>,
            'sortBy': <str>,
            'sortOrder': <'ASC'|'DESC'>,
            'seasonId': <int|'all'?>,
            'q': <str>
        }
    Output:
        {
            'page': <int>,
            'objects': [<entry>],
            'total': <int>
        }
    """
    order_by = query.leaderboard_order_by(request.args.get('sortBy'),
                                          request.args.get('sortOrder'))
    page_size = int(request.args.get('pageSize', DEFAULT_LIVE_TABLE_PAGE_SIZE))
    page = int(request.args.get('page', 0))
    start = page * page_size
    limit = f'LIMIT {start}, {page_size}'

    q = request.args.get('q', '').strip()
    where = query.text_match_where(query.person_query(), q) if q else 'TRUE'
    try:
        competition_id = int(request.args.get('competitionId', ''))
        where += f' AND (c.id = {competition_id})'
        season_id = None
    except ValueError:
        season_id = seasons.season_id(str(request.args.get('seasonId')), None)
    try:
        competition_series_id = int(request.args.get('competitionSeriesId',
                                                     ''))
        where += f' AND (cs.id = {competition_series_id})'
    except ValueError:
        pass
    entries = comp.load_leaderboard(where=where,
                                    group_by='p.id',
                                    order_by=order_by,
                                    limit=limit,
                                    season_id=season_id)
    prepare_leaderboard(entries)
    total = comp.load_leaderboard_count(where=where, season_id=season_id)
    r = {'page': page, 'total': total, 'objects': entries}
    resp = return_json(r, camelize=True)
    resp.set_cookie('page_size', str(page_size))
    return resp
コード例 #3
0
def h2h_api() -> Response:
    """
    Grab a slice of results from a 0-indexed resultset of head-to-head entries.
    Input:
        {
            'page': <int>,
            'pageSize': <int>,
            'personId': <int>,
            'sortBy': <str>,
            'sortOrder': <'ASC'|'DESC'>,
            'seasonId': <int|'all'>,
            'q': <str>
        }
    Output:
        {
            'page': <int>,
            'objects': [<entry>],
            'total': <int>
        }
    """
    order_by = query.head_to_head_order_by(request.args.get('sortBy'),
                                           request.args.get('sortOrder'))
    page_size = int(request.args.get('pageSize', DEFAULT_LIVE_TABLE_PAGE_SIZE))
    page = int(request.args.get('page', 0))
    start = page * page_size
    limit = f'LIMIT {start}, {page_size}'
    season_id = seasons.season_id(str(request.args.get('seasonId')), None)
    person_id = int(request.args.get('personId', 0))
    q = request.args.get('q', '').strip()
    where = query.text_match_where('opp.mtgo_username', q) if q else 'TRUE'
    entries = ps.load_head_to_head(person_id,
                                   where=where,
                                   order_by=order_by,
                                   limit=limit,
                                   season_id=season_id)
    for entry in entries:
        entry.opp_url = url_for('.person',
                                mtgo_username=entry.opp_mtgo_username,
                                season_id=None if season_id
                                == seasons.current_season_num() else season_id)
    total = ps.load_head_to_head_count(person_id=person_id,
                                       where=where,
                                       season_id=season_id)
    r = {'page': page, 'total': total, 'objects': entries}
    resp = return_json(r, camelize=True)
    resp.set_cookie('page_size', str(page_size))
    return resp
コード例 #4
0
def people_api() -> Response:
    """
    Grab a slice of results from a 0-indexed resultset of people.
    Input:
        {
            'page': <int>,
            'pageSize': <int>,
            'sortBy': <str>,
            'sortOrder': <'ASC'|'DESC'>,
            'seasonId': <int|'all'>,
            'q': <str>
        }
    Output:
        {
            'page': <int>,
            'objects': [<person>],
            'total': <int>
        }
    """
    order_by = query.people_order_by(request.args.get('sortBy'),
                                     request.args.get('sortOrder'))
    page_size = int(request.args.get('pageSize', DEFAULT_LIVE_TABLE_PAGE_SIZE))
    page = int(request.args.get('page', 0))
    start = page * page_size
    limit = f'LIMIT {start}, {page_size}'
    season_id = seasons.season_id(str(request.args.get('seasonId')), None)
    q = request.args.get('q', '').strip()
    where = query.text_match_where(query.person_query(), q) if q else 'TRUE'
    people = ps.load_people(where=where,
                            order_by=order_by,
                            limit=limit,
                            season_id=season_id)
    prepare_people(people)
    total = ps.load_people_count(where=where, season_id=season_id)
    r = {'page': page, 'total': total, 'objects': people}
    resp = return_json(r, camelize=True)
    resp.set_cookie('page_size', str(page_size))
    return resp