diff --git a/backend/services/feed_service.py b/backend/services/feed_service.py index 4db95a6..0450bee 100644 --- a/backend/services/feed_service.py +++ b/backend/services/feed_service.py @@ -648,15 +648,24 @@ class FeedService: slides=[RowsSlide(kind="rows", eyebrow="오늘의 한 문장", line=a.body[0], icon=a.icon, rows=rows)], share_messages=[a.body[0]]) +def _band_sentence(sentences: Optional[dict], score: int) -> Optional[str]: + """seed 의 점수 구간 설명 {"0": …, "30": …, "60": …, "80": …} 중 점수가 들어가는 구간 문장.""" + lo = next((x for x in sorted((int(k) for k in sentences or {}), reverse=True) if score >= x), None) + return sentences[str(lo)] if lo is not None else None + + def _gak_caption(i: IndexItem) -> str: - """슬라이드에 없는 내일 점수, 없으면 하기 좋은 시간.""" + """점수 구간 설명 문장 + 슬라이드에 없는 내일 점수(없으면 하기 좋은 시간).""" + band = _band_sentence(i.definition.sentences, i.score.score) nxt = next((x for x in i.trend if x.score_date > i.score.score_date), None) if nxt is not None: diff = nxt.score - i.score.score how = "비슷해요" if abs(diff) < 5 else f"오늘보다 {abs(diff)}점 {'높아요' if diff > 0 else '낮아요'}" - return f"내일은 {nxt.score}점, {how}." - spans = [_span(w) for w in i.definition.windows or []] - return f"하기 좋은 때는 {spans[0][0]}~{spans[0][1]}시예요." if spans else f"오늘의 각 {i.rank}위예요." + tail = f"내일은 {nxt.score}점, {how}." + else: + spans = [_span(w) for w in i.definition.windows or []] + tail = f"하기 좋은 때는 {spans[0][0]}~{spans[0][1]}시예요." if spans else f"오늘의 각 {i.rank}위예요." + return f"{band} {tail}" if band else tail def _temp_change(today: Optional[TodayWeather], tomorrow: Optional[TodayWeather]) -> Optional[str]: diff --git a/backend/tests/test_feed.py b/backend/tests/test_feed.py index a98db4d..6a935bd 100644 --- a/backend/tests/test_feed.py +++ b/backend/tests/test_feed.py @@ -338,3 +338,14 @@ async def test_feed_has_day_trip_card_with_city_event(offline, monkeypatch): assert rows["거리"].startswith("여기서 약 ") and rows["날씨"] == "비 10% · 체감 21° · 맑음" assert "춘천" in trip["caption"] assert event["line"] == "강릉 커피축제" and event["image"] == "https://tong.visitkorea.or.kr/c.jpg" + + +def test_gak_caption_starts_with_score_band_sentence(): + from types import SimpleNamespace + + from services.feed_service import _gak_caption + d = SimpleNamespace(sentences={"0": "쉬어요", "30": "애매", "60": "괜찮아요", "80": "딱 좋아요!"}, windows=[{"from": 18, "to": 24}]) + item = SimpleNamespace(definition=d, score=SimpleNamespace(score=83, score_date=date(2026, 10, 7)), trend=[], rank=1) + assert _gak_caption(item) == "딱 좋아요! 하기 좋은 때는 18~24시예요." + item.definition.sentences = {} + assert _gak_caption(item) == "하기 좋은 때는 18~24시예요."