diff --git a/backend/services/feed_service.py b/backend/services/feed_service.py index 0d66f06..4db95a6 100644 --- a/backend/services/feed_service.py +++ b/backend/services/feed_service.py @@ -74,6 +74,7 @@ _FEED_TTL_MAX = 3600 _PARTIAL_TTL = 60 _SUNSET_HOUR = 18 # 노을 시간대 각의 대략적인 순서용 _RAIN_PROB = 40 +_HERO_RAIN_PROB = 60 # 히어로 '오늘 비': 오늘 남은 칸 중 비 형태가 있거나 확률이 이만큼 넘는 첫 칸 _SUNSET_FULL = 60 _FEED_DAY_START = 3 # 03:00 에 그날 카드가 바뀐다 _COMMUTE_HOURS = (("내일 출근 8시", 8), ("내일 퇴근 7시", 19)) @@ -120,8 +121,11 @@ def _discomfort_label(v: int) -> str: def _hero_input(now: datetime, slot: str, cur: Optional[WeatherHourly], now_w: Optional[NowWeather], today: Optional[TodayWeather], uv: Optional[float]) -> HeroInput: temps = [float(x.row.temp_c) for x in today.slots if x.row] if today else [] rainy = [h for h in now_w.rain_hours if h.rain_type is not RainType.NONE] if now_w else [] + ahead = [x for x in today.slots if x.row and x.at > now] if today else [] + later = next((x.at for x in ahead if x.row.rain_type != RainType.NONE.value or x.row.rain_prob >= _HERO_RAIN_PROB), None) return HeroInput( now=now, night=slot in ("evening", "night"), rain_at=rainy[0].at if rainy else None, + rain_later_at=later, today_known=bool(ahead), air=AirGrade(now_w.air.grade) if now_w and now_w.air and now_w.air.grade is not None else None, uv=uv, temp_min=min(temps, default=None), temp_max=max(temps, default=None), temp=float(cur.temp_c) if cur else None, feels=float(cur.feels_c) if cur else None, discomfort=cur.discomfort_index if cur else None, diff --git a/backend/services/hero_stats.py b/backend/services/hero_stats.py index 318b526..02b501c 100644 --- a/backend/services/hero_stats.py +++ b/backend/services/hero_stats.py @@ -29,7 +29,9 @@ class HeroStatItem: class HeroInput: now: datetime night: bool - rain_at: Optional[datetime] = None + rain_at: Optional[datetime] = None # 앞으로 2시간 안에 비 오는 첫 시각 (초단기) + rain_later_at: Optional[datetime] = None # 그 뒤 오늘 안에 비 오는 첫 시각 (단기예보) + today_known: bool = False # 오늘 남은 시간 예보가 있어 '오늘 비 안 와요'라고 말할 수 있는지 air: Optional[AirGrade] = None uv: Optional[float] = None temp_min: Optional[float] = None @@ -57,6 +59,8 @@ def hero_stats(x: HeroInput) -> list[HeroStatItem]: alerts: list[HeroStatItem] = [] if x.rain_at is not None: alerts.append(HeroStatItem("rain", "umbrella", "지금 비", _rain_value(x.now, x.rain_at), "rain")) + elif x.rain_later_at is not None: + alerts.append(HeroStatItem("rain", "umbrella", "오늘 비", _rain_value(x.now, x.rain_later_at), "rain")) if x.air in (AirGrade.BAD, AirGrade.VERY_BAD): alerts.append(HeroStatItem("air", "mask", "미세먼지", GRADE_LABEL[x.air], "warn")) if not x.night and x.uv is not None and x.uv >= UV_HIGH: @@ -68,12 +72,10 @@ def hero_stats(x: HeroInput) -> list[HeroStatItem]: if x.discomfort is not None and x.discomfort >= MUGGY: alerts.append(HeroStatItem("muggy", "muggy", "불쾌지수", f"{x.discomfort} · {_discomfort_label(x.discomfort)}", "warn")) - # 비는 올 때만 알린다 (안 온다는 칸은 두지 않음) + # 챙길 게 없을 땐 하루 기준 비 소식과 밤의 달만. '미세먼지 좋음'·'자외선 낮음' 같은 값으로 칸을 채우지 않는다 fills: list[HeroStatItem] = [] - if x.air is not None: - fills.append(HeroStatItem("air", "vent", "미세먼지", GRADE_LABEL[x.air])) - if not x.night and x.uv is not None: - fills.append(HeroStatItem("uv", "glasses", "자외선", f"{round(x.uv)} · {uv_label(x.uv)}")) + if x.today_known and x.rain_at is None and x.rain_later_at is None: + fills.append(HeroStatItem("rain", "moon" if x.night else "sun", "오늘 밤 비" if x.night else "오늘 비", "안 와요")) if x.night and x.moon: fills.append(HeroStatItem("moon", "moon", "오늘 밤 달", x.moon)) diff --git a/backend/tests/test_hero_stats.py b/backend/tests/test_hero_stats.py index 3643b56..d7b0cc0 100644 --- a/backend/tests/test_hero_stats.py +++ b/backend/tests/test_hero_stats.py @@ -18,7 +18,14 @@ def test_clear_day_shows_uv_warning_and_temp_swing(): def test_rain_comes_first(): x = HeroInput(now=NOW, night=False, rain_at=NOW + timedelta(minutes=40), air=AirGrade.GOOD, uv=1.0) - assert _view(x) == [("umbrella", "지금 비", "오후 3시쯤 와요", "rain"), ("vent", "미세먼지", "좋음", "normal")] + assert _view(x) == [("umbrella", "지금 비", "오후 3시쯤 와요", "rain")] + + +def test_rain_later_today_and_no_rain_today(): + later = HeroInput(now=NOW, night=False, rain_later_at=NOW.replace(hour=18), today_known=True, air=AirGrade.GOOD, uv=1.0) + assert _view(later) == [("umbrella", "오늘 비", "오후 6시쯤 와요", "rain")] + dry = HeroInput(now=NOW, night=False, today_known=True, air=AirGrade.GOOD, uv=1.0) + assert _view(dry) == [("sun", "오늘 비", "안 와요", "normal")] def test_bad_air_beats_uv_and_wears_mask(): @@ -33,7 +40,7 @@ def test_summer_night_muggy_then_moon_and_no_card_for_no_rain(): def test_one_coldwind_card_only(): x = HeroInput(now=NOW, night=False, temp_min=5, temp_max=17, temp=10, feels=6, uv=2.0) - assert [s.icon for s in hero_stats(x)] == ["coldwind", "glasses"] + assert [s.icon for s in hero_stats(x)] == ["coldwind"] # 낮은 자외선으로 빈 칸을 채우지 않는다 def test_nothing_known_gives_nothing(): diff --git a/frontend/src/b/TodayPage.tsx b/frontend/src/b/TodayPage.tsx index da4d297..f55254a 100644 --- a/frontend/src/b/TodayPage.tsx +++ b/frontend/src/b/TodayPage.tsx @@ -124,7 +124,7 @@ function Hero({ hero, today, feedLoad, todayLoad }: HeroProps) { {feelsLine ?? } -
+
{/* 두 칸은 서버가 지금 챙길 것(비·미세먼지·자외선·일교차 등) 순서로 골라 준다 */} {hero?.stats?.length ? hero.stats.map((s) => (