fix: 매시 정각~14분에 지금 날씨가 예보로 돌아가던 것 — 새 실황은 15분부터 쓰고, 그 전엔 시각은 그대로 두고 앞 시각 관측을 이어서
This commit is contained in:
1 parent
3baa543313
commit
fb483c6b50
11 files changed
+62
-40
No files matched your search
@@ -30,14 +30,14 @@ _OBS = Observed(at=_at(14), rain_type=RainType.RAIN, rain_mm=0.3, temp_c=9.8, hu
|
||||
|
||||
def test_observed_replaces_the_observed_hour_with_what_is_measured():
|
||||
rows = {r.forecast_at: r for r in (_hourly(13), _hourly(14), _hourly(15))}
|
||||
r = with_observed(rows, _OBS)[_at(14)]
|
||||
r = with_observed(rows, _OBS, _at(14, 20))[_at(14)]
|
||||
assert (r.rain_type, float(r.rain_mm), float(r.temp_c), r.humidity, float(r.wind_ms)) == (RainType.RAIN.value, 0.3, 9.8, 78, 4.5)
|
||||
assert float(r.feels_c) == feels_like_c(9.8, 78, 4.5, 10) and r.discomfort_index == discomfort_index(9.8, 78)
|
||||
|
||||
|
||||
def test_observed_keeps_forecast_only_values_and_other_hours():
|
||||
rows = {r.forecast_at: r for r in (_hourly(13), _hourly(14), _hourly(15))}
|
||||
out = with_observed(rows, _OBS)
|
||||
out = with_observed(rows, _OBS, _at(14, 20))
|
||||
assert (out[_at(14)].rain_prob, out[_at(14)].sky) == (30, Sky.CLOUDY.value)
|
||||
assert out[_at(13)] is rows[_at(13)] and out[_at(15)] is rows[_at(15)]
|
||||
assert rows[_at(14)].rain_type == RainType.NONE.value # 원본은 그대로
|
||||
@@ -45,8 +45,24 @@ def test_observed_keeps_forecast_only_values_and_other_hours():
|
||||
|
||||
def test_observed_does_nothing_without_an_observation_or_the_hours_row():
|
||||
rows = {_at(13): _hourly(13)}
|
||||
assert with_observed(rows, None) == rows
|
||||
assert with_observed(rows, _OBS) == rows
|
||||
assert with_observed(rows, None, _at(14, 20)) == rows
|
||||
assert with_observed(rows, _OBS, _at(14, 20)) == rows
|
||||
|
||||
|
||||
def test_until_the_new_observation_is_out_the_current_hour_shows_the_last_one():
|
||||
"""15:05 엔 15시 실황이 아직 없다(15:15 부터 쓴다). 그동안 15시 줄은 14시에 관측한 날씨를 이어서 보이고, 지난 14시 줄은 예보 그대로 둔다."""
|
||||
rows = {r.forecast_at: r for r in (_hourly(13), _hourly(14), _hourly(15), _hourly(16))}
|
||||
out = with_observed(rows, _OBS, _at(15, 5))
|
||||
r = out[_at(15)]
|
||||
assert (r.forecast_at, r.rain_type, float(r.rain_mm), float(r.temp_c), r.humidity, float(r.wind_ms)) == (_at(15), RainType.RAIN.value, 0.3, 9.8, 78, 4.5)
|
||||
assert float(r.feels_c) == feels_like_c(9.8, 78, 4.5, 10) and r.discomfort_index == discomfort_index(9.8, 78)
|
||||
assert all(out[_at(h)] is rows[_at(h)] for h in (13, 14, 16))
|
||||
|
||||
|
||||
def test_an_observation_older_than_the_hour_before_is_not_carried_over():
|
||||
"""이어서 쓰는 건 바로 앞 시각 관측까지다. 14시 관측을 16시 줄에 쓰지 않는다."""
|
||||
rows = {r.forecast_at: r for r in (_hourly(14), _hourly(15), _hourly(16))}
|
||||
assert with_observed(rows, _OBS, _at(16, 5)) == rows
|
||||
|
||||
|
||||
def _line(**kw):
|
||||
@@ -79,7 +95,7 @@ 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)
|
||||
out = with_observed(rows, _OBS, _at(14, 20))
|
||||
assert _hour(out[_at(14)]).observed is True and _hour(out[_at(13)]).observed is False
|
||||
|
||||
|
||||
@@ -97,9 +113,13 @@ def test_current_slot_line_of_a_gak_uses_the_observed_rain():
|
||||
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))
|
||||
region = SimpleNamespace(lat=37.5, lon=127.0)
|
||||
rows = {r.forecast_at: r for r in (_hourly(h) for h in range(5, 24))}
|
||||
parts = slot_results(defn, day, region, with_observed(rows, _OBS, _at(14, 20)), {}, ctx, _at(18), _at(14, 20))
|
||||
assert parts["day"].summary == "오후 2시 8°, 비 오는 중"
|
||||
# 15:05 엔 시각은 지금(오후 3시) 그대로, 날씨만 14시에 관측한 것
|
||||
parts = slot_results(defn, day, region, with_observed(rows, _OBS, _at(15, 5)), {}, ctx, _at(18), _at(15, 5))
|
||||
assert parts["day"].summary == "오후 3시 8°, 비 오는 중"
|
||||
|
||||
|
||||
_ITEMS = [{"category": c, "obsrValue": v} for c, v in {"PTY": "1", "REH": "78", "RN1": "0.3", "T1H": "9.8", "WSD": "4.5"}.items()]
|
||||
@@ -128,9 +148,9 @@ async def test_observed_now_reads_the_latest_hour_and_keeps_it_for_that_hour(ncs
|
||||
@pytest.mark.anyio
|
||||
async def test_observed_now_asks_again_when_a_new_hour_is_out(ncst_calls):
|
||||
await observed_now(REGION, _at(14, 20))
|
||||
await observed_now(REGION, _at(15, 5)) # 15시 실황은 15:10부터라 아직 14시 것
|
||||
await observed_now(REGION, _at(15, 14)) # 15시 실황은 15:15부터 쓰니 아직 14시 것
|
||||
assert ncst_calls == [_at(14)]
|
||||
await observed_now(REGION, _at(15, 10))
|
||||
await observed_now(REGION, _at(15, 15))
|
||||
assert ncst_calls == [_at(14), _at(15)]
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user