feat: 지금 날씨를 초단기실황 관측값으로, 각 점수에서 시간대 알맞음 제거·우산각 계산식 변경

- 초단기실황(getUltraSrtNcst)을 받아 지금 정시 한 시각의 비·기온·습도·바람을 예보 대신 관측값으로 덮어씀 (체감·불쾌지수는 다시 계산). 지역별 1시간 캐시, 실패하면 초단기예보·단기예보로 되돌아감, 새 시각 실황이 나오면 각 점수를 다시 계산. 가이드대로 ±900 이상은 결측 처리. 테스트가 실제 기상청을 부르지 않게 실황 호출을 기본으로 막음
- 시간대 알맞음 요소를 31개 각에서 빼고 비중을 5% 단위로 나눔. 요소가 3개 미만이 된 뜨아각·파전각·감성노래각·감사각·선크림각에 요소를 더함. 러닝각의 활동 시간대 밖 점수 상한도 없앰. 요소가 하나뿐인 각은 가장 낮은 요소로 깎지 않음
- 우산각은 비 한 가지: 남은 하루(지금~자정) 비 확률 평균이 점수, 지금 비가 오면 70점에서 시작해 평균 × 30점을 더함. 내일·토·일 칸은 그날 6~24시 평균 × 100. 우산분실각도 비 한 가지
- 각 계산 기준 문서는 생성기를 새 규칙에 맞게 고쳐 다시 생성, 점수 계산식·서비스 동작 안내 문서 갱신
This commit is contained in:
skkim committed 2026-11-23 14:51:04 +09:00
1 parent 8ea9f8f04b
commit 5ab2381f79
19 files changed
+737 -243

No files matched your search

+25 -4
View File
@@ -62,6 +62,7 @@ class Context:
sunrise_score: Optional[int] = None # 그날 아침 일출 하늘 점수 (해돋이각)
rain_hours: frozenset[int] = frozenset() # 그날 비 오는 시각(0~23). 우산분실각의 '앞서 비가 왔는지'
time_matches: bool = True # 평가하는 시간대가 각의 활동 시간대에 해당하는지
at_now: bool = False # 평가하는 첫 시각이 지금인지 (우산각의 '지금 비'). 다른 구간·내일 칸은 지금이 없다
@dataclass(frozen=True)
@@ -138,6 +139,18 @@ def rain_score(rule: dict, max_prob: int, raining: bool, until: str = "") -> tup
return (0 if raining else _linear(max_prob, 100, 0)), (f"비 소식, {prob}" if raining else prob)
def rain_rest_of_day_score(rule: dict, probs: list[int], raining_now: bool) -> tuple[int, str]:
"""남은 시각(시각마다 1시간)의 비 확률 평균. 지금 비가 오면 now_base 에서 시작해 나머지를 평균으로 채운다 (그 시각은 100% 로 침)."""
if raining_now:
probs = [100, *probs[1:]]
avg = sum(probs) / len(probs)
note = f"남은 시간 평균 비 확률 {round(avg)}%"
if raining_now:
base = rule["now_base"]
return _clamp(base + (100 - base) * avg / 100), f"지금 비가 와요, {note}"
return _clamp(avg), note
def wind_score(rule: dict, wind: Optional[float]) -> tuple[int, str]:
if wind is None:
return _UNKNOWN, f"바람 정보가 없어 {_UNKNOWN}점으로 둬요"
@@ -310,7 +323,8 @@ def summary_line(mid: Hour) -> str:
def _weighted(factors: dict[str, int], weights: dict[str, int], worst_pull: bool = True, time_is_binary: bool = False) -> int:
"""비중대로 섞고, worst_pull 이면 가장 낮은 요소로 최대 25% 깎는다 (지금 날씨 점수는 깎지 않는다)."""
mixed = sum(factors[a] * weights[a] for a in AXES) / 100
if not worst_pull:
# 요소가 하나면 그 요소가 곧 가장 낮은 요소라 깎으면 같은 점수를 두 번 깎게 된다
if not worst_pull or sum(1 for a in AXES if weights[a]) <= 1:
return round(mixed)
# 시간대 불일치는 해당 가중치만 잃으며, 최저 요소에 따른 추가 감점에는 넣지 않는다.
worst = min((factors[a] for a in AXES if weights[a] and not (time_is_binary and a == "time")), default=100)
@@ -343,7 +357,10 @@ def evaluate(definition, windows: list[list[Hour]], ctx: Context) -> Optional[Re
grounds = [h.ground_c for h in hours if h.ground_c is not None]
scored = {
"temp": temp_score(rules["temp"], feels),
"rain": rain_score(rules["rain"], max_prob, raining, until if max_prob > own_prob else ""),
"rain": (
rain_rest_of_day_score(rules["rain"], [h.rain_prob for h in hours], ctx.at_now and hours[0].rain_type is not RainType.NONE)
if rules["rain"].get("span") == "rest_of_day" else rain_score(rules["rain"], max_prob, raining, until if max_prob > own_prob else "")
),
"wind": wind_score(rules["wind"], max(winds) if winds else None),
"humidity": humidity_score(rules["humidity"], mean(h.humidity for h in hours)),
"air": air_score(ctx.pm25, ctx.air_label, rules.get("air")),
@@ -395,7 +412,8 @@ def estimate(definition, fc: DayForecast, windows: list[list[int]], ctx: Context
if not hours:
continue
temps = [hour_temp(fc.temp_min_c, fc.temp_max_c, h) for h in hours]
own_prob = max(fc.rain_prob_am if h < 12 else fc.rain_prob_pm if h < 24 else after.rain_prob_am for h in hours)
hour_probs = [fc.rain_prob_am if h < 12 else fc.rain_prob_pm if h < 24 else after.rain_prob_am for h in hours]
own_prob = max(hour_probs)
max_prob = max(own_prob, ctx.lookahead_rain_prob)
humidity = (50, "습도 이 각엔 상관없어 50점으로 둬요") if rules["humidity"]["type"] == "ignore" else (
_UNKNOWN, f"습도 정보가 없어 {_UNKNOWN}점으로 둬요"
@@ -403,7 +421,10 @@ def estimate(definition, fc: DayForecast, windows: list[list[int]], ctx: Context
temp, temp_note = temp_score(rules["temp"], mean(temps))
scored = {
"temp": (temp, f"{temp_note} (최저·최고 기온으로 어림)"),
"rain": rain_score(rules["rain"], max_prob, False, until if max_prob > own_prob else ""),
"rain": (
rain_rest_of_day_score(rules["rain"], hour_probs, False)
if rules["rain"].get("span") == "rest_of_day" else rain_score(rules["rain"], max_prob, False, until if max_prob > own_prob else "")
),
"wind": wind_score(rules["wind"], None),
"humidity": humidity,
"air": air_score(None, None),