feat(score): update statistics & return user in score
This commit is contained in:
@@ -1,12 +1,26 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from app.database.score import Score
|
||||
import math
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from app.models.beatmap import BeatmapAttributes
|
||||
from app.models.mods import APIMod
|
||||
from app.models.score import GameMode
|
||||
|
||||
import rosu_pp_py as rosu
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from app.database.score import Score
|
||||
|
||||
|
||||
def clamp[T: int | float](n: T, min_value: T, max_value: T) -> T:
|
||||
if n < min_value:
|
||||
return min_value
|
||||
elif n > max_value:
|
||||
return max_value
|
||||
else:
|
||||
return n
|
||||
|
||||
|
||||
def calculate_beatmap_attribute(
|
||||
beatmap: str,
|
||||
@@ -32,7 +46,7 @@ def calculate_beatmap_attribute(
|
||||
|
||||
|
||||
def calculate_pp(
|
||||
score: Score,
|
||||
score: "Score",
|
||||
beatmap: str,
|
||||
) -> float:
|
||||
map = rosu.Beatmap(content=beatmap)
|
||||
@@ -57,3 +71,34 @@ def calculate_pp(
|
||||
)
|
||||
attrs = perf.calculate(map)
|
||||
return attrs.pp
|
||||
|
||||
|
||||
# https://osu.ppy.sh/wiki/Gameplay/Score/Total_score
|
||||
def calculate_level_to_score(level: int) -> float:
|
||||
if level <= 100:
|
||||
# 55 = 4^3 - 3^2
|
||||
return 5000 / 3 * (55 - level) + 1.25 * math.pow(1.8, level - 60)
|
||||
else:
|
||||
return 26_931_190_827 + 99_999_999_999 * (level - 100)
|
||||
|
||||
|
||||
def calculate_score_to_level(score: float) -> int:
|
||||
if score < 5000:
|
||||
return int(55 - (3 * score / 5000)) # 55 = 4^3 - 3^2
|
||||
elif score < 26_931_190_827:
|
||||
return int(60 + math.log(score / 1.25, 1.8))
|
||||
else:
|
||||
return int((score - 26_931_190_827) / 99_999_999_999 + 100)
|
||||
|
||||
|
||||
# https://osu.ppy.sh/wiki/Performance_points/Weighting_system
|
||||
def calculate_pp_weight(index: int) -> float:
|
||||
return math.pow(0.95, index)
|
||||
|
||||
|
||||
def calculate_weighted_pp(pp: float, index: int) -> float:
|
||||
return calculate_pp_weight(index) * pp if pp > 0 else 0.0
|
||||
|
||||
|
||||
def calculate_weighted_acc(acc: float, index: int) -> float:
|
||||
return calculate_pp_weight(index) * acc if acc > 0 else 0.0
|
||||
|
||||
Reference in New Issue
Block a user