fix(score): make scores of loved beatmap as ranked scores
This commit is contained in:
@@ -13,8 +13,10 @@ from app.calculator import (
|
||||
clamp,
|
||||
pre_fetch_and_calculate_pp,
|
||||
)
|
||||
from app.config import settings
|
||||
from app.database.team import TeamMember
|
||||
from app.dependencies.database import get_redis
|
||||
from app.models.beatmap import BeatmapRankStatus
|
||||
from app.models.model import (
|
||||
CurrentUserAttributes,
|
||||
PinAttributes,
|
||||
@@ -714,9 +716,12 @@ async def process_user(
|
||||
score: Score,
|
||||
score_token: int,
|
||||
beatmap_length: int,
|
||||
ranked: bool = False,
|
||||
has_leaderboard: bool = False,
|
||||
beatmap_status: BeatmapRankStatus,
|
||||
):
|
||||
has_pp = beatmap_status.has_pp() or settings.enable_all_beatmap_pp
|
||||
ranked = beatmap_status.ranked() or settings.enable_all_beatmap_pp
|
||||
has_leaderboard = beatmap_status.has_leaderboard() or settings.enable_all_beatmap_leaderboard
|
||||
|
||||
mod_for_save = mod_to_save(score.mods)
|
||||
previous_score_best = await get_user_best_score_in_beatmap(session, score.beatmap_id, user.id, score.gamemode)
|
||||
previous_score_best_mod = await get_user_best_score_with_mod_in_beatmap(
|
||||
@@ -809,28 +814,31 @@ async def process_user(
|
||||
previous_score_best_mod.rank = score.rank
|
||||
previous_score_best_mod.score_id = score.id
|
||||
|
||||
statistics.play_count += 1
|
||||
mouthly_playcount.count += 1
|
||||
playtime, is_valid = calculate_playtime(score, beatmap_length)
|
||||
if is_valid:
|
||||
redis = get_redis()
|
||||
await redis.xadd(f"score:existed_time:{score_token}", {"time": playtime})
|
||||
statistics.play_count += 1
|
||||
mouthly_playcount.count += 1
|
||||
statistics.play_time += playtime
|
||||
with session.no_autoflush:
|
||||
await process_beatmap_playcount(session, user.id, score.beatmap_id)
|
||||
|
||||
statistics.count_100 += score.n100 + score.nkatu
|
||||
statistics.count_300 += score.n300 + score.ngeki
|
||||
statistics.count_50 += score.n50
|
||||
statistics.count_miss += score.nmiss
|
||||
statistics.total_hits += score.n300 + score.n100 + score.n50 + score.ngeki + score.nkatu
|
||||
|
||||
if score.passed and ranked:
|
||||
if score.passed and has_pp:
|
||||
with session.no_autoflush:
|
||||
statistics.pp, statistics.hit_accuracy = await calculate_user_pp(
|
||||
session, statistics.user_id, score.gamemode
|
||||
)
|
||||
|
||||
if add_to_db:
|
||||
session.add(mouthly_playcount)
|
||||
with session.no_autoflush:
|
||||
await process_beatmap_playcount(session, user.id, score.beatmap_id)
|
||||
|
||||
await session.commit()
|
||||
await session.refresh(user)
|
||||
|
||||
|
||||
@@ -31,6 +31,10 @@ class BeatmapRankStatus(IntEnum):
|
||||
BeatmapRankStatus.APPROVED,
|
||||
}
|
||||
|
||||
def ranked(self) -> bool:
|
||||
# https://osu.ppy.sh/wiki/Gameplay/Score/Ranked_score
|
||||
return self in {BeatmapRankStatus.RANKED, BeatmapRankStatus.APPROVED, BeatmapRankStatus.LOVED}
|
||||
|
||||
|
||||
class Genre(IntEnum):
|
||||
ANY = 0
|
||||
|
||||
@@ -135,13 +135,12 @@ async def submit_score(
|
||||
db_beatmap = await Beatmap.get_or_fetch(db, fetcher, bid=beatmap)
|
||||
except HTTPError:
|
||||
raise HTTPException(status_code=404, detail="Beatmap not found")
|
||||
has_pp = db_beatmap.beatmap_status.has_pp() | settings.enable_all_beatmap_pp
|
||||
has_leaderboard = db_beatmap.beatmap_status.has_leaderboard() | settings.enable_all_beatmap_leaderboard
|
||||
status = db_beatmap.beatmap_status
|
||||
beatmap_length = db_beatmap.total_length
|
||||
score = await process_score(
|
||||
current_user,
|
||||
beatmap,
|
||||
has_pp,
|
||||
status.has_pp() or settings.enable_all_beatmap_pp,
|
||||
score_token,
|
||||
info,
|
||||
fetcher,
|
||||
@@ -153,15 +152,7 @@ async def submit_score(
|
||||
await db.refresh(current_user)
|
||||
score_id = score.id
|
||||
score_token.score_id = score_id
|
||||
await process_user(
|
||||
db,
|
||||
current_user,
|
||||
score,
|
||||
token,
|
||||
beatmap_length,
|
||||
has_pp,
|
||||
has_leaderboard,
|
||||
)
|
||||
await process_user(db, current_user, score, token, beatmap_length, status)
|
||||
score = (await db.exec(select(Score).options(joinedload(Score.user)).where(Score.id == score_id))).one()
|
||||
|
||||
resp: ScoreResp = await ScoreResp.from_db(db, score)
|
||||
|
||||
Reference in New Issue
Block a user