feat: 노을 점수 맑은 하늘 구간을 매끄럽게 하고 가시거리·습도·비 갠 뒤로 공기 보정

This commit is contained in:
skkim committed 2026-10-07 16:53:04 +09:00
1 parent 3c8e8984af
commit 0c168d1ffe
6 files changed
+144 -13

No files matched your search

+28
View File
@@ -141,3 +141,31 @@ async def test_clouds_are_stored_by_region_with_only_needed_hours(monkeypatch, c
assert {(r.kind, r.distance_km) for r in rows} == {(1, 20), (1, 100), (2, 20), (2, 100)}
assert {r.model for r in rows} == {3, 4}
assert len({r.forecast_at for r in rows}) == 6
def test_score_rows_apply_air_at_sunset_and_keep_cloud_score_without_air():
from datetime import date, datetime, timedelta, timezone
from types import SimpleNamespace
from common.enums import SkyType
from services.calc.sky_score import Layers
from services.calc.sun import sun_times
region = SimpleNamespace(code="R", lat=37.56, lon=126.91)
today = date(2026, 10, 7)
hour = sky_service._nearest_hour(sun_times(today, region.lat, region.lon).sunset_at)
clouds = {("R", SkyType.SUNSET.value, km, hour, 3): Layers(0, 20, 0) for km in (20, 100)}
now = datetime(2026, 10, 7, 3, tzinfo=timezone.utc)
plain = sky_service._score_rows(region, today, clouds, now)[0]["score"]
hourly = {("R", hour): SimpleNamespace(humidity=90, rain_prob=0)}
om = {("R", sky_service._nearest_slot(hour)): SimpleNamespace(visibility_m=5000)}
hazy = sky_service._score_rows(region, today, clouds, now, hourly, om)[0]["score"]
assert hazy == round(plain * 0.6 * 0.75)
rain = {("R", hour - timedelta(hours=3)): SimpleNamespace(humidity=50, rain_prob=80), ("R", hour): SimpleNamespace(humidity=50, rain_prob=10)}
assert sky_service._score_rows(region, today, clouds, now, rain, {})[0]["score"] == min(100, round(plain * 1.15))
def test_nearest_slot_is_closest_three_hour_end():
from datetime import datetime, timezone
at = lambda h, m=0: datetime(2026, 10, 7, h, m, tzinfo=timezone.utc) # noqa: E731
assert [sky_service._nearest_slot(at(h, m)).hour for h, m in ((8, 0), (9, 0), (10, 29), (10, 31))] == [9, 9, 9, 12]