Merge remote-tracking branch 'origin/main' into feat/meeting-1008

# Conflicts:
#	backend/services/sky_service.py
This commit is contained in:
minaChoi committed 2026-10-12 15:35:54 +09:00
commit 57cad25f32
7 files changed
+146 -64

No files matched your search

+29 -2
View File
@@ -156,8 +156,8 @@ def test_score_rows_apply_air_at_sunset_and_keep_cloud_score_without_air():
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 hazy == round(plain * 0.8 * 0.85)
rain = {("R", hour - timedelta(hours=3)): SimpleNamespace(humidity=60, rain_prob=80), ("R", hour): SimpleNamespace(humidity=60, rain_prob=10)}
assert sky_service._score_rows(region, today, clouds, now, rain, {})[0]["score"] == min(100, round(plain * 1.15))
@@ -165,3 +165,30 @@ 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]
def test_open_west_bonus_applies_to_sunset_only_and_needs_a_spot_nearby():
from datetime import date, datetime, 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)
st = sun_times(today, region.lat, region.lon)
clouds = {
("R", kind.value, km, sky_service._nearest_hour(at), 3): Layers(0, 20, 0)
for kind, at in ((SkyType.SUNSET, st.sunset_at), (SkyType.SUNRISE, st.sunrise_at)) for km in (20, 100)
}
now = datetime(2026, 10, 7, 3, tzinfo=timezone.utc)
by = lambda rows: {(r["sky_type"], r["score_date"]): r["score"] for r in rows} # noqa: E731
plain = by(sky_service._score_rows(region, today, clouds, now))
west = by(sky_service._score_rows(region, today, clouds, now, open_west=True))
assert west[(SkyType.SUNSET.value, today)] == min(100, round(plain[(SkyType.SUNSET.value, today)] * 1.1))
assert west[(SkyType.SUNRISE.value, today)] == plain[(SkyType.SUNRISE.value, today)]
near = SimpleNamespace(lat=37.5555, lon=126.895) # 망원한강공원, 약 1.5km
far = SimpleNamespace(lat=37.0, lon=126.0)
assert sky_service._open_west(region, [near]) and not sky_service._open_west(region, [far]) and not sky_service._open_west(region, [])
+10 -4
View File
@@ -24,15 +24,21 @@ def test_score_rises_steadily_with_a_few_clouds():
assert scores == sorted(scores) and len(set(scores)) == len(scores) # 맑은 날도 구름 몇 %로 갈리고 10%에서 꺾이지 않는다
def test_air_factor_hazy_humid_lowers_and_clearing_rain_raises():
def test_air_factor_centers_on_usual_air_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(visibility_km=20, humidity=60)) == 1.0 # 평소 공기
assert air_factor(Air(visibility_km=5)) == 0.8 and air_factor(Air(humidity=90)) == 0.85
assert air_factor(Air(visibility_km=40)) == 1.12 and air_factor(Air(humidity=40)) == 1.06 # 맑고 건조하면 올라간다
assert 0.8 < air_factor(Air(visibility_km=12.5)) < 1.0 < air_factor(Air(visibility_km=30)) < 1.12
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_open_west_horizon_adds_bonus():
assert air_factor(Air(open_west=True)) == 1.1
assert air_factor(Air(open_west=True, rain_before=70, rain_now=10)) == 1.15 * 1.1
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