Merge remote-tracking branch 'origin/main' into feat/watch-summary
This commit is contained in:
commit
f6ec296130
84 files changed
+3406
-879
No files matched your search
@@ -3,13 +3,14 @@ from typing import Annotated, Literal, Optional, Union
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from common.enums import PostType, SlotTone
|
||||
from common.enums import PostType, SkySituation, SlotTone
|
||||
from common.models.gmodel import Res_WebPacketProtocol, WebPacketProtocol
|
||||
|
||||
|
||||
class Row(WebPacketProtocol):
|
||||
label: str
|
||||
value: str
|
||||
place: Optional[str] = Field(default=None, description="위치가 정해진 장소면 지도에서 찾을 이름 (앱이 네이버 지도 링크를 건다)")
|
||||
|
||||
|
||||
class HourCell(WebPacketProtocol):
|
||||
@@ -62,6 +63,7 @@ class SunsetSlide(WebPacketProtocol):
|
||||
score: int
|
||||
grade_label: str
|
||||
cuts: list[Cut]
|
||||
situation: Optional[SkySituation] = Field(default=None, description="하늘 상황. 앱이 카드 하늘 색을 고른다")
|
||||
|
||||
|
||||
class WeekDay(WebPacketProtocol):
|
||||
@@ -143,6 +145,8 @@ class Hero(WebPacketProtocol):
|
||||
weather_score: Optional[int] = None
|
||||
top1: Optional[TopIndex] = None
|
||||
bubble: Optional[str] = None
|
||||
moon_name: Optional[str] = Field(default=None, description="오늘 밤 달 모양: 삭·초승달·상현달·차오르는 달·보름달·기우는 달·하현달·그믐달")
|
||||
moon_pct: Optional[int] = Field(default=None, description="달이 밝게 보이는 비율 0~100")
|
||||
|
||||
|
||||
class BandEvent(WebPacketProtocol):
|
||||
|
||||
@@ -5,7 +5,7 @@ from fastapi import APIRouter, Depends, Path, Query
|
||||
|
||||
from common.enums import ErrorType, IndexCategory
|
||||
from common.models.errors import error_info
|
||||
from router.v1.index.protocol import Factor, IndexSummary, Res_IndexDetail, Res_IndexList, TrendPoint
|
||||
from router.v1.index.protocol import Factor, IndexSummary, Res_IndexDetail, Res_IndexList, ScoreBand, TrendPoint
|
||||
from services.calc.index_calc import AXES, axis_label, zero_rules_text
|
||||
from services.index_service import IndexItem, IndexService, slot_label
|
||||
|
||||
@@ -53,4 +53,12 @@ async def get_index(index_id: int = Path(...), region: str = Query(..., descript
|
||||
if getattr(d, f"weight_{a}")
|
||||
],
|
||||
zero_rules=zero_rules_text(d.zero_rules), zero_reason=s.zero_reason, limit=d.limit_description,
|
||||
bands=_bands(d.sentences or {}, s.score),
|
||||
)
|
||||
|
||||
|
||||
def _bands(sentences: dict, score: int) -> list[ScoreBand]:
|
||||
"""seed 의 sentences {"0": ..., "30": ..., "60": ..., "80": ...} 를 구간으로. 키는 구간 시작 점수."""
|
||||
lows = sorted(int(k) for k in sentences)
|
||||
highs = [lo - 1 for lo in lows[1:]] + [100]
|
||||
return [ScoreBand(low=lo, high=hi, text=sentences[str(lo)], current=lo <= score <= hi) for lo, hi in zip(lows, highs)]
|
||||
@@ -44,6 +44,13 @@ class Factor(WebPacketProtocol):
|
||||
note: str
|
||||
|
||||
|
||||
class ScoreBand(WebPacketProtocol):
|
||||
low: int
|
||||
high: int
|
||||
text: str = Field(description="이 점수 구간이면 어떤 날인지, 통통 튀는 말투 한 문장")
|
||||
current: bool = Field(description="오늘 점수가 이 구간에 있음")
|
||||
|
||||
|
||||
class Res_IndexDetail(Res_WebPacketProtocol):
|
||||
index: Optional[IndexSummary] = None
|
||||
description: Optional[str] = None
|
||||
@@ -51,3 +58,4 @@ class Res_IndexDetail(Res_WebPacketProtocol):
|
||||
zero_rules: Optional[str] = None
|
||||
zero_reason: Optional[str] = None
|
||||
limit: Optional[str] = None
|
||||
bands: list[ScoreBand] = Field(default=[], description="점수 구간별 설명 (0~29, 30~59, 60~79, 80~100)")
|
||||
@@ -1,7 +1,9 @@
|
||||
from datetime import date, datetime
|
||||
from typing import Literal, Optional
|
||||
|
||||
from common.enums import Confidence, SkyGrade, SkyType
|
||||
from pydantic import Field
|
||||
|
||||
from common.enums import Confidence, SkyGrade, SkySituation, SkyType
|
||||
from common.models.gmodel import Res_WebPacketProtocol, WebPacketProtocol
|
||||
|
||||
|
||||
@@ -19,6 +21,9 @@ class SkyScoreData(WebPacketProtocol):
|
||||
grade_label: str
|
||||
confidence: Confidence
|
||||
best_times: list[BestTime] = []
|
||||
situation: Optional[SkySituation] = None
|
||||
situation_label: Optional[str] = Field(default=None, description="하늘 상황 한 줄: 구름에 가려요 / 구름이 적어 짧게 끝나요 / 하늘이 넓게 물들 수 있어요 등")
|
||||
verdict: Optional[Literal["go", "maybe", "rest"]] = None
|
||||
|
||||
|
||||
class SpotData(WebPacketProtocol):
|
||||
@@ -28,6 +33,7 @@ class SpotData(WebPacketProtocol):
|
||||
lat: float
|
||||
lon: float
|
||||
distance_km: float
|
||||
direction: str = Field(default="", description="내 구에서 본 방향 (16방위, 예: 북서)")
|
||||
|
||||
|
||||
class PlanSpot(WebPacketProtocol):
|
||||
@@ -43,6 +49,9 @@ class SkyPlanData(WebPacketProtocol):
|
||||
reason: str
|
||||
score: int
|
||||
grade_label: str
|
||||
situation_label: Optional[str] = None
|
||||
models_total: Optional[int] = Field(default=None, description="계산에 쓴 예보 모델 수")
|
||||
models_agree: Optional[int] = Field(default=None, description="그중 같은 하늘 상황을 낸 모델 수")
|
||||
best_at: Optional[datetime] = None
|
||||
spot: Optional[PlanSpot] = None
|
||||
timeline: list[BestTime] = []
|
||||
@@ -66,8 +75,10 @@ class RankData(WebPacketProtocol):
|
||||
note: Optional[str] = None
|
||||
score: int
|
||||
grade: SkyGrade
|
||||
situation_label: Optional[str] = None
|
||||
|
||||
|
||||
class Res_SkyRanking(Res_WebPacketProtocol):
|
||||
day: Optional[date] = None
|
||||
summary: Optional[str] = Field(default=None, description="대부분 같은 하늘 상황인 날 한 줄 (예: 오늘은 전국이 맑아 대부분 짧게 끝나요)")
|
||||
items: list[RankData] = []
|
||||
@@ -1,12 +1,13 @@
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
|
||||
from common.database.model.models import SkyScore
|
||||
from common.enums import Confidence, ErrorType, SkyGrade, SkyType
|
||||
from common.enums import Confidence, ErrorType, SkyGrade, SkySituation, SkyType
|
||||
from common.models.errors import error_info
|
||||
from common.utils.kma_time import now_kst
|
||||
from common.utils.text import compass
|
||||
from router.v1.sky.protocol import BestTime, PlanSpot, RankData, Res_Sky, Res_SkyRanking, SkyPlanData, SkyScoreData, SpotData
|
||||
from services.calc.sky_score import GRADE_LABEL
|
||||
from services.sky_service import SkyPlan, SkyService
|
||||
from services.calc.sky_score import GRADE_LABEL, SITUATION_LINE
|
||||
from services.sky_service import SkyPlan, SkyService, day_verdict, ranking_summary
|
||||
|
||||
router = APIRouter(prefix="/v1/sky", tags=["sky"])
|
||||
|
||||
@@ -15,12 +16,18 @@ def _score(x: SkyScore) -> SkyScoreData:
|
||||
return SkyScoreData(
|
||||
day=x.score_date, sky_type=SkyType(x.sky_type), score=x.score, grade=g, grade_label=GRADE_LABEL[g],
|
||||
confidence=Confidence(x.confidence), best_times=[BestTime(**b) for b in x.best_times],
|
||||
situation=SkySituation(x.situation) if x.situation else None, situation_label=_situation(x), verdict=day_verdict(x),
|
||||
)
|
||||
|
||||
|
||||
def _situation(x: SkyScore) -> str | None:
|
||||
return SITUATION_LINE[SkySituation(x.situation)] if x.situation else None
|
||||
|
||||
|
||||
def _plan(p: SkyPlan) -> SkyPlanData:
|
||||
return SkyPlanData(
|
||||
day=p.day, when=p.when, verdict=p.verdict, headline=p.headline, reason=p.reason, score=p.score, grade_label=p.grade_label,
|
||||
situation_label=p.situation_label, models_total=p.models_total, models_agree=p.models_agree,
|
||||
best_at=p.best_at, spot=PlanSpot(name=p.spot.spot.name, distance_km=p.spot.distance_km) if p.spot else None,
|
||||
timeline=[BestTime(**b) for b in p.timeline], outlook=p.outlook,
|
||||
)
|
||||
@@ -36,7 +43,8 @@ async def get_sky(region: str = Query(..., description="구 행정코드"), serv
|
||||
sunset=_score(view.sunset) if view.sunset else None, sunrise=_score(view.sunrise) if view.sunrise else None,
|
||||
days=[_score(x) for x in view.days],
|
||||
spots=[
|
||||
SpotData(no=i + 1, name=s.spot.name, description=s.spot.description, lat=float(s.spot.lat), lon=float(s.spot.lon), distance_km=s.distance_km)
|
||||
SpotData(no=i + 1, name=s.spot.name, description=s.spot.description, lat=float(s.spot.lat), lon=float(s.spot.lon), distance_km=s.distance_km,
|
||||
direction=compass(s.direction))
|
||||
for i, s in enumerate(view.spots)
|
||||
],
|
||||
plan=_plan(view.plan) if view.plan else None,
|
||||
@@ -49,9 +57,10 @@ async def get_sky_ranking(service: SkyService = Depends()) -> Res_SkyRanking:
|
||||
if err is not ErrorType.SUCCESS:
|
||||
return Res_SkyRanking(result=error_info(err))
|
||||
return Res_SkyRanking(
|
||||
day=now_kst().date(),
|
||||
day=now_kst().date(), summary=ranking_summary(items),
|
||||
items=[
|
||||
RankData(rank=i.rank, region_code=i.region.code, name=i.region.name, note=i.region.ranking_note, score=i.score.score, grade=SkyGrade(i.score.grade))
|
||||
RankData(rank=i.rank, region_code=i.region.code, name=i.region.name, note=i.region.ranking_note, score=i.score.score, grade=SkyGrade(i.score.grade),
|
||||
situation_label=_situation(i.score))
|
||||
for i in items
|
||||
],
|
||||
)
|
||||
Reference in new issue
Block a user