Skip to content

Commit b6deedb

Browse files
committed
correctly reset per-role ratings when recalculating
1 parent bd9c88a commit b6deedb

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

handlers/admin/index.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ async def admin_index(request: Request) -> str:
2727
@admin_only
2828
async def admin_recalculate_ratings(request: Request) -> str:
2929
request.app.ctx.banner["text"] = "Rating recalculation in progress, stats may be inaccurate and the site may be slow"
30-
request.app.create_task(recalculate_ratings(), name="Recalculate Ratings").add_done_callback(lambda _: reset_banner())
30+
request.app.add_task(recalculate_ratings(), name="Recalculate Ratings").add_done_callback(lambda _: reset_banner())
3131

3232
return response.json({"status": "ok"})
3333

@@ -36,7 +36,7 @@ async def admin_recalculate_ratings(request: Request) -> str:
3636
@admin_only
3737
async def admin_recalculate_sm5_ratings(request: Request) -> str:
3838
request.app.ctx.banner["text"] = "Rating recalculation in progress, stats may be inaccurate and the site may be slow"
39-
request.app.create_task(recalculate_sm5_ratings(), name="Recalculate SM5 Ratings").add_done_callback(lambda _: reset_banner())
39+
request.app.add_task(recalculate_sm5_ratings(), name="Recalculate SM5 Ratings").add_done_callback(lambda _: reset_banner())
4040

4141
return response.json({"status": "ok"})
4242

@@ -45,7 +45,7 @@ async def admin_recalculate_sm5_ratings(request: Request) -> str:
4545
@admin_only
4646
async def admin_recalculate_lb_ratings(request: Request) -> str:
4747
request.app.ctx.banner["text"] = "Rating recalculation in progress, stats may be inaccurate and the site may be slow"
48-
request.app.create_task(recalculate_laserball_ratings(), name="Recalculate Laserball Ratings").add_done_callback(lambda _: reset_banner())
48+
request.app.add_task(recalculate_laserball_ratings(), name="Recalculate Laserball Ratings").add_done_callback(lambda _: reset_banner())
4949

5050
return response.json({"status": "ok"})
5151

helpers/ratinghelper.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,18 @@ async def recalculate_sm5_ratings(*, _sample_size: int=99999) -> None:
610610

611611
# reset sm5 ratings
612612

613+
logger.info("Resetting sm5 general ratings")
614+
613615
await Player.all().update(sm5_mu=MU, sm5_sigma=SIGMA)
614616

617+
# reset per-role ratings
618+
619+
for role in IntRole:
620+
if role == IntRole.OTHER:
621+
continue
622+
logger.info(f"Resetting {str(role).lower()} ratings")
623+
await Player.all().update(**{f"{str(role).lower()}_mu": MU, f"{str(role).lower()}_sigma": SIGMA})
624+
615625
# get all games and recalculate ratings
616626

617627
sm5_games = await SM5Game.all().order_by("start_time").limit(_sample_size)

0 commit comments

Comments
 (0)