fix: 각 정의 검토 반영 — 지금 비 오면 바깥 각 상한(비 소식 조건), 습도 상한, 시간대가 구간과 2시간 이상 겹쳐야 구간 점수, 뜨아·환기·김서림·화장붕괴·냉면·택시·배달·야구·사진·공부·넷플릭스·군밤·연날리기·이불빨래·실내건조·귤·군고구마·붕어빵·눈사람·빙수·캠핑·단풍·해돋이 비중·조건 조정, 새 각 우산·파전·감성노래
This commit is contained in:
1 parent
c0ba463e54
commit
d020d27715
7 files changed
+505
-76
No files matched your search
@@ -229,7 +229,7 @@ def axis_label(axis: str, rules: dict) -> str:
|
||||
rule = rules.get("air", _AIR_RULE)
|
||||
return "공기 탁함" if rule["full"] > rule["zero"] else "공기 맑음"
|
||||
table = {"temp": _TEMP_LABEL, "wind": _WIND_LABEL, "humidity": _HUMIDITY_LABEL, "time": _TIME_LABEL}[axis]
|
||||
return table[rules[axis]["type"]]
|
||||
return rules[axis].get("label") or table[rules[axis]["type"]]
|
||||
|
||||
|
||||
def _zero(rules: list[dict], agg: dict) -> tuple[Optional[str], Optional[int]]:
|
||||
@@ -249,9 +249,9 @@ def _zero(rules: list[dict], agg: dict) -> tuple[Optional[str], Optional[int]]:
|
||||
|
||||
_FIELD_TEXT = {
|
||||
"rain_prob": "비 확률", "wind_ms": "바람", "feels_c": "체감", "pm25": "초미세먼지", "cloudy_ratio": "흐린 하늘",
|
||||
"gust_ms": "돌풍", "ground_c": "지표면 온도",
|
||||
"gust_ms": "돌풍", "ground_c": "지표면 온도", "humidity": "습도",
|
||||
}
|
||||
_UNIT = {"rain_prob": "%", "wind_ms": "m/s", "feels_c": "°", "pm25": "㎍/㎥", "cloudy_ratio": "%", "gust_ms": "m/s", "ground_c": "°"}
|
||||
_UNIT = {"rain_prob": "%", "wind_ms": "m/s", "feels_c": "°", "pm25": "㎍/㎥", "cloudy_ratio": "%", "gust_ms": "m/s", "ground_c": "°", "humidity": "%"}
|
||||
|
||||
|
||||
def _cond(r: dict) -> tuple[str, str, str]:
|
||||
@@ -260,6 +260,8 @@ def _cond(r: dict) -> tuple[str, str, str]:
|
||||
return "강풍 특보가 있어", "강풍 특보가 있거나", "강풍 특보가 있으면"
|
||||
if r["field"] == "snow":
|
||||
return "눈 소식이 없어", "눈 소식이 없거나", "눈 소식이 없으면"
|
||||
if r["field"] == "rain":
|
||||
return "비 소식이 있어", "비 소식이 있거나", "비 소식이 있으면"
|
||||
base = f"{_FIELD_TEXT[r['field']]} {r['value']}{_UNIT[r['field']]} {'이상' if r['op'] == '>=' else '미만'}"
|
||||
return f"{base}이라", f"{base}이거나", f"{base}이면"
|
||||
|
||||
@@ -341,6 +343,7 @@ def evaluate(definition, windows: list[list[Hour]], ctx: Context) -> Optional[Re
|
||||
"warning": "wind" if ctx.wind_warning else None,
|
||||
"gust_ms": max(gusts, default=None), "ground_c": max(grounds, default=None),
|
||||
"snow": "yes" if any(h.rain_type in (RainType.SNOW, RainType.SLEET) for h in hours) else "no",
|
||||
"rain": "yes" if raining else "no", "humidity": round(mean(h.humidity for h in hours)),
|
||||
}
|
||||
reason, cap = _zero(definition.zero_rules, agg)
|
||||
if reason is not None:
|
||||
|
||||
@@ -189,6 +189,7 @@ def with_ultra_rain(by_at: dict[datetime, WeatherHourly], ultra: Optional[list[R
|
||||
|
||||
|
||||
EARLY = "early" # 0~5시: 전날 밤 구간
|
||||
MIN_SLOT_HOURS = 2 # 각 시간대가 구간과 이만큼은 겹쳐야 그 구간 점수를 낸다 (한 시간짜리 각은 한 시간)
|
||||
|
||||
|
||||
def current_slot(now: datetime, sunset_at: datetime) -> str:
|
||||
@@ -211,9 +212,10 @@ def slot_results(
|
||||
"""그날 아침·낮·저녁·밤과 0~5시(전날 밤) 점수. 각 시간대와 겹치지 않는 구간은 빠진다."""
|
||||
parts = {k: windows_for(defn, day, region, by_at, by_om, only=hours) for k, hours in slot_hours(day, sunset_at).items()}
|
||||
parts[EARLY] = windows_for(defn, day - timedelta(days=1), region, by_at, by_om, only=set(range(24, 24 + NIGHT_END_HOUR)))
|
||||
need = min(MIN_SLOT_HOURS, max((len(h) for h in window_hours(defn, day, region)), default=0))
|
||||
out = {}
|
||||
for key, windows in parts.items():
|
||||
result = evaluate(defn, windows, ctx)
|
||||
result = evaluate(defn, [w for w in windows if len(w) >= need], ctx)
|
||||
if result is not None:
|
||||
out[key] = result
|
||||
return out
|
||||
|
||||
Reference in new issue
Block a user