Skip to content

Commit

Permalink
mods adn map embed
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyui committed May 30, 2024
1 parent 71efa7c commit 912d65d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
23 changes: 14 additions & 9 deletions common/speedrunning.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,11 @@ async def end_user_speedrun(user_id: int, game_mode: int) -> SpeedrunResults | N

if speedrun.score_type is ScoreType.WEIGHTED_PP:
score_value = sum(
score.score_value * 0.95 ** (score.score_rank - 1)
for score in speedrun_scores
score.value * 0.95 ** (score.rank - 1) for score in speedrun_scores
)
score_value += 416.6667 * (1 - 0.9994 ** len(speedrun_scores))
elif speedrun.score_type is ScoreType.WEIGHTED_SCORE:
score_value = sum(score.score_value for score in speedrun_scores)
score_value = sum(score.value for score in speedrun_scores)
else:
raise NotImplementedError()

Expand Down Expand Up @@ -142,8 +141,10 @@ async def get_active_user_speedrun(user_id: int, game_mode: int) -> UserSpeedrun

@dataclass
class SpeedrunScore:
score_value: int
score_rank: int
value: int
rank: int
mods: int
beatmap_id: int
song_name: str


Expand Down Expand Up @@ -181,11 +182,13 @@ async def get_active_speedrun_scores(
recs = await glob.db.fetchAll(
f"""
SELECT
{score_read_param} AS score_value,
{score_read_param} AS value,
DENSE_RANK() OVER (
PARTITION BY userid
ORDER BY pp DESC
) AS score_rank,
) AS rank,
score.mods,
beatmaps.beatmap_id,
beatmaps.song_name
FROM scores
JOIN users ON scores.userid = users.id
Expand All @@ -207,8 +210,10 @@ async def get_active_speedrun_scores(
)
return [
SpeedrunScore(
score_value=rec["score_value"],
score_rank=rec["score_rank"],
value=rec["value"],
rank=rec["rank"],
mods=rec["mods"],
beatmap_id=rec["beatmap_id"],
song_name=rec["song_name"],
)
for rec in recs
Expand Down
10 changes: 9 additions & 1 deletion constants/chatbotCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,17 @@ async def end_speedrun(fro: str, chan: str, message: list[str]) -> str:
speedrun = speedrun_results.speedrun
scores = speedrun_results.scores

def get_beatmap_url(beatmap_id: int) -> str:
return f"https://osu.ppy.sh/beatmaps/{beatmap_id}"

def get_url_embed(url: str, text: str) -> str:
return f"[{url} {text}]"

ret = f"Speedrun ended! Total score: {speedrun.score_value:,.2f} in {speedrun.timeframe}\n"
for score in scores:
ret += f"{score.song_name}: {score.score_value:,.2f}\n"
beatmap_url = get_beatmap_url(score.beatmap_id)
mods_str = f" +{scoreUtils.readableMods(score.mods)}" if score.mods else ""
ret += f"{get_url_embed(beatmap_url, score.song_name)}: {score.value:,.2f}{mods_str}\n"

return ret[:-1]

Expand Down

0 comments on commit 912d65d

Please sign in to comment.