Beispiel #1
0
async def get_user_grade():
    # get request stuff
    mode = request.args.get('mode', default='std', type=str)
    mods = request.args.get('mods', default='rx', type=str)
    id = request.args.get('id', type=int)

    # validate everything

    if (mode := utils.convert_mode_int(mode)) is None:
        return b'invalid mode type! (std, taiko, catch, mania)'
Beispiel #2
0
async def get_player_most():
    # get request args
    id = request.args.get('id', type=int)
    mode = request.args.get('mode', type=str)
    mods = request.args.get('mods', type=str)
    limit = request.args.get('limit', type=int)

    # check if required parameters are met
    if not id:
        return b'missing parameters! (id)'

    if mods not in valid_mods:
        return b'invalid mods! (vn, rx, ap)'

    if (mode := utils.convert_mode_int(mode)) is None:
        return b'invalid mode type! (std, taiko, catch, mania)'
Beispiel #3
0
async def get_player_scores():
    # get request args
    id = request.args.get('id', type=int)
    mode = request.args.get('mode', type=str)
    mods = request.args.get('mods', type=str)
    sort = request.args.get('sort', type=str)
    limit = request.args.get('limit', type=int)

    # check if required parameters are met
    if not id:
        return b'missing parameters! (id)'

    if sort == 'recent':
        sort = 'id'
    elif sort == 'best':
        sort = 'pp'
    else:
        return b'invalid sort! (recent or best)'

    if mods not in valid_mods:
        return b'invalid mods! (vn, rx, ap)'

    if (mode := utils.convert_mode_int(mode)) is None:
        return b'invalid mode type! (std, taiko, catch, mania)'
Beispiel #4
0
async def get_user_grade():
    # get request stuff
    mode = request.args.get('mode', default='std', type=str)
    mods = request.args.get('mods', default='rx', type=str)
    id = request.args.get('id', type=int)

    # validate everything
    if mode not in valid_modes:
        return b'invalid mode! (std, taiko, catch, mania)'
    else:
        mode = convert_mode_int(mode)

    if mods not in valid_mods:
        return b'invalid mods! (vn, rx, ap)'

    if not id:
        return b'missing id!'

    # get all scores
    q = f'SELECT grade FROM scores_{mods} WHERE mode = {mode} AND userid = %s'

    scores = await glob.db.fetchall(q, [id])

    grades = {
        "x": 0,
        "xh": 0,
        "s": 0,
        "sh": 0,
        "a": 0
    }
      
    if not scores:
        return jsonify(grades)



    # count
    for score in (x for x in scores if x['grade'].lower() in grades):
        grades[score['grade'].lower()] += 1 
        
    if glob.config.debug:
        log(' '.join(q), Ansi.LGREEN)
    # return
    return jsonify(grades)