feat: KBO/MLB 운영 안정화 — 순위 탭·라이브 개선·취소/더블헤더 지원·야구 점수제
AI 예측 - 생성 시점을 킥오프 22시간 전으로 변경(선발투수 예고 이후), 잡 매시간 실행 - 경기 시작 후 생성 금지(사후 예측 방지), 경기 단위 커밋으로 중단 시 진행분 보존 일정·라이브 UI - 야구 일정에 순위 탭 추가 (KBO 단일 순위표 · MLB 6개 디비전, /api/standings 신설) - 경기중 카드에 현재 이닝·실시간 스코어 표시 (30s 폴링, 서버 15s 캐시) - MLB 선발 누락 수정: statsapi 날짜 파라미터 미국 날짜 기준 보정(-1일) - 라이브 대기타석 스크롤바 다크 테마 처리 운영 견고성 - 우천취소: 경기 삭제 → cancelled 상태 보존 (투표·예측 기록 유지, 정산/투표/AI 제외) - 더블헤더: 시작시각순 seq로 1·2차전 분리 등록 (match_id _2, 정산·라이브·프리뷰 매핑) - 축구 데이터 수집을 wc 리그로 한정 (야구 팀을 축구 API에 검색하던 쿼터 낭비 수정) 점수제 - 야구 판정 완화: 근접=득실차 ±1, 부분=한 팀 득점 ±1 (등급·배점은 리그 공통 유지) - 채점 판정을 _grade_of() 단일 함수로 통합, 종료된 야구 경기 재채점 - 배점 안내 모달 야구 문구 분리, docs/SCORING.md 갱신 기타 - 야구 전용 댓글 닉네임 풀 (종목별 세션 캐시 분리) - 리더보드 리그별 조회 연동 (?league=)
This commit is contained in:
1 parent
bfaf621949
commit
4e1ebc8989
46 files changed
+2560
-188
No files matched your search
@@ -0,0 +1,53 @@
|
||||
"""리그 순위표 API — 워커가 캐싱한 standings:{league} 를 팀 정보와 합쳐 서빙.
|
||||
|
||||
KBO: 단일 테이블(10팀, 순위순). MLB: 디비전(AL/NL × 동·중·서) 6그룹.
|
||||
캐시가 아직 없으면 빈 groups 를 반환한다(프론트는 안내 문구 표시).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from ..database import get_db
|
||||
from ..models import DataCache
|
||||
from ..teams_baseball import team_info
|
||||
|
||||
router = APIRouter(prefix="/api/standings", tags=["standings"])
|
||||
|
||||
# MLB 디비전 표시 순서 (AL 동→중→서, NL 동→중→서)
|
||||
_MLB_DIV_ORDER = ["ALE", "ALC", "ALW", "NLE", "NLC", "NLW"]
|
||||
|
||||
|
||||
@router.get("")
|
||||
async def get_standings(
|
||||
league: str = Query(..., description="kbo | mlb"),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> dict:
|
||||
if league not in ("kbo", "mlb"):
|
||||
return {"league": league, "updatedAt": None, "groups": []}
|
||||
row = await db.get(DataCache, f"standings:{league}")
|
||||
table: dict = row.payload if row else {}
|
||||
rows = [{**team_info(league, code), **st} for code, st in table.items()]
|
||||
|
||||
if league == "kbo":
|
||||
rows.sort(key=lambda r: r.get("rank") or 99)
|
||||
groups = [{"key": None, "rows": rows}] if rows else []
|
||||
else:
|
||||
by_div: dict[str, list] = {}
|
||||
for r in rows:
|
||||
by_div.setdefault(r.get("div") or "", []).append(r)
|
||||
for lst in by_div.values():
|
||||
lst.sort(key=lambda r: r.get("rank") or 99)
|
||||
groups = [
|
||||
{"key": d, "rows": by_div[d]} for d in _MLB_DIV_ORDER if d in by_div
|
||||
]
|
||||
if not groups and rows:
|
||||
# 캐시가 div 주입 이전 버전이면 전체 승률순 단일 그룹으로 폴백
|
||||
rows.sort(key=lambda r: -float(r.get("wra") or 0))
|
||||
groups = [{"key": None, "rows": rows}]
|
||||
|
||||
return {
|
||||
"league": league,
|
||||
"updatedAt": row.fetched_at.isoformat() if row and row.fetched_at else None,
|
||||
"groups": groups,
|
||||
}
|
||||
Reference in new issue
Block a user