Refactor: Next.js+Firebase → React(Vite) + FastAPI + PostgreSQL
- 백엔드: FastAPI + SQLAlchemy(async) + PostgreSQL, 별도 워커(APScheduler) - 프론트: React 19 + Vite + TS + Tailwind v4 (기존 UI 이식, API 연동) - docker-compose: db · api · worker · frontend 일괄 실행 - 경기 일정: openfootball 매일 09:00 크롤링 → DB upsert (신규 경기 자동 삽입+예측 생성) - AI 예측: GPT·Claude·Gemini 실 API 매일 생성 → DB 저장 → 조회 (목데이터 제거) - 투표창: 오픈 킥오프 D-2 / 마감 킥오프 1시간 전, lockAt 백엔드 전달→프론트 카운트다운 - 채점/리더보드: docs/SCORING.md 기준 누적 포인트 - crowd: 0 시작, 실제 제출로만 증분 - 구 Next.js/Firebase 파일 제거, README/AGENTS 갱신 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
35414a8d47
commit
6ffe0dfca3
95 files changed
+5266
-8856
No files matched your search
@@ -0,0 +1,72 @@
|
||||
"""수집한 일정을 DB에 반영 — 워커(스케줄링 서버)가 매일 호출.
|
||||
|
||||
매칭 키 = (teamA_code, teamB_code) 순서쌍 (그룹 라운드로빈에서 유일).
|
||||
- 기존 경기: 킥오프/venue/투표시간(opens·lock) 갱신. 결과·예측·crowd·라운드/후킹은 보존.
|
||||
- 신규 경기: matchId 생성 + crowd 초기화하여 삽입(예측은 워커 AI 생성이 채움).
|
||||
종료(result) 경기는 시각 변경하지 않음.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from ..models import CrowdStats, Match
|
||||
from ..schedule_data import TEAMS, lock_at, opens_at, parse_kickoff
|
||||
|
||||
log = logging.getLogger("triplepick.schedule")
|
||||
|
||||
|
||||
async def sync_schedule(db: AsyncSession, records: list[dict]) -> dict:
|
||||
if not records:
|
||||
return {"updated": 0, "inserted": 0, "skipped": 0}
|
||||
|
||||
existing = (await db.execute(select(Match))).scalars().all()
|
||||
by_pair = {(m.team_a_code, m.team_b_code): m for m in existing}
|
||||
|
||||
updated = inserted = skipped = 0
|
||||
for rec in records:
|
||||
a, b = rec["teamA"], rec["teamB"]
|
||||
kickoff = parse_kickoff(rec["kickoffKst"])
|
||||
m = by_pair.get((a, b))
|
||||
if m is not None:
|
||||
if m.result_outcome is not None:
|
||||
skipped += 1
|
||||
continue
|
||||
m.kickoff_at = kickoff
|
||||
m.opens_at = opens_at(kickoff)
|
||||
m.lock_at = lock_at(kickoff)
|
||||
if rec.get("venue"):
|
||||
m.venue = rec["venue"]
|
||||
updated += 1
|
||||
else:
|
||||
ta, tb = TEAMS.get(a), TEAMS.get(b)
|
||||
if not ta or not tb:
|
||||
skipped += 1
|
||||
continue
|
||||
match_id = f"A_{a}_{b}_{kickoff.astimezone().strftime('%Y%m%d')}"
|
||||
db.add(
|
||||
Match(
|
||||
match_id=match_id,
|
||||
round_label="Match",
|
||||
group="A",
|
||||
team_a_name=ta["name"], team_a_short=ta["shortName"],
|
||||
team_a_code=ta["code"], team_a_flag=ta["flag"],
|
||||
team_b_name=tb["name"], team_b_short=tb["shortName"],
|
||||
team_b_code=tb["code"], team_b_flag=tb["flag"],
|
||||
venue=rec.get("venue", ""),
|
||||
hook_text=f"{ta['shortName']} vs {tb['shortName']}, AI의 예측은",
|
||||
kickoff_at=kickoff,
|
||||
opens_at=opens_at(kickoff),
|
||||
lock_at=lock_at(kickoff),
|
||||
status="scheduled",
|
||||
)
|
||||
)
|
||||
db.add(CrowdStats(match_id=match_id, total=0, team_a_win=0, draw=0, team_b_win=0))
|
||||
inserted += 1
|
||||
|
||||
await db.commit()
|
||||
result = {"updated": updated, "inserted": inserted, "skipped": skipped}
|
||||
log.info("schedule sync: %s", result)
|
||||
return result
|
||||
Reference in new issue
Block a user