Crowd Pick 합 100% 초과 버그 수정 및 투표 오픈을 킥오프 7일 전으로 변경
This commit is contained in:
1 parent
76eafceee8
commit
0a64a220ca
5 files changed
+70
-9
No files matched your search
@@ -8,7 +8,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from ..config import settings
|
||||
from ..database import get_db
|
||||
from ..domain import now_utc
|
||||
from ..models import AIPrediction, Match, PageVisit
|
||||
from ..models import AIPrediction, CrowdStats, Match, PageVisit, UserPrediction
|
||||
from ..schemas import AdminAIPredictionIn, AdminSetResultIn, DailyVisitOut, GenericOk
|
||||
from ..services.grading import apply_result
|
||||
|
||||
@@ -85,3 +85,50 @@ async def daily_visits(db: AsyncSession = Depends(get_db)) -> list[DailyVisitOut
|
||||
)
|
||||
).all()
|
||||
return [DailyVisitOut(date=d.isoformat(), uniqueVisitors=c) for d, c in rows]
|
||||
|
||||
|
||||
@router.post(
|
||||
"/recount-crowd", response_model=GenericOk, dependencies=[Depends(require_admin)]
|
||||
)
|
||||
async def recount_crowd(db: AsyncSession = Depends(get_db)) -> GenericOk:
|
||||
"""crowd_stats 를 user_predictions(진실 원천)에서 재집계.
|
||||
|
||||
과거 같은 outcome 재제출로 팀 컬럼만 부풀려진(=합 100% 초과) 행을 복구한다.
|
||||
"""
|
||||
# 경기별 outcome 분포 집계
|
||||
rows = (
|
||||
await db.execute(
|
||||
select(
|
||||
UserPrediction.match_id,
|
||||
UserPrediction.outcome,
|
||||
func.count(),
|
||||
).group_by(UserPrediction.match_id, UserPrediction.outcome)
|
||||
)
|
||||
).all()
|
||||
|
||||
tally: dict[str, dict[str, int]] = {}
|
||||
for match_id, outcome, c in rows:
|
||||
t = tally.setdefault(
|
||||
match_id, {"total": 0, "team_a_win": 0, "draw": 0, "team_b_win": 0}
|
||||
)
|
||||
col = {"TEAM_A_WIN": "team_a_win", "DRAW": "draw", "TEAM_B_WIN": "team_b_win"}[outcome]
|
||||
t[col] += c
|
||||
t["total"] += c
|
||||
|
||||
stats = (await db.execute(select(CrowdStats))).scalars().all()
|
||||
fixed = 0
|
||||
for s in stats:
|
||||
t = tally.get(s.match_id, {"total": 0, "team_a_win": 0, "draw": 0, "team_b_win": 0})
|
||||
if (
|
||||
s.total != t["total"]
|
||||
or s.team_a_win != t["team_a_win"]
|
||||
or s.draw != t["draw"]
|
||||
or s.team_b_win != t["team_b_win"]
|
||||
):
|
||||
s.total = t["total"]
|
||||
s.team_a_win = t["team_a_win"]
|
||||
s.draw = t["draw"]
|
||||
s.team_b_win = t["team_b_win"]
|
||||
fixed += 1
|
||||
await db.commit()
|
||||
return GenericOk(ok=True, detail="crowd recounted", extra={"matchesFixed": fixed})
|
||||
Reference in new issue
Block a user