전체일정 스코어 조정, utc 시간 -> kst 변경
This commit is contained in:
1 parent
7185cfbb72
commit
8a4a23b0cb
9 files changed
+71
-35
No files matched your search
+25
-6
@@ -8,7 +8,7 @@ phase 는 now 기준 동적 계산 (lib/schedule.ts matchPhase 와 동일 규칙
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
from .config import settings
|
||||
from .models import AIPrediction, CrowdStats, Match
|
||||
@@ -25,15 +25,32 @@ def now_utc() -> datetime:
|
||||
return datetime.now(timezone.utc)
|
||||
|
||||
|
||||
KST = timezone(timedelta(hours=9))
|
||||
|
||||
|
||||
def ensure_aware(dt: datetime) -> datetime:
|
||||
"""naive datetime(일부 DB 드라이버 반환)을 UTC aware 로 보정."""
|
||||
return dt.replace(tzinfo=timezone.utc) if dt.tzinfo is None else dt
|
||||
|
||||
|
||||
def kst_iso(dt: datetime) -> str:
|
||||
"""저장값(UTC)을 KST(+09:00) ISO 문자열로 직렬화 — 프론트 표시 기준 통일."""
|
||||
return ensure_aware(dt).astimezone(KST).isoformat()
|
||||
|
||||
|
||||
def compute_phase(m: Match, now: datetime | None = None) -> str:
|
||||
"""투표/경기 단계:
|
||||
finished 결과 입력됨 → "종료"
|
||||
live 킥오프 이후, 결과 입력 전 → "경기중"
|
||||
locked 투표 마감(킥오프 1h 전) ~ 킥오프 → "투표 종료"(비활성)
|
||||
scheduled 오픈 전 → "오픈 예정"
|
||||
open 투표 중
|
||||
"""
|
||||
now = now or now_utc()
|
||||
if m.result_outcome is not None:
|
||||
return "finished"
|
||||
if now >= ensure_aware(m.kickoff_at):
|
||||
return "live"
|
||||
if now >= ensure_aware(m.lock_at):
|
||||
return "locked"
|
||||
if now < ensure_aware(m.opens_at):
|
||||
@@ -110,18 +127,20 @@ def match_out(
|
||||
order = {"GPT": 0, "Claude": 1, "Gemini": 2}
|
||||
for p in sorted(m.predictions, key=lambda x: order.get(x.model, 9)):
|
||||
preds.append(prediction_out(p, lang))
|
||||
# status·phase 를 동일한 실시간 계산값으로 통일 — 워커 틱 지연과 무관하게 일관.
|
||||
phase = compute_phase(m, now)
|
||||
return MatchOut(
|
||||
matchId=m.match_id,
|
||||
roundLabel=m.round_label,
|
||||
group=m.group,
|
||||
teamA=_team_a(m),
|
||||
teamB=_team_b(m),
|
||||
kickoffKst=m.kickoff_at.isoformat(),
|
||||
kickoffKst=kst_iso(m.kickoff_at),
|
||||
venue=m.venue,
|
||||
opensAt=m.opens_at.isoformat(),
|
||||
lockAt=m.lock_at.isoformat(),
|
||||
status=m.status,
|
||||
phase=compute_phase(m, now),
|
||||
opensAt=kst_iso(m.opens_at),
|
||||
lockAt=kst_iso(m.lock_at),
|
||||
status=phase,
|
||||
phase=phase,
|
||||
votingOpen=is_open_for_voting(m, now),
|
||||
hookText=m.hook_text,
|
||||
result=result,
|
||||
|
||||
Reference in new issue
Block a user