Ejemplo n.º 1
0
def return_values(c100_s, c50_s, misses_s, combo_s, file_name, mod_s):
    try:
        file = requests.get(b_info.main(file_name)).text.splitlines()
    except:
        print("ERROR: " + file_name + " not a valid beatmap")
        sys.exit(1)

    map = Beatmap(file)

    if combo_s == "":
        combo = map.max_combo
    else:
        combo = int(combo_s)

    mod_s = mod_s.upper()

    mod.dt = 0
    mod.ez = 0
    mod.fl = 0
    mod.hd = 0
    mod.hr = 0
    mod.ht = 0
    mod.nc = 0
    mod.nf = 0
    mod.so = 0

    if mod_s != "":
        mod_s = [mod_s[i:i + 2] for i in range(0, len(mod_s), 2)]
        for m in mod_s:
            set_mods(mod, m)
            mod.update()

    if c100_s == "":
        c100 = 0
    else:
        c100 = int(c100_s)

    if c50_s == "":
        c50 = 0
    else:
        c50 = int(c50_s)

    if misses_s == "":
        misses = 0
    else:
        misses = int(misses_s)

    mod_string = mod_str(mod)
    map.apply_mods(mod)
    diff = diff_calc.main(map)
    pp, aim_value, speed_value, acc_value = pp_calc.pp_calc(diff[0], diff[1], diff[3], misses, c100, c50, mod, combo)

    return pp
Ejemplo n.º 2
0
def return_values(c100, c50, misses, combo, map_id, mod_s):
    try:
        file = requests.get(
            "https://osu.ppy.sh/osu/{}".format(map_id)).text.splitlines()
    except:
        print("ERROR: " + file_name +
              " not a valid beatmap or API key is incorrect")
        sys.exit(1)

    map = Beatmap(file)

    mod.dt = 0
    mod.ez = 0
    mod.fl = 0
    mod.hd = 0
    mod.hr = 0
    mod.ht = 0
    mod.nc = 0
    mod.nf = 0
    mod.so = 0

    if mod_s != 0:
        set_mods(mod, mod_s)
        mod.update()

    mod_string = mod_str(mod)
    map.apply_mods(mod)
    diff = diff_calc.main(map)
    pp = pp_calc.pp_calc(diff[0], diff[1], diff[3], misses, c100, c50, mod,
                         combo)

    title = map.artist + " - " + map.title + "[" + map.version + "]"
    if mod_string != "":
        title += "+" + mod_string
    title += " (" + map.creator + ")"

    return (str(title), pp[0].pp)
