Merge remote-tracking branch 'origin/main' into feat/region-seo-pages

# Conflicts:
#	frontend/src/b/BLayout.tsx
This commit is contained in:
minaChoi committed 2026-10-14 09:16:08 +09:00
commit 2ca060b626
6 files changed
+196 -9

No files matched your search

+154
View File
@@ -3730,5 +3730,159 @@
"sort_order": 51,
"priority": 3,
"months": []
},
{
"code": "umbrella_lost",
"name": "우산분실각",
"icon": "umbrella",
"category": 4,
"is_fun": false,
"is_core": false,
"has_detail": true,
"description": "오전 9시~밤 10시, 비가 그쳐서 우산을 두고 오기 쉬운 정도",
"windows": [
{
"from": 9,
"to": 11
},
{
"from": 11,
"to": 13
},
{
"from": 13,
"to": 15
},
{
"from": 15,
"to": 17
},
{
"from": 17,
"to": 19
},
{
"from": 19,
"to": 22
}
],
"weight_temp": 0,
"weight_rain": 80,
"weight_wind": 0,
"weight_humidity": 0,
"weight_air": 0,
"weight_uv": 0,
"weight_sun": 0,
"weight_view": 0,
"weight_time": 20,
"factor_rules": {
"temp": {
"type": "range",
"lo": 0,
"hi": 40
},
"rain": {
"dir": "dry"
},
"wind": {
"type": "ignore"
},
"humidity": {
"type": "ignore"
},
"time": {
"type": "fixed",
"value": 100
}
},
"zero_rules": [
{
"field": "rain_before",
"op": "==",
"value": "no"
},
{
"field": "rain",
"op": "==",
"value": "yes"
}
],
"limit_description": "비가 언제 그칠지는 예보만큼만 맞아요",
"sentences": {
"0": "우산 두고 올 일 없는 날이에요.",
"30": "비가 오락가락해요. 우산 손에 꼭 쥐어요.",
"60": "비가 그쳤어요. 카페·버스에 우산 두고 오기 딱 좋아요.",
"80": "비 끝, 하늘 맑음! 일어날 때 우산부터 챙겨요 ☂️"
},
"sort_order": 52,
"priority": 2,
"months": []
},
{
"code": "traffic",
"name": "교통체증각",
"icon": "drive",
"category": 4,
"is_fun": false,
"is_core": false,
"has_detail": true,
"description": "출퇴근길 비·눈·추위로 차가 막히는 정도",
"windows": [
{
"from": 7,
"to": 10
},
{
"from": 17,
"to": 20
}
],
"weight_temp": 10,
"weight_rain": 70,
"weight_wind": 0,
"weight_humidity": 0,
"weight_air": 0,
"weight_uv": 0,
"weight_sun": 0,
"weight_view": 0,
"weight_time": 20,
"factor_rules": {
"temp": {
"type": "lower",
"zero": 10,
"full": -5
},
"rain": {
"dir": "wet"
},
"wind": {
"type": "ignore"
},
"humidity": {
"type": "ignore"
},
"time": {
"type": "weekday",
"mon": 100,
"tue": 100,
"wed": 100,
"thu": 100,
"fri": 100,
"sat": 40,
"sun": 40,
"holiday": 30
}
},
"zero_rules": [],
"limit_description": "사고·공사·행사로 막히는 건 반영하지 못해요",
"sentences": {
"0": "길이 수월해요. 평소처럼 나가요.",
"30": "조금 더뎌 수 있어요. 10분 일찍!",
"60": "빗길에 차가 막혀요. 대중교통이 나아요.",
"80": "출퇴근길 주차장 예상! 30분 일찍 나서요 🚗"
},
"sort_order": 53,
"priority": 2,
"months": []
}
]
+6 -1
View File
@@ -56,6 +56,7 @@ class Context:
lookahead_rain_prob: int
moon_note: str = "" # 별보기각 근거 문구: 그날 밤 달 모양·보이는 시간
sunrise_score: Optional[int] = None # 그날 아침 일출 하늘 점수 (해돋이각)
rain_hours: frozenset[int] = frozenset() # 그날 비 오는 시각(0~23). 우산분실각의 '앞서 비가 왔는지'
@dataclass(frozen=True)
@@ -262,6 +263,8 @@ def _cond(r: dict) -> tuple[str, str, str]:
return "눈 소식이 없어", "눈 소식이 없거나", "눈 소식이 없으면"
if r["field"] == "rain":
return "비 소식이 있어", "비 소식이 있거나", "비 소식이 있으면"
if r["field"] == "rain_before":
return "앞서 내린 비가 없어", "앞서 내린 비가 없거나", "앞서 내린 비가 없으면"
base = f"{_FIELD_TEXT[r['field']]} {r['value']}{_UNIT[r['field']]} {'이상' if r['op'] == '>=' else '미만'}"
return f"{base}이라", f"{base}이거나", f"{base}이면"
@@ -344,6 +347,7 @@ def evaluate(definition, windows: list[list[Hour]], ctx: Context) -> Optional[Re
"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)),
"rain_before": "yes" if any(h < hours[0].hour for h in ctx.rain_hours) else "no",
}
reason, cap = _zero(definition.zero_rules, agg)
if reason is not None:
@@ -393,7 +397,8 @@ def estimate(definition, fc: DayForecast, windows: list[list[int]], ctx: Context
notes = {a: n for a, (_, n) in scored.items()}
score = _weighted(factors, weights)
# 중기예보엔 눈 여부가 없어서, 눈이 와야 하는 각은 0점으로 둔다
known = {"rain_prob": max_prob, "snow": "no"}
# 하루 예보로는 비가 언제 그치는지 몰라 '앞서 비 옴'은 없는 것으로 본다
known = {"rain_prob": max_prob, "snow": "no", "rain_before": "no"}
reason, cap = _zero([r for r in definition.zero_rules if r["field"] in known], known)
if reason is not None:
score = min(score, cap)
+8 -2
View File
@@ -193,6 +193,12 @@ 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 rain_hours(by_at: dict[datetime, WeatherHourly], day: date) -> frozenset[int]:
"""그날 비·눈 오는 시각(0~23)."""
start = kst_midnight(day)
return frozenset(h for h in range(24) if (r := by_at.get(start + timedelta(hours=h))) is not None and r.rain_type != RainType.NONE.value)
def slot_results(
defn, day: date, region: Region, by_at: dict[datetime, WeatherHourly], by_om: dict[datetime, OpenMeteoHourly], ctx: Context, sunset_at: datetime,
now: Optional[datetime] = None,
@@ -388,7 +394,7 @@ class IndexService:
air_label=GRADE_LABEL[AirGrade(air.grade)] if air and air.grade else None,
wind_warning=any(w.warning_type is WarningType.WIND for w in warnings or []),
)
today_ctx = Context(day=today, is_holiday=False, moon=0, sunset_score=None, lookahead_rain_prob=0, **base_ctx)
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()}
@@ -419,7 +425,7 @@ class IndexService:
m = night(day, float(region.lat), float(region.lon))
ctx = Context(
day=day, is_holiday=day in (holidays or set()), moon=m.lit * up_ratio(m, _STARS_HOURS), moon_note=f"{m.name}, {view_line(m, None)}",
sunset_score=sunset.get(day), sunrise_score=sunrise.get(day), lookahead_rain_prob=0, **base_ctx,
sunset_score=sunset.get(day), sunrise_score=sunrise.get(day), lookahead_rain_prob=0, rain_hours=rain_hours(by_at, day), **base_ctx,
)
for d in defs:
result = day_result(d, day, region, by_at, daily, ctx, short=day < today + timedelta(days=DAYS), by_om=by_om)
+10
View File
@@ -308,3 +308,13 @@ def test_humidity_cap():
def test_axis_label_can_be_overridden():
assert axis_label("temp", {"temp": {"type": "higher", "label": "덜 추움"}}) == "덜 추움"
def test_umbrella_lost_needs_rain_that_stopped():
"""우산분실각: 앞서 비가 왔다가 그친 시간대만 점수가 난다. 비가 안 온 날, 아직 비가 오는 시간대는 0점."""
defn = _defn(weight_temp=0, weight_rain=80, weight_wind=0, weight_humidity=0, weight_air=0, weight_time=20,
zero_rules=[{"field": "rain_before", "op": "==", "value": "no"}, {"field": "rain", "op": "==", "value": "yes"}])
after_rain = replace(CTX, rain_hours=frozenset({9, 10}))
assert evaluate(defn, [[_h(13), _h(14)]], after_rain).score >= 80
assert evaluate(defn, [[_h(13), _h(14)]], CTX).zero_reason == "앞서 내린 비가 없어 0점"
assert evaluate(defn, [[_h(10, rain=RainType.RAIN)]], replace(CTX, rain_hours=frozenset({9, 10}))).score == 0