refactor(recalculate): make it a tool
This commit is contained in:
7
main.py
7
main.py
@@ -1,9 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from contextlib import asynccontextmanager
|
||||
from datetime import datetime
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from app.config import settings
|
||||
@@ -38,7 +36,6 @@ from app.service.init_geoip import init_geoip
|
||||
from app.service.load_achievements import load_achievements
|
||||
from app.service.online_status_maintenance import schedule_online_status_maintenance
|
||||
from app.service.osu_rx_statistics import create_rx_statistics
|
||||
from app.service.recalculate import recalculate
|
||||
from app.service.redis_message_system import redis_message_system
|
||||
from app.service.stats_scheduler import start_stats_scheduler, stop_stats_scheduler
|
||||
from app.utils import bg_tasks
|
||||
@@ -188,10 +185,6 @@ if settings.osu_web_client_secret == "your_osu_web_client_secret_here":
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
||||
if os.environ.get("RECALCULATE", "false").lower() == "true":
|
||||
asyncio.run(recalculate())
|
||||
exit()
|
||||
|
||||
uvicorn.run(
|
||||
"main:app",
|
||||
host=settings.host,
|
||||
|
||||
@@ -2,13 +2,17 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import math
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
||||
|
||||
from app.calculator import (
|
||||
calculate_pp,
|
||||
calculate_score_to_level,
|
||||
calculate_weighted_acc,
|
||||
calculate_weighted_pp,
|
||||
clamp,
|
||||
pre_fetch_and_calculate_pp,
|
||||
)
|
||||
from app.config import settings
|
||||
from app.const import BANCHOBOT_ID
|
||||
@@ -64,6 +68,7 @@ async def recalculate():
|
||||
|
||||
await session.commit()
|
||||
logger.success(f"Recalculated for mode: {mode}, total users: {len(statistics_list)}")
|
||||
await engine.dispose()
|
||||
|
||||
|
||||
async def _recalculate_pp(
|
||||
@@ -99,8 +104,8 @@ async def _recalculate_pp(
|
||||
score.pp = 0
|
||||
return
|
||||
try:
|
||||
pp = await pre_fetch_and_calculate_pp(score, beatmap_id, session, redis, fetcher)
|
||||
score.pp = pp
|
||||
beatmap_raw = await fetcher.get_or_fetch_beatmap_raw(redis, beatmap_id)
|
||||
pp = await calculate_pp(score, beatmap_raw, session)
|
||||
if pp == 0:
|
||||
return
|
||||
if score.beatmap_id not in prev or prev[score.beatmap_id].pp < pp:
|
||||
@@ -280,3 +285,7 @@ async def _recalculate_statistics(statistics: UserStatistics, session: AsyncSess
|
||||
case Rank.A:
|
||||
statistics.grade_a -= 1
|
||||
statistics.level_current = calculate_score_to_level(statistics.total_score)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(recalculate())
|
||||
Reference in New Issue
Block a user