feat: 우산분실각(비 그친 뒤 우산 두고 오기 쉬운 정도)·교통체증각(출퇴근길 비·눈·추위) 추가, '앞서 비 옴' 조건(rain_before)

This commit is contained in:
minaChoi committed 2026-10-14 09:08:50 +09:00
1 parent b586db0de7
commit 0aeceac257
5 files changed
+186 -3

No files matched your search

+6 -1
View File
@@ -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)