Ejemplo n.º 3
0
def return_recent(user, best, number, last_beatmap, low_detail):
    user = "******".join(user.split(" "))

    if user == [0]:
        return 5, 0, 0, 0, 0, 0, 0, 0, 0

    try:
        f = open('keys.cfg')
        config = configparser.ConfigParser()
        config.readfp(f)
        key = config._sections["osu"]['api_key']
    except:
        raise Exception("Invalid config")

    index_adjust = 0
    date_index_adjust = 0

    url = 'https://osu.ppy.sh/api/get_user_recent?k={}&u={}&limit=50'.format(
        key, user)
    if best == 1 or best == 3:
        url = 'https://osu.ppy.sh/api/get_user_best?k={}&u={}&limit=100'.format(
            key, user)
    if best == 2:
        url = 'https://osu.ppy.sh/api/get_scores?k={}&u={}&b={}&limit=100'.format(
            key, user, last_beatmap)
        index_adjust = 1
        date_index_adjust = 1
    jsonurl = str(requests.get(url).text)
    jsonurl = jsonurl[1:-2]
    user_split = [i[1:] for i in jsonurl.split("},")]
    play_info = []
    for i in range(len(user_split)):
        play_info.append([])
        info_list = user_split[i].split("\"")
        play_info[i] = [(info_list[1 + x * 4], info_list[3 + x * 4])
                        for x in range(int(len(info_list) / 4))]

    if number > len(play_info):
        return play_info, user, 0, 0, 0, 0, 0, 0, 0

    if len(play_info[0]) <= 1:
        return play_info, user, 0, 0, 0, 0, 0, 0, 0

    if best == 3:
        play_info = sorted(play_info, key=get_date, reverse=True)

    datetime_rb = datetime.strptime(
        play_info[number - 1][12 + date_index_adjust][1], '%Y-%m-%d %H:%M:%S')
    now = int(time.time())
    d = divmod(now - datetime_rb.replace(tzinfo=timezone.utc).timestamp(),
               86400)  # days
    h = divmod(d[1], 3600)  # hours
    m = divmod(h[1], 60)  # minutes
    s = m[1]  # seconds
    if d[0] > 0:
        if int(d[0]) == 1:
            time_ago = "1 day ago"
        else:
            time_ago = "{} days ago".format(int(d[0]))
    elif h[0] > 0:
        if int(h[0]) == 1:
            time_ago = "1 hour ago"
        else:
            time_ago = "{} hours ago".format(int(h[0]))
    elif m[0] > 0:
        if int(m[0]) == 1:
            time_ago = "1 minute ago"
        else:
            time_ago = "{} minutes ago".format(int(m[0]))
    else:
        if int(s) == 1:
            time_ago = "1 second ago"
        else:
            time_ago = "{} seconds ago".format(int(s))

    if best != 2:
        b_id = play_info[number - 1][0][1]
    else:
        b_id = last_beatmap

    mods = int(play_info[number - 1][10 + index_adjust][1])
    time_multiplier = 1
    mods_string = ""
    if mods & 0b1: mods_string += "NF"
    if mods & 0b1 << 11: mods_string += "SO"
    if mods & 0b1 << 1: mods_string += "EZ"
    if mods & 0b1 << 8:
        time_multiplier = 0.75
        mods_string += "HT"
    if mods & 0b1 << 3: mods_string += "HD"
    if mods & 0b1 << 9:
        time_multiplier = 1.5
        mods_string += "NC"
    elif mods & 0b1 << 6:
        time_multiplier = 1.5
        mods_string += "DT"
    if mods & 0b1 << 4: mods_string += "HR"
    if mods & 0b1 << 10: mods_string += "FL"
    if mods & 0b1 << 14:
        mods_string += "PF"
    elif mods & 0b1 << 5:
        mods_string += "SD"

    if mods_string == "":
        mods_string = "None"

    new_beatmap = calc.return_beatmap(mods_string, b_id)

    diff_file = diff_calc.main(new_beatmap)

    combo = play_info[number - 1][2 + index_adjust][1]
    c50 = play_info[number - 1][3 + index_adjust][1]
    c100 = play_info[number - 1][4 + index_adjust][1]
    c300 = play_info[number - 1][5 + index_adjust][1]
    misses = play_info[number - 1][6 + index_adjust][1]
    pp = calc.return_values(c100, c50, misses, combo, str(b_id), mods_string)
    max_pp = calc.return_values("", "", "", "", str(b_id), mods_string)

    objects = len(new_beatmap.objects)

    url = 'https://osu.ppy.sh/api/get_beatmaps?k={}&b={}'.format(key, b_id)
    jsonurl = str(requests.get(url).text)
    jsonurl = jsonurl[2:-2]
    beatmap_split = jsonurl.split("\"")
    beatmap_info = [(beatmap_split[1 + x * 4], beatmap_split[3 + x * 4])
                    for x in range(int(len(beatmap_split) / 4))]

    s_id = beatmap_info[0][1]
    song_length = int(int(beatmap_info[3][1]) / time_multiplier)
    drain_length = int(int(beatmap_info[4][1]) / time_multiplier)
    diff = beatmap_info[5][1]
    cs = new_beatmap.cs
    od = new_beatmap.od
    ar = new_beatmap.ar
    hp = new_beatmap.hp
    artist = beatmap_info[14][1]
    song_title = beatmap_info[15][1]
    mapper = beatmap_info[16][1]
    bpm = float(float(beatmap_info[18][1]) * time_multiplier)
    max_combo = beatmap_info[26][1]
    star_rating = diff_file[2]

    status_num = int(beatmap_info[2][1])
    if status_num == 1:
        status_s = "Ranked"
    elif status_num == 2:
        status_s = "Approved"
    elif status_num == 3:
        status_s = "Qualified"
    elif status_num == 4:
        status_s = "Loved"
    else:
        status_s = "the f**k?"

    song_min = math.floor(song_length / 60)
    song_sec = song_length % 60
    drain_min = math.floor(drain_length / 60)
    drain_sec = drain_length % 60

    song_length = "{:02d}:{:02d}".format(song_min, song_sec)
    drain_length = "{:02d}:{:02d}".format(drain_min, drain_sec)

    title = "{} - {} ({}) [{}]".format(artist, song_title, mapper, diff)
    link = 'https://osu.ppy.sh/b/{}'.format(beatmap_info[1][1])

    map_text_list = [
        "__**Map Information:**__", "**Stars:** {:.2f}*".format(star_rating),
        "**Difficulty Settings:** CS{:.1f} | AR{:.1f} | OD{:.1f} | HP{:.1f}".
        format(cs, ar, od, hp),
        "**Song Settings:** {:.1f} BPM | length {} (drain {})".format(
            bpm, song_length, drain_length), "**Status:** {}".format(status_s)
    ]

    map_text = '\n'.join(map_text_list)

    score = play_info[number - 1][1][1]
    grade = play_info[number - 1][13 + index_adjust][1]
    rank_string = ""
    fc_string = ""
    top_score_string = ""
    final_pp = pp.pp

    if grade == "F":
        grade += " ({:.2f}% completion)".format(
            100 * ((int(c50) + int(c100) + int(c300) + int(misses)) / objects))

    user_info_s = "{}".format(user)
    user_link = "https://osu.ppy.sh/u/{}".format(user)
    user_pfp = ""

    if int(combo) < int(max_combo):
        fc_pp = calc.return_values(c100, c50, 0, max_combo, str(b_id),
                                   mods_string)
        fc_string = " FC {:.2f}pp /".format(fc_pp.pp)

    if not low_detail:
        url = 'https://osu.ppy.sh/api/get_user?k={}&u={}'.format(key, user)
        jsonurl = str(requests.get(url).text)
        jsonurl = jsonurl[2:-2]
        user_split = jsonurl.split("\"")
        user_info = [(user_split[1 + x * 4], user_split[3 + x * 4])
                     for x in range(int(len(user_split) / 4))]

        user_id = user_info[0][1]
        user_pfp = "https://a.ppy.sh/{}".format(user_id)
        username = user_info[1][1]
        rank = user_info[9][1]
        pp_total = user_info[11][1]
        country = user_info[18][1]
        country_rank = user_info[20][1]

        user_info_s = "{} | {}pp, global #{} ({} #{})".format(
            username, pp_total, rank, country, country_rank)

        if best == 1 or best == 3:
            final_pp = float(play_info[number - 1][14 + index_adjust][1])

        url = 'https://osu.ppy.sh/api/get_scores?k={}&b={}&limit=100'.format(
            key, b_id)
        jsonurl = str(requests.get(url).text)
        jsonurl = jsonurl[1:-2]
        user_split = [i[1:] for i in jsonurl.split("},")]
        leaderboard_info = []
        for i in range(len(user_split)):
            leaderboard_info.append([])
            info_list = user_split[i].split("\"")
            leaderboard_info[i] = [(info_list[1 + x * 4], info_list[3 + x * 4])
                                   for x in range(int(len(info_list) / 4))]

        for i in range(len(leaderboard_info)):
            if leaderboard_info[i][1][1] == str(
                    score) and leaderboard_info[i][2][1] == username:
                rank_string = " __**#{}**__".format(i + 1)
                if best == 0 or best == 2:
                    final_pp = float(leaderboard_info[i][15][1])
                break

        url = 'https://osu.ppy.sh/api/get_user_best?k={}&u={}&limit=100'.format(
            key, user)
        jsonurl = str(requests.get(url).text)
        jsonurl = jsonurl[1:-2]
        user_split = [i[1:] for i in jsonurl.split("},")]
        top_scores_info = []
        for i in range(len(user_split)):
            top_scores_info.append([])
            info_list = user_split[i].split("\"")
            top_scores_info[i] = [(info_list[1 + x * 4], info_list[3 + x * 4])
                                  for x in range(int(len(info_list) / 4))]
        for i in range(len(top_scores_info)):
            if top_scores_info[i][1][1] == str(
                    score) and top_scores_info[i][0][1] == str(b_id):
                top_score_string = " __**#{}**__".format(i + 1)
                break

    play_info_list = [
        "__**Play Information:**__",
        "**Grade:** {}".format(grade),
        "**Mods:** {}".format(mods_string),
        "**Score:** {}{}".format(score, rank_string),
        "**Accuracy:** {:.2f}%".format(
            100 * (int(c300) * 3 + int(c50) * 0.5 + int(c100)) /
            ((int(c300) + int(c100) + int(c50) + int(misses)) * 3)),
        "**Hits:** {} / {} / {} / {}".format(c300, c100, c50, misses),
        "**Combo:** {}/{}x".format(combo, max_combo),
        "**Performance:** __{:.2f}pp__{} /{} SS {:.2f}pp".format(
            final_pp, top_score_string, fc_string, max_pp.pp),
        "**When:** {}".format(time_ago),
    ]

    if best == 0:
        tries = 1
        for i in range(49):
            if i < number:
                continue
            if play_info[i][0][1] == str(b_id) and play_info[i][10][1] == str(
                    mods):
                tries += 1
            else:
                break
        if tries >= 49:
            play_info_list.append("**Try:** 49+")
        else:
            play_info_list.append("**Try:** {}".format(tries))

    play_info_s = '\n'.join(play_info_list)

    difficulty_settings = play_info_s + '\n\n' + map_text

    return play_info, title, link, difficulty_settings, user_info_s, user_link, user_pfp, b_id, s_id
