Files
o2o-weather/backend/tests/test_outing_score_table.py
T
skkim 0edb7059c8 feat: 주말 나들이 점수를 평균 60 정규분포로 보정, 지금 날씨·나들이 점수 100점은 완벽한 날만
- 나들이 점수(주말 전국 순위·당일치기)에 지금 날씨 점수와 같은 방식의 바꾸기 표를 적용: 원래 점수를 1년 치 분포의 순위로 보고 평균 60·표준편차 15 정규분포 점수로 바꿈 (weekend_rank.py, outing_score_table.json, scripts/gen_outing_score_table.py)
- 나들이 점수 만점 조건을 엄격하게: 체감온도 최적 21°±0.5°, 바람 초속 1m 이하일 때만 100점 (같은 예보를 받는 여러 지역이 한꺼번에 100점이 되던 것을 줄임)
- 표 맨 위가 100으로 잘려 비슷한 원래 점수(96·97·99)가 모두 100점이 되던 것을 막기 위해 straighten_top 추가: 표시 점수 83 이하인 마지막 원래 점수에서 100점까지 직선으로 이어, 100점은 구간에서 나올 수 있는 가장 높은 원래 점수(밤은 85)일 때만 나옴. 지금 날씨 점수 표도 다시 만듦 (90점 이상 약 2.4% → 1.5%)
- 당일치기 최소 점수는 원래 50점과 같은 날씨 수준(표시 62점)으로 옮김
- 주말 순위 캐시 키를 weekend_rank:v2:<날짜>로 올려 옛 점수 캐시를 쓰지 않게 함
- 테스트 추가: test_outing_score_table, test_weather_score_table(straighten_top·100점 조건)
- docs/점수_계산식.md의 지금 날씨 점수·나들이 점수 항목을 새 기준과 숫자로 갱신
2026-10-23 15:02:09 +09:00

59 lines
3.1 KiB
Python

from common.enums import RainType, Sky
from services.calc.index_calc import Hour, Outing, outing
from services.weekend_rank import OUTING_SCORE_TABLE, TRIP_MIN_SCORE, calibrated_outing, outing_day_score
def test_table_is_a_monotonic_0_to_100_lookup():
assert len(OUTING_SCORE_TABLE) == 101
assert all(0 <= v <= 100 for v in OUTING_SCORE_TABLE)
assert all(a <= b for a, b in zip(OUTING_SCORE_TABLE, OUTING_SCORE_TABLE[1:]))
assert OUTING_SCORE_TABLE[0] < OUTING_SCORE_TABLE[100] == 100
def test_table_makes_top_scores_rare_and_centers_60():
"""원래 점수가 높을수록 표시 점수가 오르되, 90점 이상으로 가는 원래 점수는 위쪽 일부뿐."""
assert any(55 <= v <= 65 for v in OUTING_SCORE_TABLE)
assert sum(v >= 90 for v in OUTING_SCORE_TABLE) <= 15
# 맑고 알맞은 날(원래 100)과 조금 못 미치는 날(원래 97)이 모두 100점으로 몰리지 않는다
assert calibrated_outing(95) < 100
def test_calibrated_outing_reads_the_table():
assert calibrated_outing(70) == OUTING_SCORE_TABLE[70]
assert calibrated_outing(0) == OUTING_SCORE_TABLE[0]
def test_day_score_uses_calibrated_value_for_hourly_and_estimated_results():
for estimated in (False, True):
r = Outing(score=80, factors={}, notes={}, reason="비 0% · 체감 21° · 맑음", capped=False, estimated=estimated)
assert outing_day_score(r) == OUTING_SCORE_TABLE[80]
def test_trip_min_score_keeps_the_same_weather_quality():
"""당일치기 최소 기준은 원래 점수 50과 같은 날씨 수준을 표시 점수로 옮긴 값."""
assert TRIP_MIN_SCORE == calibrated_outing(50)
# 표는 가까운 원래 점수끼리 같은 값이 될 수 있어, 눈에 띄게 낮은 날은 빠지고 높은 날은 들어가는지만 본다
assert calibrated_outing(45) < TRIP_MIN_SCORE <= calibrated_outing(55)
def _day(feels: float = 21.0, wind: float = 0.5, prob: int = 0, sky: Sky = Sky.CLEAR) -> list[Hour]:
return [Hour(hour=h, feels_c=feels, rain_type=RainType.NONE, rain_prob=prob, wind_ms=wind, humidity=50, sky=sky) for h in range(10, 18)]
def test_outing_100_needs_exact_temperature_and_very_calm_wind():
"""맑고 비 없는 날도 체감 21° 근처(±0.5°)·바람 초속 1m 이하여야 100점. 그래야 같은 예보의 여러 지역이 한꺼번에 100점이 되지 않는다."""
assert outing(_day()).score == 100
assert outing(_day(feels=21.4)).factors["temp"] == 100
assert outing(_day(feels=22.3)).factors["temp"] < 100
assert outing(_day(wind=1.0)).factors["wind"] == 100
assert outing(_day(wind=1.8)).factors["wind"] < 95
assert outing(_day(wind=1.2)).score > outing(_day(wind=1.8)).score > outing(_day(wind=2.0)).score
def test_100_only_for_a_perfect_original_score_and_top_scores_stay_distinct():
"""맨 위가 100으로 잘려 원래 96·97·99가 모두 100점이 되던 것을 막는다: 100점은 원래 100뿐, 그 아래는 서로 다른 점수."""
assert OUTING_SCORE_TABLE[100] == 100
assert OUTING_SCORE_TABLE[99] < 100
top = OUTING_SCORE_TABLE[90:]
assert all(a < b for a, b in zip(top, top[1:]))