feat: 노을 공기 보정을 평소 공기 기준점 중심으로 바꿔 맑은 날 점수가 한 점에 몰리지 않게

This commit is contained in:
skkim committed 2026-10-08 11:59:08 +09:00
1 parent 91a86a2c10
commit 3857ef8d14
4 files changed
+24 -14

No files matched your search

+3 -3
View File
@@ -48,9 +48,9 @@ light = 1 - min(low100 + 0.5×mid100, 100) / 100
```
- 맑은 하늘(구름 0%)은 55점(은은함)이고, 구름이 몇 %만 있어도 점수가 갈린다. 예전에는 10% 미만을 0.3으로 고정해 맑은 날 전국이 48점에 몰리고, 10%에서 점수가 오히려 떨어졌다.
- 공기 보정 (`air_factor`, 구 중심 해 질·뜰 무렵 값. 값이 없으면 ×1.0):
- 가시거리(`openmeteo_hourly.visibility_m`, 가장 가까운 3시간 구간): 20km 이상 ×1.0 ~ 5km 이하 ×0.8. 뿌연 공기는 색을 흐린다.
- 습도(`weather_hourly.humidity`, 가장 가까운 정시): 70% 이하 ×1.0 ~ 90% 이상 ×0.85. 평소 날씨는 깎지 않고 아주 뿌옇거나 습한 날만 깎는다.
- 공기 보정 (`air_factor`, 구 중심 해 질·뜰 무렵 값. 값이 없으면 ×1.0). 평소 공기(가시거리 20km·습도 60%)를 ×1.0 으로 두고 좋으면 올리고 나쁘면 내린다. 맑은 날 전국이 한 점수(구름 0% = 55점)에 몰리지 않게 하려는 것:
- 가시거리(`openmeteo_hourly.visibility_m`, 가장 가까운 3시간 구간): 5km 이하 ×0.8 · 20km ×1.0 · 40km 이상 ×1.12, 사이는 직선. 뿌연 공기는 색을 흐리고 맑은 공기는 더 선명하다.
- 습도(`weather_hourly.humidity`, 가장 가까운 정시): 40% 이하 ×1.06 · 60% ×1.0 · 90% 이상 ×0.85, 사이는 직선.
- 비 갠 뒤: 2~6시간 전 비 확률 60% 이상이고 그 시각 비 확률 40% 미만이면 ×1.15.
- 모델마다 따로 계산해 **평균**을 최종 점수로 쓰고, 모델 점수의 표준편차로 신뢰도를 정한다 (8 미만 높음, 15 미만 보통, 그 이상 낮음). 모델이 2개 미만이면 낮음. 신뢰도는 공기 보정 전 구름 점수로 본다.
- 등급: 80 이상 붉음, 60 이상 고움, 40 이상 은은함, 그 미만 흐림.
+16 -7
View File
@@ -36,19 +36,28 @@ def score(near20: Layers, far100: Layers) -> int:
return round(100 * (0.75 * f_canvas + 0.25 * f_near) * (0.25 + 0.75 * light))
def _ramp(v: float, bad: float, good: float, low: float) -> float:
"""good 쪽은 1.0, bad 쪽은 low, 사이는 직선."""
t = max(0.0, min(1.0, (v - bad) / (good - bad)))
return low + (1 - low) * t
# 공기 보정 기준점 (값, 배수). 평소 공기(가시거리 20km, 습도 60%)가 ×1.0 이고 좋으면 올리고 나쁘면 내린다. 양 끝 밖은 끝 값 그대로.
_VISIBILITY_FACTOR = ((5, 0.8), (20, 1.0), (40, 1.12))
_HUMIDITY_FACTOR = ((40, 1.06), (60, 1.0), (90, 0.85))
def _interp(v: float, points: tuple[tuple[float, float], ...]) -> float:
"""기준점 사이를 직선으로 잇는다."""
if v <= points[0][0]:
return points[0][1]
for (x0, f0), (x1, f1) in zip(points, points[1:]):
if v <= x1:
return f0 + (f1 - f0) * (v - x0) / (x1 - x0)
return points[-1][1]
def air_factor(air: Air) -> float:
"""공기로 구름 점수를 보정하는 배수. 뿌연 공기·높은 습도는 색을 흐리게 하고, 비 갠 뒤는 더 붉다."""
"""공기로 구름 점수를 보정하는 배수. 맑고 건조하면 올리고 뿌옇거나 습하면 내린다. 비 갠 뒤는 더 붉다."""
f = 1.0
if air.visibility_km is not None:
f *= _ramp(air.visibility_km, 5, 20, 0.8)
f *= _interp(air.visibility_km, _VISIBILITY_FACTOR)
if air.humidity is not None:
f *= _ramp(air.humidity, 90, 70, 0.85)
f *= _interp(air.humidity, _HUMIDITY_FACTOR)
if air.rain_before is not None and air.rain_before >= 60 and (air.rain_now or 0) < 40:
f *= 1.15
return f
+1 -1
View File
@@ -161,7 +161,7 @@ def test_score_rows_apply_air_at_sunset_and_keep_cloud_score_without_air():
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.8 * 0.85)
rain = {("R", hour - timedelta(hours=3)): SimpleNamespace(humidity=50, rain_prob=80), ("R", hour): SimpleNamespace(humidity=50, rain_prob=10)}
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))
+4 -3
View File
@@ -24,11 +24,12 @@ 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=20, humidity=70)) == 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 0.8 < air_factor(Air(visibility_km=12.5)) < 1.0
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 # 아직 비 오는 중이면 가산 없음