Ejemplo n.º 4
0
        mod.nc = 1
    if m == "FL":
        mod.fl = 1
    if m == "SO":
        mod.so = 1


if mod_s != "":
    mod_s = [mod_s[i:i + 2] for i in range(0, len(mod_s), 2)]
    for m in mod_s:
        set_mods(mod, m)
        mod.update()

mod_string = mod_str(mod)
map.apply_mods(mod)
diff = diff_calc.main(map)
if acc == 0:
    pp = pp_calc.pp_calc(diff[0], diff[1], diff[3], misses, c100, c50, mod,
                         combo, sv)
else:
    pp = pp_calc.pp_calc_acc(diff[0], diff[1], diff[3], acc, mod, combo,
                             misses, sv)
title = map.artist + " - " + map.title + "[" + map.version + "]"
if mod_string != "":
    title += "+" + mod_string
title += " (" + map.creator + ")"
print("Map: " + title)
print("AR: " + str(round(map.ar, 2)) + " CS: " + str(round(map.cs, 2)) +
      " OD: " + str(round(map.od, 2)))
print("Stars: " + str(round(diff[2], 2)))
print("Acc: " + str(round(pp.acc_percent, 2)) + "%")
Ejemplo n.º 5
0
def return_values(c100_s, c50_s, misses_s, combo_s, file_name, mod_s,
                  balancing_values):
    try:
        file = requests.get(b_info.main(file_name)).text.splitlines()
    except:
        print("ERROR: " + file_name + " not a valid beatmap")
        sys.exit(1)

    map = Beatmap(file)

    if combo_s == "":
        combo = map.max_combo
    else:
        combo = int(combo_s)

    mod_s = mod_s.upper()

    mod.dt = 0
    mod.ez = 0
    mod.fl = 0
    mod.hd = 0
    mod.hr = 0
    mod.ht = 0
    mod.nc = 0
    mod.nf = 0
    mod.so = 0

    if mod_s != "":
        mod_s = [mod_s[i:i + 2] for i in range(0, len(mod_s), 2)]
        for m in mod_s:
            set_mods(mod, m)
            mod.update()

    if c100_s == "":
        c100 = 0
    else:
        c100 = int(c100_s)

    if c50_s == "":
        c50 = 0
    else:
        c50 = int(c50_s)

    if misses_s == "":
        misses = 0
    else:
        misses = int(misses_s)

    mod_string = mod_str(mod)
    map.apply_mods(mod)
    diff = diff_calc.main(map, balancing_values)
    pp, aim_value, speed_value, acc_value, length_bonus, new_length_bonus, speed_length = pp_calc.pp_calc(
        diff[0], diff[1], diff[3], diff[4], diff[5], misses, c100, c50, mod,
        combo)

    title = map.artist + " - " + map.title + "[" + map.version + "]"
    if mod_string != "":
        title += "+" + mod_string
    title += " (" + map.creator + ")\n"
    map_s = "Map: {}\n".format(title)
    difficulty_settings = "AR: {:.2f} CS: {:.2f} OD: {:.2f}\n".format(
        map.ar, map.cs, map.od)
    stars = "Stars: {:.2f}\n".format(diff[2])
    acc = "Acc: {:.2f}%\n\n".format(pp.acc_percent)
    circle_s = "Circles: {}\n".format(map.num_circles)
    slider_s = "Sliders: {}\n".format(map.num_sliders)
    spinner_s = "Spinners: {}\n".format(map.num_spinners)
    object_s = "Objects: {}\n\n".format(map.num_objects)
    comb_s = "Combo: {}/{}\n".format(int(combo), int(map.max_combo))
    miss_s = "Misses: {}\n\n".format(misses)
    aim_vs = "Aim Value: {:.2f}PP\n".format(aim_value)
    speed_vs = "Speed Value: {:.2f}PP\n".format(speed_value)
    acc_vs = "Acc Value: {:.2f}PP\n\n".format(acc_value)
    aim_ts = "Aim Total Value: {:.0f}\n".format(diff[6][1])
    speed_ts = "Speed Total Value: {:.0f}\n\n".format(diff[7][1])
    length_os = "Old Length Bonus: {:.4f}\n".format(length_bonus)
    length_as = "New Length Bonus: {:.4f}\n\n".format(new_length_bonus)
    pp_s = "Performance: {:.2f}PP\n".format(pp.pp)

    return (map_s + difficulty_settings + stars + acc + circle_s + slider_s +
            spinner_s + object_s + comb_s + miss_s + aim_vs + speed_vs +
            acc_vs + aim_ts + speed_ts + length_os + length_as + pp_s)