feat: 지금 날씨 점수를 평균 60 정규분포로 (가장 낮은 요소로 깎기 제거, 구간별 바꾸기 표, 90점 이상 약 2.4%)

- 지금 날씨 점수는 '가장 낮은 요소로 깎기'를 하지 않는다 (밤엔 해 난 비율이 늘 0점이라 밤 점수가 62점을 못 넘었음). 각 점수는 그대로
- 원래 점수를 구간(아침·낮·저녁·밤)마다 1년 치 분포의 순위로 보고 평균 60·표준편차 15 정규분포 점수로 바꿔 보여 준다
- 바꾸기 표는 scripts/gen_weather_score_table.py 가 Open-Meteo 과거 예보로 만든다 (weather_score_table.json)
This commit is contained in:
skkim committed 2026-10-22 13:33:50 +09:00
1 parent 61fefd200a
commit 3b5afba8a1
6 files changed
+655 -8

No files matched your search

+8 -4
View File
@@ -296,9 +296,13 @@ def _summary(hours: list[Hour]) -> str:
return f"{hour_label(mid.hour % 24)} {round(mid.feels_c)}°, {tag}"
def _weighted(factors: dict[str, int], weights: dict[str, int]) -> int:
def _weighted(factors: dict[str, int], weights: dict[str, int], worst_pull: bool = True) -> int:
"""비중대로 섞고, worst_pull 이면 가장 낮은 요소로 최대 25% 깎는다 (지금 날씨 점수는 깎지 않는다)."""
mixed = sum(factors[a] * weights[a] for a in AXES) / 100
if not worst_pull:
return round(mixed)
worst = min((factors[a] for a in AXES if weights[a]), default=100)
return round(sum(factors[a] * weights[a] for a in AXES) / 100 * (1 - _WORST_PULL + _WORST_PULL * worst / 100))
return round(mixed * (1 - _WORST_PULL + _WORST_PULL * worst / 100))
def _until(definition) -> str:
@@ -338,7 +342,7 @@ def evaluate(definition, windows: list[list[Hour]], ctx: Context) -> Optional[Re
}
factors = {a: v for a, (v, _) in scored.items()}
notes = {a: n for a, (_, n) in scored.items()}
score = _weighted(factors, weights)
score = _weighted(factors, weights, getattr(definition, "worst_pull", True))
agg = {
"rain_prob": max_prob, "wind_ms": max(winds) if winds else None, "pm25": ctx.pm25,
"feels_c": (min(h.feels_c for h in hours), max(h.feels_c for h in hours)),
@@ -395,7 +399,7 @@ def estimate(definition, fc: DayForecast, windows: list[list[int]], ctx: Context
}
factors = {a: v for a, (v, _) in scored.items()}
notes = {a: n for a, (_, n) in scored.items()}
score = _weighted(factors, weights)
score = _weighted(factors, weights, getattr(definition, "worst_pull", True))
# 중기예보엔 눈 여부가 없어서, 눈이 와야 하는 각은 0점으로 둔다
# 하루 예보로는 비가 언제 그치는지 몰라 '앞서 비 옴'은 없는 것으로 본다
known = {"rain_prob": max_prob, "snow": "no", "rain_before": "no"}
@@ -0,0 +1,428 @@
{
"about": "지금 날씨 점수 바꾸기 표: 원래 점수 0~100 → 표시 점수. 평균 60·표준편차 15. scripts/gen_weather_score_table.py 가 만든다",
"period": [
"2025-10-21",
"2026-10-20"
],
"regions": 32,
"samples": {
"morning": 11680,
"day": 11680,
"evening": 11680,
"night": 11680
},
"slots": {
"morning": [
1,
1,
1,
1,
1,
1,
1,
4,
5,
5,
9,
11,
14,
16,
17,
18,
20,
21,
23,
25,
26,
28,
29,
31,
31,
32,
33,
33,
34,
34,
35,
35,
35,
36,
37,
37,
38,
38,
39,
40,
41,
42,
43,
44,
45,
46,
46,
47,
48,
49,
50,
51,
53,
54,
55,
57,
59,
61,
62,
63,
64,
64,
65,
65,
66,
66,
67,
67,
68,
68,
69,
69,
70,
71,
71,
72,
73,
73,
74,
74,
75,
76,
77,
78,
79,
80,
82,
83,
85,
88,
90,
93,
96,
99,
100,
100,
100,
100,
100,
100,
100
],
"day": [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
4,
6,
9,
12,
15,
19,
22,
24,
26,
27,
28,
29,
30,
31,
31,
32,
32,
33,
33,
34,
35,
36,
37,
37,
38,
39,
40,
41,
41,
42,
42,
43,
43,
44,
44,
45,
45,
46,
46,
47,
47,
47,
48,
48,
48,
49,
49,
50,
50,
51,
52,
54,
56,
59,
61,
62,
63,
63,
64,
64,
64,
65,
65,
66,
66,
66,
67,
67,
68,
68,
69,
70,
71,
72,
73,
74,
76,
77,
79,
81,
83,
85,
87,
91,
97,
100,
100
],
"evening": [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
7,
11,
14,
17,
20,
23,
25,
27,
28,
29,
30,
31,
32,
32,
33,
34,
34,
35,
36,
37,
38,
38,
39,
39,
40,
40,
41,
41,
42,
42,
43,
43,
44,
45,
45,
46,
46,
47,
47,
48,
48,
48,
49,
50,
50,
51,
52,
53,
55,
56,
59,
60,
62,
63,
63,
64,
64,
65,
65,
66,
66,
67,
67,
68,
69,
69,
70,
71,
72,
72,
74,
75,
76,
78,
79,
81,
84,
86,
89,
92,
96,
100,
100,
100,
100
],
"night": [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
4,
7,
10,
11,
13,
15,
17,
20,
22,
26,
28,
30,
32,
33,
34,
34,
35,
35,
35,
36,
36,
37,
38,
38,
39,
40,
41,
41,
42,
43,
44,
45,
47,
48,
49,
50,
52,
53,
55,
57,
59,
62,
63,
65,
65,
66,
66,
66,
67,
68,
68,
69,
69,
70,
70,
71,
71,
72,
73,
74,
74,
75,
77,
78,
80,
82,
85,
88,
92,
96,
100,
100,
100,
100,
100,
100,
100,
100,
100,
100,
100,
100,
100,
100,
100,
100,
100,
100,
100,
100
]
}
}
+18 -1
View File
@@ -1,6 +1,8 @@
import asyncio
import json
from dataclasses import dataclass, field, replace
from datetime import date, datetime, time, timedelta
from pathlib import Path
from types import SimpleNamespace
from typing import Optional
@@ -39,8 +41,13 @@ WEATHER_SCORE_DEF = SimpleNamespace(
"air": {"zero": 75, "full": 10}, "sun": {"zero": 0.2, "full": 0.9}, "time": {"type": "fixed", "value": 100},
},
zero_rules=[], windows=[{"from": NIGHT_END_HOUR, "to": 24 + NIGHT_END_HOUR}],
# 가장 낮은 요소로 깎지 않는다: 밤엔 해 난 비율이 늘 0점이라 깎기가 밤 점수를 눌렀다
worst_pull=False,
)
# 지금 날씨 점수 바꾸기 표: 구간마다 원래 점수 0~100 → 표시 점수(평균 60, 90점 이상은 드물게). scripts/gen_weather_score_table.py 가 만든다
WEATHER_SCORE_TABLE: dict[str, list[int]] = json.loads((Path(__file__).parent / "calc" / "weather_score_table.json").read_text(encoding="utf-8"))["slots"]
SEASONS = ("겨울", "봄", "여름", "가을")
@@ -193,6 +200,16 @@ def _shown_parts(parts: dict[str, int], cur: str) -> dict[str, int]:
return {k: shown[k] for k in SLOTS if k in shown}
def calibrated_weather(slot: str, score: int) -> int:
"""지금 날씨 점수의 원래 점수를 그 구간 표로 바꾼다. 0~5시(전날 밤 구간)는 밤 표."""
return WEATHER_SCORE_TABLE[shown_slot(slot)][score]
def weather_slot_scores(results: dict[str, Result]) -> dict[str, int]:
"""구간별 날씨 점수 결과를 표시 점수로."""
return {k: calibrated_weather(k, r.score) for k, r in results.items()}
def rain_hours(by_at: dict[datetime, WeatherHourly], day: date) -> frozenset[int]:
"""그날 비·눈 오는 시각(0~23)."""
start = kst_midnight(day)
@@ -396,7 +413,7 @@ class IndexService:
)
today_ctx = Context(day=today, is_holiday=False, moon=0, sunset_score=None, lookahead_rain_prob=0, rain_hours=rain_hours(by_at, today), **base_ctx)
sunset_at = sun_times(today, float(region.lat), float(region.lon)).sunset_at
weather_parts = {k: r.score for k, r in slot_results(WEATHER_SCORE_DEF, today, region, by_at, by_om, today_ctx, sunset_at, now).items()}
weather_parts = weather_slot_scores(slot_results(WEATHER_SCORE_DEF, today, region, by_at, by_om, today_ctx, sunset_at, now))
issued = max([r.issued_at for r in rows] + [d.issued_at for d in daily_rows or []])
inputs_at = max(issued, air.measured_at) if air else issued