diff --git a/backend/seed/index_definition.json b/backend/seed/index_definition.json index a14384d..e0ee25e 100644 --- a/backend/seed/index_definition.json +++ b/backend/seed/index_definition.json @@ -3730,5 +3730,159 @@ "sort_order": 51, "priority": 3, "months": [] + }, + { + "code": "umbrella_lost", + "name": "우산분실각", + "icon": "umbrella", + "category": 4, + "is_fun": false, + "is_core": false, + "has_detail": true, + "description": "오전 9시~밤 10시, 비가 그쳐서 우산을 두고 오기 쉬운 정도", + "windows": [ + { + "from": 9, + "to": 11 + }, + { + "from": 11, + "to": 13 + }, + { + "from": 13, + "to": 15 + }, + { + "from": 15, + "to": 17 + }, + { + "from": 17, + "to": 19 + }, + { + "from": 19, + "to": 22 + } + ], + "weight_temp": 0, + "weight_rain": 80, + "weight_wind": 0, + "weight_humidity": 0, + "weight_air": 0, + "weight_uv": 0, + "weight_sun": 0, + "weight_view": 0, + "weight_time": 20, + "factor_rules": { + "temp": { + "type": "range", + "lo": 0, + "hi": 40 + }, + "rain": { + "dir": "dry" + }, + "wind": { + "type": "ignore" + }, + "humidity": { + "type": "ignore" + }, + "time": { + "type": "fixed", + "value": 100 + } + }, + "zero_rules": [ + { + "field": "rain_before", + "op": "==", + "value": "no" + }, + { + "field": "rain", + "op": "==", + "value": "yes" + } + ], + "limit_description": "비가 언제 그칠지는 예보만큼만 맞아요", + "sentences": { + "0": "우산 두고 올 일 없는 날이에요.", + "30": "비가 오락가락해요. 우산 손에 꼭 쥐어요.", + "60": "비가 그쳤어요. 카페·버스에 우산 두고 오기 딱 좋아요.", + "80": "비 끝, 하늘 맑음! 일어날 때 우산부터 챙겨요 ☂️" + }, + "sort_order": 52, + "priority": 2, + "months": [] + }, + { + "code": "traffic", + "name": "교통체증각", + "icon": "drive", + "category": 4, + "is_fun": false, + "is_core": false, + "has_detail": true, + "description": "출퇴근길 비·눈·추위로 차가 막히는 정도", + "windows": [ + { + "from": 7, + "to": 10 + }, + { + "from": 17, + "to": 20 + } + ], + "weight_temp": 10, + "weight_rain": 70, + "weight_wind": 0, + "weight_humidity": 0, + "weight_air": 0, + "weight_uv": 0, + "weight_sun": 0, + "weight_view": 0, + "weight_time": 20, + "factor_rules": { + "temp": { + "type": "lower", + "zero": 10, + "full": -5 + }, + "rain": { + "dir": "wet" + }, + "wind": { + "type": "ignore" + }, + "humidity": { + "type": "ignore" + }, + "time": { + "type": "weekday", + "mon": 100, + "tue": 100, + "wed": 100, + "thu": 100, + "fri": 100, + "sat": 40, + "sun": 40, + "holiday": 30 + } + }, + "zero_rules": [], + "limit_description": "사고·공사·행사로 막히는 건 반영하지 못해요", + "sentences": { + "0": "길이 수월해요. 평소처럼 나가요.", + "30": "조금 더뎌 수 있어요. 10분 일찍!", + "60": "빗길에 차가 막혀요. 대중교통이 나아요.", + "80": "출퇴근길 주차장 예상! 30분 일찍 나서요 🚗" + }, + "sort_order": 53, + "priority": 2, + "months": [] } ] diff --git a/backend/services/calc/index_calc.py b/backend/services/calc/index_calc.py index 4dcc185..ab01444 100644 --- a/backend/services/calc/index_calc.py +++ b/backend/services/calc/index_calc.py @@ -56,6 +56,7 @@ class Context: lookahead_rain_prob: int moon_note: str = "" # 별보기각 근거 문구: 그날 밤 달 모양·보이는 시간 sunrise_score: Optional[int] = None # 그날 아침 일출 하늘 점수 (해돋이각) + rain_hours: frozenset[int] = frozenset() # 그날 비 오는 시각(0~23). 우산분실각의 '앞서 비가 왔는지' @dataclass(frozen=True) @@ -262,6 +263,8 @@ def _cond(r: dict) -> tuple[str, str, str]: return "눈 소식이 없어", "눈 소식이 없거나", "눈 소식이 없으면" if r["field"] == "rain": return "비 소식이 있어", "비 소식이 있거나", "비 소식이 있으면" + if r["field"] == "rain_before": + return "앞서 내린 비가 없어", "앞서 내린 비가 없거나", "앞서 내린 비가 없으면" base = f"{_FIELD_TEXT[r['field']]} {r['value']}{_UNIT[r['field']]} {'이상' if r['op'] == '>=' else '미만'}" return f"{base}이라", f"{base}이거나", f"{base}이면" @@ -344,6 +347,7 @@ def evaluate(definition, windows: list[list[Hour]], ctx: Context) -> Optional[Re "gust_ms": max(gusts, default=None), "ground_c": max(grounds, default=None), "snow": "yes" if any(h.rain_type in (RainType.SNOW, RainType.SLEET) for h in hours) else "no", "rain": "yes" if raining else "no", "humidity": round(mean(h.humidity for h in hours)), + "rain_before": "yes" if any(h < hours[0].hour for h in ctx.rain_hours) else "no", } reason, cap = _zero(definition.zero_rules, agg) if reason is not None: @@ -393,7 +397,8 @@ def estimate(definition, fc: DayForecast, windows: list[list[int]], ctx: Context notes = {a: n for a, (_, n) in scored.items()} score = _weighted(factors, weights) # 중기예보엔 눈 여부가 없어서, 눈이 와야 하는 각은 0점으로 둔다 - known = {"rain_prob": max_prob, "snow": "no"} + # 하루 예보로는 비가 언제 그치는지 몰라 '앞서 비 옴'은 없는 것으로 본다 + known = {"rain_prob": max_prob, "snow": "no", "rain_before": "no"} reason, cap = _zero([r for r in definition.zero_rules if r["field"] in known], known) if reason is not None: score = min(score, cap) diff --git a/backend/services/index_service.py b/backend/services/index_service.py index d586207..a615e8c 100644 --- a/backend/services/index_service.py +++ b/backend/services/index_service.py @@ -193,6 +193,12 @@ def _shown_parts(parts: dict[str, int], cur: str) -> dict[str, int]: return {k: shown[k] for k in SLOTS if k in shown} +def rain_hours(by_at: dict[datetime, WeatherHourly], day: date) -> frozenset[int]: + """그날 비·눈 오는 시각(0~23).""" + start = kst_midnight(day) + return frozenset(h for h in range(24) if (r := by_at.get(start + timedelta(hours=h))) is not None and r.rain_type != RainType.NONE.value) + + def slot_results( defn, day: date, region: Region, by_at: dict[datetime, WeatherHourly], by_om: dict[datetime, OpenMeteoHourly], ctx: Context, sunset_at: datetime, now: Optional[datetime] = None, @@ -388,7 +394,7 @@ class IndexService: air_label=GRADE_LABEL[AirGrade(air.grade)] if air and air.grade else None, wind_warning=any(w.warning_type is WarningType.WIND for w in warnings or []), ) - today_ctx = Context(day=today, is_holiday=False, moon=0, sunset_score=None, lookahead_rain_prob=0, **base_ctx) + today_ctx = Context(day=today, is_holiday=False, moon=0, sunset_score=None, lookahead_rain_prob=0, rain_hours=rain_hours(by_at, today), **base_ctx) sunset_at = sun_times(today, float(region.lat), float(region.lon)).sunset_at weather_parts = {k: r.score for k, r in slot_results(WEATHER_SCORE_DEF, today, region, by_at, by_om, today_ctx, sunset_at, now).items()} @@ -419,7 +425,7 @@ class IndexService: m = night(day, float(region.lat), float(region.lon)) ctx = Context( day=day, is_holiday=day in (holidays or set()), moon=m.lit * up_ratio(m, _STARS_HOURS), moon_note=f"{m.name}, {view_line(m, None)}", - sunset_score=sunset.get(day), sunrise_score=sunrise.get(day), lookahead_rain_prob=0, **base_ctx, + sunset_score=sunset.get(day), sunrise_score=sunrise.get(day), lookahead_rain_prob=0, rain_hours=rain_hours(by_at, day), **base_ctx, ) for d in defs: result = day_result(d, day, region, by_at, daily, ctx, short=day < today + timedelta(days=DAYS), by_om=by_om) diff --git a/backend/tests/test_index_calc.py b/backend/tests/test_index_calc.py index ff95e2f..3ea3c38 100644 --- a/backend/tests/test_index_calc.py +++ b/backend/tests/test_index_calc.py @@ -308,3 +308,13 @@ def test_humidity_cap(): def test_axis_label_can_be_overridden(): assert axis_label("temp", {"temp": {"type": "higher", "label": "덜 추움"}}) == "덜 추움" + + +def test_umbrella_lost_needs_rain_that_stopped(): + """우산분실각: 앞서 비가 왔다가 그친 시간대만 점수가 난다. 비가 안 온 날, 아직 비가 오는 시간대는 0점.""" + defn = _defn(weight_temp=0, weight_rain=80, weight_wind=0, weight_humidity=0, weight_air=0, weight_time=20, + zero_rules=[{"field": "rain_before", "op": "==", "value": "no"}, {"field": "rain", "op": "==", "value": "yes"}]) + after_rain = replace(CTX, rain_hours=frozenset({9, 10})) + assert evaluate(defn, [[_h(13), _h(14)]], after_rain).score >= 80 + assert evaluate(defn, [[_h(13), _h(14)]], CTX).zero_reason == "앞서 내린 비가 없어 0점" + assert evaluate(defn, [[_h(10, rain=RainType.RAIN)]], replace(CTX, rain_hours=frozenset({9, 10}))).score == 0 diff --git a/frontend/seo/gak.json b/frontend/seo/gak.json index 3693a79..80d9d2d 100644 --- a/frontend/seo/gak.json +++ b/frontend/seo/gak.json @@ -202,5 +202,13 @@ { "name": "싱잉인더레인각", "description": "비 오는 날 우산 쓰고 노래하며 걷기 좋은 정도" + }, + { + "name": "우산분실각", + "description": "오전 9시~밤 10시, 비가 그쳐서 우산을 두고 오기 쉬운 정도" + }, + { + "name": "교통체증각", + "description": "출퇴근길 비·눈·추위로 차가 막히는 정도" } ] diff --git a/frontend/src/b/BLayout.tsx b/frontend/src/b/BLayout.tsx index 0466f0c..4bf814b 100644 --- a/frontend/src/b/BLayout.tsx +++ b/frontend/src/b/BLayout.tsx @@ -48,17 +48,17 @@ function TopBar() { const tab = TABS.find((t) => t.to !== '/' && pathname.startsWith(t.to)) return ( -
+
{tab?.title ?

{tab.title}

:

날씨각

} {mePending ? ( @@ -208,6 +208,10 @@ function Shell() { useEffect(() => { window.scrollTo({ top: 0 }) }, [pathname]) + // 지금 보고 있는 탭을 다시 누르면 맨 위로 + const toTopIfHere = (to: string) => () => { + if (pathname === to) window.scrollTo({ top: 0, behavior: 'smooth' }) + } useEffect(() => { document.querySelector('meta[name="theme-color"]')?.setAttribute('content', NOTCH_BG[kind]) }, [kind]) @@ -228,14 +232,14 @@ function Shell() { {TABS.map((t) => t.key === 'today' ? ( // 메인 탭: 막대 위로 솟은 큰 주황 동그라미 - cx('b-tab-main relative -mt-6 flex flex-col items-center gap-1 text-[12px] font-extrabold', isActive || pathname.startsWith('/today/') ? 'text-(--orange)' : 'text-(--ink3)')}> + cx('b-tab-main relative -mt-6 flex flex-col items-center gap-1 text-[12px] font-extrabold', isActive || pathname.startsWith('/today/') ? 'text-(--orange)' : 'text-(--ink3)')}> {t.label} ) : ( - cx('flex flex-col items-center gap-0.5 text-[11px] font-extrabold', isActive ? 'text-(--ink) [&_svg]:stroke-[2.4]' : 'text-(--ink3) [&_svg]:stroke-[1.9]')}> + cx('flex flex-col items-center gap-0.5 text-[11px] font-extrabold', isActive ? 'text-(--ink) [&_svg]:stroke-[2.4]' : 'text-(--ink3) [&_svg]:stroke-[1.9]')}> {t.label}