fix: 지금 비가 오는데 '비 60%'·'5시쯤 비가 와요'로 나오던 문구 — 실황으로 본 대로

- 지금 구간 한 줄(히어로·각): 실황으로 관측한 시각은 예보 확률 대신 본 대로 씀. 비가 오면 '비 오는 중'(눈·진눈깨비도), 비가 없으면 확률 없이 바람·하늘. 비가 관측됐는데 예보 확률이 낮아 '바람 조금'으로 나오던 것도 같이 고쳐짐. 예보 시각(다른 구간·내일)은 그대로 확률
- 2시간 비 안내: 실황이 지금 비를 관측했으면 앞으로의 예보보다 먼저 '지금 비가 와요. 우산 챙기세요'
- 매시 00~10분은 그 시각 실황이 아직 없어 예보 문구가 나옴
This commit is contained in:
skkim committed 2026-11-23 16:22:50 +09:00
1 parent 4fd757e5b4
commit b0e6a01157
6 files changed
+105 -9

No files matched your search

+53
View File
@@ -49,6 +49,59 @@ def test_observed_does_nothing_without_an_observation_or_the_hours_row():
assert with_observed(rows, _OBS) == rows
def _line(**kw):
from services.calc.index_calc import Hour, summary_line
base = dict(hour=16, feels_c=11.0, rain_type=RainType.NONE, rain_prob=60, wind_ms=1.5, humidity=90, sky=Sky.CLOUDY)
return summary_line(Hour(**{**base, **kw}))
def test_observed_hour_line_says_it_is_raining_instead_of_a_probability():
"""실황은 관측이라 확률이 없다. 지금 비가 오면 '비 60%' 가 아니라 오는 중이라고 쓴다."""
assert _line(observed=True, rain_type=RainType.RAIN) == "오후 4시 11°, 비 오는 중"
assert _line(observed=True, rain_type=RainType.SHOWER) == "오후 4시 11°, 비 오는 중"
assert _line(observed=True, rain_type=RainType.SNOW) == "오후 4시 11°, 눈 오는 중"
assert _line(observed=True, rain_type=RainType.SLEET) == "오후 4시 11°, 진눈깨비 오는 중"
def test_observed_hour_line_without_rain_never_shows_a_probability():
"""관측으로 비가 없으면 예보 확률이 60% 여도 확률을 쓰지 않는다."""
assert _line(observed=True) == "오후 4시 11°, 바람 살랑"
assert _line(observed=True, wind_ms=None) == "오후 4시 11°, 흐림"
def test_forecast_hour_line_keeps_the_probability():
assert _line() == "오후 4시 11°, 비 60%"
assert _line(rain_type=RainType.RAIN) == "오후 4시 11°, 비 60%"
def test_only_the_observed_row_is_marked_observed():
from services.index_service import _hour
rows = {r.forecast_at: r for r in (_hourly(13), _hourly(14))}
out = with_observed(rows, _OBS)
assert _hour(out[_at(14)]).observed is True and _hour(out[_at(13)]).observed is False
def test_current_slot_line_of_a_gak_uses_the_observed_rain():
from datetime import date
from services.calc.index_calc import Context
from services.index_service import slot_results
day = date(2026, 10, 8)
defn = SimpleNamespace(
weight_temp=50, weight_rain=50, weight_wind=0, weight_humidity=0, weight_air=0, weight_time=0,
factor_rules={"temp": {"type": "range", "lo": 18, "hi": 24}, "rain": {"dir": "dry"}, "wind": {"type": "ignore"},
"humidity": {"type": "ignore"}, "time": {"type": "fixed", "value": 100}},
zero_rules=[], windows=[{"from": 9, "to": 20}],
)
ctx = Context(day=day, is_holiday=False, pm25=10, air_label="좋음", moon=0, sunset_score=None, wind_warning=False, lookahead_rain_prob=0)
by_at = with_observed({r.forecast_at: r for r in (_hourly(h) for h in range(5, 24))}, _OBS)
parts = slot_results(defn, day, SimpleNamespace(lat=37.5, lon=127.0), by_at, {}, ctx, _at(18), _at(14, 20))
assert parts["day"].summary == "오후 2시 8°, 비 오는 중"
_ITEMS = [{"category": c, "obsrValue": v} for c, v in {"PTY": "1", "REH": "78", "RN1": "0.3", "T1H": "9.8", "WSD": "4.5"}.items()]