fix: 주말 동선 행사를 축제→공연→팝업→전시 순으로 종류마다 하나씩

This commit is contained in:
minaChoi committed 2026-10-07 20:12:59 +09:00
1 parent 73294622ad
commit f4d5472776
2 files changed
+22 -5

No files matched your search

+11 -3
View File
@@ -2,6 +2,7 @@ from dataclasses import dataclass
from datetime import date, datetime
from typing import Optional
from common.enums import EventKind
from common.utils.kma_time import KST
from common.utils.text import day_range, short_day
from services.week_service import DayPlan, EventItem, image_credit
@@ -10,6 +11,8 @@ _HOT = 28
_COLD = 10
_BIG_GAP = 10
_MAX_EVENTS = 2
# 주말 동선은 축제를 먼저, 전시는 마지막. 가깝다고 미술관만 이어지지 않게
_KIND_RANK = {EventKind.FESTIVAL: 0, EventKind.CONCERT: 1, EventKind.POPUP: 2, EventKind.EXHIBITION: 3}
@dataclass
@@ -77,11 +80,16 @@ def forecast(days: list[DayPlan]) -> WeekendForecast:
def pick_events(d: date, events: list[EventItem], exclude: frozenset[int] = frozenset()) -> list[EventItem]:
"""그날 열리는 행사 중 가까운 순. 일요일은 그날 끝나는 것을 먼저 (마지막 날 찬스)."""
"""그날 열리는 행사를 축제→공연→팝업→전시 순으로 종류마다 하나씩, 같은 종류는 가까운 순. 일요일은 같은 종류 안에서 그날 끝나는 것을 먼저 (마지막 날 찬스)."""
sunday = d.weekday() == 6
open_ = [e for e in events if e.event.start_date <= d <= e.event.end_date and e.event.event_id not in exclude]
open_.sort(key=lambda e: (sunday and e.event.end_date != d, e.distance_km if e.distance_km is not None else 9999))
return open_[:_MAX_EVENTS]
open_.sort(key=lambda e: (_KIND_RANK.get(e.event.kind, len(_KIND_RANK)), sunday and e.event.end_date != d,
e.distance_km if e.distance_km is not None else 9999))
first, rest, kinds = [], [], set()
for e in open_:
(rest if e.event.kind in kinds else first).append(e)
kinds.add(e.event.kind)
return (first + rest)[:_MAX_EVENTS]
def _place(e: EventItem) -> str:
+11 -2
View File
@@ -1,6 +1,7 @@
from datetime import date, datetime
from types import SimpleNamespace
from common.enums import EventKind
from common.utils.kma_time import KST
from services.week_service import DayPlan, EventItem
from services.weekend_plan import day_plan, forecast, pick_events
@@ -14,8 +15,8 @@ def _day(d: date, lo=12.0, hi=26.0, rainy=False, rain_hours=None, prob=10) -> Da
headline="", summary="", pick="", rain_hours=rain_hours, is_rainy=rainy, rain_prob=prob)
def _event(name, start, end, dist, image="https://img/x.jpg") -> EventItem:
e = SimpleNamespace(event_id=hash(name), name=name, icon="fireworks", start_date=start, end_date=end, place_name="경기도 고양시 일산동구 호수로 595", image_url=image, source_id="1")
def _event(name, start, end, dist, image="https://img/x.jpg", kind=EventKind.FESTIVAL) -> EventItem:
e = SimpleNamespace(event_id=hash(name), name=name, kind=kind, icon="fireworks", start_date=start, end_date=end, place_name="경기도 고양시 일산동구 호수로 595", image_url=image, source_id="1")
return EventItem(event=e, status="live", status_label="진행 중", fit=None, distance_km=dist)
@@ -64,6 +65,14 @@ def test_saturday_ignores_ending_hook_and_sunday_skips_saturday_events():
assert pick_events(SUN, [near, far], frozenset(e.event.event_id for e in sat)) == []
def test_festival_and_concert_come_before_nearer_galleries():
events = [_event("옆 전시1", SAT, SUN, 0.5, kind=EventKind.EXHIBITION), _event("옆 전시2", SAT, SUN, 0.6, kind=EventKind.EXHIBITION),
_event("먼 공연", SAT, SAT, 20.0, kind=EventKind.CONCERT), _event("먼 축제", SAT, SUN, 25.0)]
assert [e.event.name for e in pick_events(SAT, events)] == ["먼 축제", "먼 공연"]
only_galleries = events[:2]
assert [e.event.name for e in pick_events(SAT, only_galleries)] == ["옆 전시1", "옆 전시2"]
def test_cloudy_weekend_is_not_called_clear():
cloudy = [_day(SAT), _day(SUN)]
for d in cloudy: