- 각 점수: 편한 범위 안에서도 최적값에서만 100, 가장 나쁜 요인이 전체를 끌어내림 - 피드 노을 시간대 각 정렬 오류 수정 - 주말 카드 매일 노출, 예보가 닿으면 다음 주말 슬라이드 추가, 주말·행사 탭 열흘 - 지역 256→230 (일반구 39개를 시 13개로) - 회의 기록과 TODO.md 추가
76 lines
3.3 KiB
Python
76 lines
3.3 KiB
Python
from datetime import date, datetime, timezone
|
|
from types import SimpleNamespace
|
|
|
|
from common.enums import RainType, Sky
|
|
from services.calc.index_calc import Context, Hour, evaluate, rain_score, temp_score, zero_rules_text
|
|
from services.calc.moon import illumination
|
|
|
|
CTX = Context(day=date(2026, 10, 2), is_holiday=False, pm25=10, air_label="좋음", moon=0.5, sunset_score=80, wind_warning=False, lookahead_rain_prob=0)
|
|
|
|
|
|
def _defn(**kw):
|
|
base = dict(
|
|
weight_temp=30, weight_rain=25, weight_wind=15, weight_humidity=10, weight_air=10, weight_time=10,
|
|
factor_rules={
|
|
"temp": {"type": "range", "lo": 18, "hi": 24}, "rain": {"dir": "dry"}, "wind": {"type": "calm", "ok": 2, "limit": 10},
|
|
"humidity": {"type": "range", "lo": 40, "hi": 60}, "time": {"type": "weekday", "fri": 100, "default": 78},
|
|
},
|
|
zero_rules=[{"field": "rain_prob", "op": ">=", "value": 80}],
|
|
)
|
|
return SimpleNamespace(**{**base, **kw})
|
|
|
|
|
|
def _h(hour, feels=21.0, prob=0, rain=RainType.NONE, wind=1.5, hum=50, sky=Sky.CLEAR):
|
|
return Hour(hour=hour, feels_c=feels, rain_type=rain, rain_prob=prob, wind_ms=wind, humidity=hum, sky=sky)
|
|
|
|
|
|
def test_perfect_evening_scores_100():
|
|
r = evaluate(_defn(), [[_h(19, wind=1.0), _h(20, wind=1.0)]], CTX)
|
|
assert r.score == 100 and r.zero_reason is None
|
|
assert r.notes["temp"] == "체감 21°, 편한 범위 18~24° 안"
|
|
|
|
|
|
def test_good_but_not_perfect_stays_below_100():
|
|
assert evaluate(_defn(), [[_h(19, feels=23, hum=58, wind=1.8)]], CTX).score < 95
|
|
|
|
|
|
def test_one_bad_factor_pulls_total_down():
|
|
assert evaluate(_defn(), [[_h(19, wind=1.0, prob=60)]], CTX).score < 80
|
|
|
|
|
|
def test_temp_peaks_at_best_and_loses_8_per_degree_outside():
|
|
assert temp_score({"type": "range", "lo": 18, "hi": 24}, 21)[0] == 100
|
|
assert temp_score({"type": "range", "lo": 18, "hi": 24}, 24)[0] == 85
|
|
assert temp_score({"type": "range", "lo": 18, "hi": 24, "best": 22}, 22)[0] == 100
|
|
assert temp_score({"type": "range", "lo": 18, "hi": 24}, 15)[0] == 61
|
|
assert temp_score({"type": "lower", "zero": 25, "full": 5}, 15)[0] == 50
|
|
assert temp_score({"type": "range", "lo": 10, "hi": 20, "offset": -6}, 21)[1].startswith("정상 15°")
|
|
|
|
|
|
def test_rain_dry_and_wet():
|
|
assert rain_score({"dir": "dry"}, 30, False)[0] == 70
|
|
assert rain_score({"dir": "dry"}, 30, True)[0] == 0
|
|
assert rain_score({"dir": "wet"}, 30, True)[0] == 100
|
|
|
|
|
|
def test_zero_rule_forces_zero_and_cap_limits():
|
|
assert evaluate(_defn(), [[_h(19, prob=80)]], CTX).score == 0
|
|
capped = _defn(zero_rules=[{"field": "rain_prob", "op": ">=", "value": 70, "cap": 20}])
|
|
assert evaluate(capped, [[_h(19, prob=70)]], CTX).score <= 20
|
|
|
|
|
|
def test_best_window_is_chosen():
|
|
r = evaluate(_defn(), [[_h(7, feels=5)], [_h(20, feels=21)]], CTX)
|
|
assert r.window == (20, 20)
|
|
|
|
|
|
def test_zero_rules_text():
|
|
assert zero_rules_text([{"field": "rain_prob", "op": ">=", "value": 80}, {"field": "wind_ms", "op": ">=", "value": 14}]) == \
|
|
"비 확률 80% 이상 또는 바람 14m/s 이상이면 바로 0점"
|
|
assert zero_rules_text([]) == "없음 (재미로 보는 지수)"
|
|
|
|
|
|
def test_moon_full_and_new():
|
|
assert illumination(datetime(2000, 1, 6, 18, 14, tzinfo=timezone.utc)) < 0.01
|
|
assert illumination(datetime(2000, 1, 21, 12, tzinfo=timezone.utc)) > 0.95
|