- 지금 날씨 점수는 '가장 낮은 요소로 깎기'를 하지 않는다 (밤엔 해 난 비율이 늘 0점이라 밤 점수가 62점을 못 넘었음). 각 점수는 그대로 - 원래 점수를 구간(아침·낮·저녁·밤)마다 1년 치 분포의 순위로 보고 평균 60·표준편차 15 정규분포 점수로 바꿔 보여 준다 - 바꾸기 표는 scripts/gen_weather_score_table.py 가 Open-Meteo 과거 예보로 만든다 (weather_score_table.json)
54 lines
2.5 KiB
Python
54 lines
2.5 KiB
Python
from datetime import date
|
|
from types import SimpleNamespace
|
|
|
|
from services.calc.index_calc import Context, evaluate
|
|
from services.index_service import EARLY, WEATHER_SCORE_DEF, WEATHER_SCORE_TABLE, calibrated_weather, weather_slot_scores
|
|
from tests.test_index_calc import _defn, _h
|
|
|
|
PERFECT = Context(day=date(2026, 10, 2), is_holiday=False, pm25=8, air_label="좋음", moon=0, sunset_score=None, wind_warning=False, lookahead_rain_prob=0)
|
|
SLOTS = ("morning", "day", "evening", "night")
|
|
|
|
|
|
def test_weather_score_has_no_worst_factor_pull():
|
|
"""해 난 비율만 0점(밤)이어도 나머지가 만점이면 비중대로 85점. 가장 낮은 요소로 25% 더 깎지 않는다."""
|
|
hours = [_h(h, feels=21.0, prob=0, wind=0.8, hum=50, sunshine_ratio=0.0) for h in range(19, 23)]
|
|
r = evaluate(WEATHER_SCORE_DEF, [hours], PERFECT)
|
|
assert r.factors["sun"] == 0
|
|
assert r.score == 85
|
|
|
|
|
|
def test_gak_scores_keep_worst_factor_pull():
|
|
"""각 점수는 그대로: 한 요소가 0점이면 섞은 점수에서 25% 깎인다."""
|
|
defn = _defn(zero_rules=[])
|
|
r = evaluate(defn, [[_h(19, wind=12.0)]], PERFECT)
|
|
assert r.factors["wind"] == 0
|
|
plain = round(sum(r.factors[a] * getattr(defn, f"weight_{a}", 0) for a in r.factors) / 100)
|
|
assert r.score == round(plain * 0.75)
|
|
|
|
|
|
def test_table_covers_every_slot_and_never_goes_down():
|
|
for slot in SLOTS:
|
|
table = WEATHER_SCORE_TABLE[slot]
|
|
assert len(table) == 101
|
|
assert all(0 <= v <= 100 for v in table)
|
|
assert all(a <= b for a, b in zip(table, table[1:]))
|
|
assert table[100] == 100
|
|
|
|
|
|
def test_table_makes_90_rare_and_centers_60():
|
|
"""구간마다 원래 점수 중앙값 근처가 60점 근처로, 90점 이상은 원래 점수 상위 몇 칸뿐."""
|
|
for slot in SLOTS:
|
|
table = WEATHER_SCORE_TABLE[slot]
|
|
assert any(55 <= v <= 65 for v in table)
|
|
assert sum(v >= 90 for v in table) < sum(v < 90 for v in table)
|
|
|
|
|
|
def test_calibrated_uses_slot_table_and_last_night_for_early():
|
|
assert calibrated_weather("day", 70) == WEATHER_SCORE_TABLE["day"][70]
|
|
assert calibrated_weather(EARLY, 70) == WEATHER_SCORE_TABLE["night"][70]
|
|
|
|
|
|
def test_weather_slot_scores_shows_calibrated_values():
|
|
results = {k: SimpleNamespace(score=s) for k, s in {"morning": 40, "night": 60, EARLY: 60}.items()}
|
|
assert weather_slot_scores(results) == {"morning": WEATHER_SCORE_TABLE["morning"][40], "night": WEATHER_SCORE_TABLE["night"][60], EARLY: WEATHER_SCORE_TABLE["night"][60]}
|