feat: 10/6 회의 반영 — 각 점수 하향, 주말 카드 매일·다음 주말, 일반구를 시로 합침

- 각 점수: 편한 범위 안에서도 최적값에서만 100, 가장 나쁜 요인이 전체를 끌어내림
- 피드 노을 시간대 각 정렬 오류 수정
- 주말 카드 매일 노출, 예보가 닿으면 다음 주말 슬라이드 추가, 주말·행사 탭 열흘
- 지역 256→230 (일반구 39개를 시 13개로)
- 회의 기록과 TODO.md 추가
This commit is contained in:
minaChoi committed 2026-10-06 09:57:25 +09:00
1 parent a9ddbaab3c
commit 14ddebd040
12 files changed
+156 -76

No files matched your search

+21 -6
View File
@@ -10,6 +10,8 @@ AXES = ("temp", "rain", "wind", "humidity", "air", "time")
_WEEKDAY = ("mon", "tue", "wed", "thu", "fri", "sat", "sun")
_WEEKDAY_KO = ("월", "화", "수", "목", "금", "토", "일")
_UNKNOWN = 70
_EDGE = 85
_WORST_PULL = 0.25
@dataclass(frozen=True)
@@ -53,13 +55,21 @@ def _linear(v: float, zero: float, full: float) -> int:
return _clamp((v - zero) / (full - zero) * 100)
def _peak(v: float, lo: float, hi: float, best: Optional[float], per_out: float) -> int:
"""최적값에서만 100. 편한 범위 끝은 _EDGE, 범위 밖은 한 단위마다 per_out 씩 깎는다."""
best = (lo + hi) / 2 if best is None else best
if v < lo or v > hi:
return _clamp(_EDGE - per_out * min(abs(v - lo), abs(v - hi)))
side = (best - lo) if v < best else (hi - best)
return _clamp(100 - (100 - _EDGE) * (abs(v - best) / side if side else 0))
def temp_score(rule: dict, feels: float) -> tuple[int, str]:
t = feels + rule.get("offset", 0)
shown = f"정상 {round(t)}°" if rule.get("offset") else f"체감 {round(t)}°"
if rule["type"] == "range":
lo, hi = rule["lo"], rule["hi"]
dist = 0 if lo <= t <= hi else min(abs(t - lo), abs(t - hi))
return _clamp(100 - 8 * dist), f"{shown}, 편한 범위 {lo}~{hi}° {'안' if dist == 0 else '밖'}"
return _peak(t, lo, hi, rule.get("best"), 8), f"{shown}, 편한 범위 {lo}~{hi}° {'안' if lo <= t <= hi else '밖'}"
return _linear(t, rule["zero"], rule["full"]), shown
@@ -74,7 +84,12 @@ def wind_score(rule: dict, wind: Optional[float]) -> tuple[int, str]:
return (_UNKNOWN if wind is None else 50), ("바람 정보 없음" if wind is None else f"바람 초속 {wind:g}m")
note = f"바람 초속 {wind:g}m"
if rule["type"] == "calm":
return (100 if wind <= rule["ok"] else _linear(wind, rule["limit"], rule["ok"])), note
ok = rule["ok"]
if wind <= ok / 2:
return 100, note
if wind <= ok:
return _clamp(100 - (100 - _EDGE) * (wind - ok / 2) / (ok / 2)), note
return _clamp(_EDGE * (rule["limit"] - wind) / (rule["limit"] - ok)), note
if rule["type"] == "moderate":
if 2 <= wind <= 5:
return 100, note
@@ -85,8 +100,7 @@ def wind_score(rule: dict, wind: Optional[float]) -> tuple[int, str]:
def humidity_score(rule: dict, humidity: float) -> tuple[int, str]:
note = f"습도 {round(humidity)}%"
if rule["type"] == "range":
dist = 0 if rule["lo"] <= humidity <= rule["hi"] else min(abs(humidity - rule["lo"]), abs(humidity - rule["hi"]))
return _clamp(100 - 2 * dist), note
return _peak(humidity, rule["lo"], rule["hi"], rule.get("best"), 2), note
if rule["type"] == "higher":
return _linear(humidity, 40, 90), note
if rule["type"] == "lower":
@@ -180,7 +194,8 @@ 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 = round(sum(factors[a] * weights[a] for a in AXES) / 100)
worst = min((factors[a] for a in AXES if weights[a]), default=100)
score = round(sum(factors[a] * weights[a] for a in AXES) / 100 * (1 - _WORST_PULL + _WORST_PULL * worst / 100))
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)),
+26 -10
View File
@@ -56,6 +56,7 @@ ORDER = {
_SKY_MODE = {"morning": "morning", "day": "day", "evening": "sunset", "night": "night"}
_CATEGORY_META = {ArticleCategory.SEASON.value: "계절 소식", ArticleCategory.TIP.value: "날씨 상식", ArticleCategory.GAK.value: "각 원리", ArticleCategory.QUOTE.value: "한 문장"}
_FEED_TTL_MAX = 3600
_SUNSET_HOUR = 18 # 노을 시간대 각의 대략적인 순서용
_RAIN_PROB = 40
_SUNSET_FULL = 60
_FEED_DAY_START = 3 # 03:00 에 그날 카드가 바뀐다
@@ -100,10 +101,26 @@ def feed_ttl_sec(now: datetime, sunset_at: datetime) -> int:
def _gak_key(item: IndexItem, hour: int) -> tuple[int, int, int]:
"""하기 좋은 시간이 가까운 각을 앞에, 오늘 시간이 지난 각을 뒤에."""
ahead = [w for w in item.definition.windows or [] if w["to"] > hour]
spans = [_span(w) for w in item.definition.windows or []]
ahead = [(lo, hi) for lo, hi in spans if hi > hour]
if not ahead:
return 1, 0, item.rank
return 0, min(max(0, w["from"] - hour) for w in ahead), item.rank
return 0, min(max(0, lo - hour) for lo, _ in ahead), item.rank
def _span(w: dict) -> tuple[int, int]:
if w.get("around") == "sunset":
return _SUNSET_HOUR - w.get("hours", 1), _SUNSET_HOUR + w.get("hours", 1) + 1
return w["from"], w["to"]
def _weekends(days: list[DayPlan]) -> list[list[DayPlan]]:
"""예보가 있는 토·일을 주마다 묶는다. 다음 주말은 예보가 닿는 날(오늘+10일)부터 보인다."""
out: dict[date, list[DayPlan]] = {}
for d in days:
if d.day.weekday() >= 5:
out.setdefault(d.day - timedelta(days=d.day.weekday()), []).append(d)
return list(out.values())
def _spread(cards: list[PostData]) -> list[PostData]:
@@ -155,8 +172,6 @@ async def build_feed_day(day: date, crud: FeedCRUD, season_crud: SeasonCRUD) ->
end = start + timedelta(days=1)
rows = []
for position, post_type, ref_type, rank in LINEUP:
if post_type is PostType.WEEK and day.weekday() < 3:
continue
ref = refs.get(post_type)
if ref_type is RefType.ARTICLE and ref is None:
continue
@@ -335,13 +350,14 @@ class FeedService:
slides=[RowsSlide(kind="rows", eyebrow=f"{c.region.name.split()[0]} 행사 · {e.status_label}", line=e.event.name, icon=e.event.icon, rows=rows)],
share_messages=[f"{e.event.name} 같이 갈래?"])
if t is PostType.WEEK and c.days:
weekend = [d for d in c.days if d.day.weekday() >= 5][:2]
if not weekend:
weekends = _weekends(c.days)
if not weekends:
return None
return PostData(**base, title="이번 주말 추천", icon="calendar", caption=" ".join(f"{d.weekday}요일은 {d.pick}." for d in weekend),
slides=[WeekSlide(kind="week", eyebrow=f"이번 주말 · {c.region.short_name}", line=weekend[0].pick, days=[
WeekDay(day=d.day, weekday=d.weekday, icon=d.icon, text=d.headline) for d in weekend
])], share_messages=["이번 주말 같이 놀자 🙌"])
first = weekends[0]
return PostData(**base, title="이번 주말 추천", icon="calendar", caption=" ".join(f"{d.weekday}요일은 {d.pick}." for d in first),
slides=[WeekSlide(kind="week", eyebrow=f"{label} · {c.region.short_name}", line=w[0].pick, days=[
WeekDay(day=d.day, weekday=d.weekday, icon=d.icon, text=d.headline) for d in w
]) for label, w in zip(("이번 주말", "다음 주말"), weekends)], share_messages=["이번 주말 같이 놀자 🙌"])
if t is PostType.QUOTE:
return self._quote(base, c)
return None
+1 -1
View File
@@ -25,7 +25,7 @@ from services.external.kma import fetch_mid, latest_mid_base, parse_mid
from services.external.tour_api import fetch_festivals, parse_festivals
from services.index_service import IndexService
DAYS = 7
DAYS = 11 # 중기예보가 닿는 오늘+10일까지
EVENT_DAYS = 30
# 몇 달씩 이어지는 상설 행사는 '이번 주 행사'로 보이지 않게 뺀다.
MAX_EVENT_DAYS = 60