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