From 751beb6e3307d402738eb35be820282cea9b280f Mon Sep 17 00:00:00 2001 From: Mina Choi Date: Thu, 29 Oct 2026 16:12:40 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=98=A4=EB=8A=98=EC=9D=98=20=EA=B0=81?= =?UTF-8?q?=20=EC=A4=84=20=EB=82=A0=EC=94=A8=EA=B0=80=20=EC=A7=80=EA=B8=88?= =?UTF-8?q?=20=EC=8B=9C=EA=B0=81=EC=9D=B4=20=EC=95=84=EB=8B=88=EB=9D=BC=20?= =?UTF-8?q?=EB=82=A8=EC=9D=80=20=EA=B5=AC=EA=B0=84=20=EA=B0=80=EC=9A=B4?= =?UTF-8?q?=EB=8D=B0=20=EC=8B=9C=EA=B0=81(4=EC=8B=9C=2010=EB=B6=84?= =?UTF-8?q?=EC=9D=B8=EB=8D=B0=20'=EC=98=A4=ED=9B=84=205=EC=8B=9C')?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B3=B4=EC=9D=B4=EB=8D=98=20=EA=B2=83=20?= =?UTF-8?q?=E2=80=94=20=EC=A7=80=EA=B8=88=20=EA=B5=AC=EA=B0=84=EC=9D=80=20?= =?UTF-8?q?=EC=A7=80=EA=B8=88=20=EC=8B=9C=EA=B0=81=20=EB=82=A0=EC=94=A8?= =?UTF-8?q?=EB=A1=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/services/calc/index_calc.py | 6 +++++- backend/services/index_service.py | 8 +++++--- backend/tests/test_index_slots.py | 10 ++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/backend/services/calc/index_calc.py b/backend/services/calc/index_calc.py index 7dc9fdb..9e3a636 100644 --- a/backend/services/calc/index_calc.py +++ b/backend/services/calc/index_calc.py @@ -295,7 +295,11 @@ _SKY_WORD = {Sky.CLEAR: "맑음", Sky.PARTLY: "구름 많음", Sky.CLOUDY: "흐 def _summary(hours: list[Hour]) -> str: - mid = hours[len(hours) // 2] + return summary_line(hours[len(hours) // 2]) + + +def summary_line(mid: Hour) -> str: + """그 시각 날씨 한 줄 (오후 5시 13°, 비 60%).""" wind = mid.wind_ms tag = f"비 {mid.rain_prob}%" if mid.rain_prob >= 50 else ( "바람 살랑" if wind is not None and wind <= 2 else "바람 조금" if wind is not None and wind <= 5 else "바람 강함" if wind is not None else _SKY_WORD[mid.sky] diff --git a/backend/services/index_service.py b/backend/services/index_service.py index 6294c0b..0e26f0c 100644 --- a/backend/services/index_service.py +++ b/backend/services/index_service.py @@ -19,7 +19,7 @@ from crud.weather_crud import WeatherCRUD from crud.week_crud import WeekCRUD from services.air_service import GRADE_LABEL, AirService from services.calc.day_slot import NIGHT_END_HOUR, SLOTS, slot_hours, slot_of -from services.calc.index_calc import AXES, Context, DayForecast, Hour, Result, estimate, evaluate, priority_score, rank_score +from services.calc.index_calc import AXES, Context, DayForecast, Hour, Result, estimate, evaluate, priority_score, rank_score, summary_line from services.calc.moon import night, up_ratio, view_line from services.calc.sun import sun_times from services.external.open_meteo import is_dark_slot @@ -240,8 +240,7 @@ def slot_results( """각 구간의 날씨로 평가한다. 활동 시간대와 안 겹쳐도 계산하되 시간 요소는 0점. now 가 있으면 현재 구간은 남은 시각만 본다.""" hours_by_slot = slot_hours(day, sunset_at) hours_by_slot[EARLY] = set(range(NIGHT_END_HOUR)) - if now: - _trim_passed(hours_by_slot, day, sunset_at, now) + cur = _trim_passed(hours_by_slot, day, sunset_at, now) if now else None activity = [{h % 24 for h in w} for w in window_hours(defn, day, region)] out = {} for key, hours in hours_by_slot.items(): @@ -253,6 +252,9 @@ def slot_results( windows = windows_for(window, day, region, by_at, by_om, only=hours) result = evaluate(defn, windows, replace(ctx, time_matches=matches)) if result is not None: + # 지금 구간 줄은 남은 시간의 가운데가 아니라 지금 시각 날씨로 + if key == cur and windows and windows[0]: + result.summary = summary_line(windows[0][0]) out[key] = result return out diff --git a/backend/tests/test_index_slots.py b/backend/tests/test_index_slots.py index ad14fae..ac8c249 100644 --- a/backend/tests/test_index_slots.py +++ b/backend/tests/test_index_slots.py @@ -110,3 +110,13 @@ def test_running_muggy_morning_does_not_exceed_original_weather_score(): results = slot_results(RUNNING, SAT, REGION, hourly, {}, replace(CTX, pm25=30), start + timedelta(hours=18)) assert results["morning"].factors["time"] == 100 assert results["morning"].score <= 67 + + +def test_now_slot_summary_shows_current_hour_not_middle_of_rest(): + """오후 4시 10분이면 지금 구간 줄은 남은 16~18시의 가운데(5시)가 아니라 지금(4시) 날씨로.""" + start = kst_midnight(SAT) + hourly = _hourly(SAT) | _hourly(SAT + timedelta(days=1)) + sunset = start + timedelta(hours=17, minutes=30) + results = slot_results(RUNNING, SAT, REGION, hourly, {}, CTX, sunset, now=start + timedelta(hours=16, minutes=10)) + assert results["evening"].summary.startswith("오후 4시"), results["evening"].summary + assert results["night"].summary.startswith("오후 4시") is False