Merge branch 'feat/open-meteo'

This commit is contained in:
skkim committed 2026-10-07 16:55:26 +09:00
commit 0ad19e0f42
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]
+17 -1
View File
@@ -2,7 +2,9 @@ from datetime import date, datetime, timedelta, timezone
from common.enums import Confidence, SkyGrade, SkyType
from common.utils.geo import destination, haversine_km
from services.calc.sky_score import GRADE_LABEL, Layers, best_times, confidence, grade, reason, score, situation, sunset_timeline, verdict
from services.calc.sky_score import (
GRADE_LABEL, Air, Layers, air_factor, best_times, confidence, grade, reason, score, situation, sunset_timeline, verdict,
)
from services.calc.sun import sun_times
CLEAR = Layers(0, 0, 0)
@@ -17,6 +19,20 @@ def test_clear_sky_is_only_soft():
assert grade(score(CLEAR, CLEAR)) is SkyGrade.SOFT
def test_score_rises_steadily_with_a_few_clouds():
scores = [score(Layers(0, c, 0), CLEAR) for c in (0, 5, 9, 10, 15, 20, 30, 50)]
assert scores == sorted(scores) and len(set(scores)) == len(scores) # 맑은 날도 구름 몇 %로 갈리고 10%에서 꺾이지 않는다
def test_air_factor_hazy_humid_lowers_and_clearing_rain_raises():
assert air_factor(Air()) == 1.0
assert air_factor(Air(visibility_km=40, humidity=50)) == 1.0
assert air_factor(Air(visibility_km=5)) == 0.6 and air_factor(Air(humidity=90)) == 0.75
assert 0.6 < air_factor(Air(visibility_km=30)) < 1.0
assert air_factor(Air(rain_before=70, rain_now=10)) == 1.15
assert air_factor(Air(rain_before=70, rain_now=60)) == 1.0 # 아직 비 오는 중이면 가산 없음
def test_low_clouds_toward_sun_block_the_light():
canvas = Layers(low=0, mid=20, high=50)
assert grade(score(canvas, Layers(low=90, mid=50, high=0))) is SkyGrade.GRAY