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 diff --git a/frontend/src/b/TodayPage.tsx b/frontend/src/b/TodayPage.tsx index c3b848d..662bcec 100644 --- a/frontend/src/b/TodayPage.tsx +++ b/frontend/src/b/TodayPage.tsx @@ -639,7 +639,7 @@ export function TodayPage() { } className="inset-x-3 top-3.5 bottom-auto" /> )} {/* 단풍철엔 단풍 지도를 포스트 맨 앞에 */} - {load !== 'loading' && posts.length > 0 && } + {load !== 'loading' && posts.length > 0 && } {posts.map((p, i) => { const t = talkAt(i) const ev = eventNo.get(p.post_id) diff --git a/frontend/src/b/foliageMap.tsx b/frontend/src/b/foliageMap.tsx index 45879d9..f8f4812 100644 --- a/frontend/src/b/foliageMap.tsx +++ b/frontend/src/b/foliageMap.tsx @@ -1,5 +1,6 @@ import { useEffect, useLayoutEffect, useMemo, useRef, useState, type MouseEvent } from 'react' import { useNavigate } from 'react-router' +import type { PostReaction } from '@nalssigak/shared/api/client/types.gen' import { cx } from '../lib/utils' import { useCarousel } from './carousel' import { headline, ICON_R, LABEL, LABEL_INK, LEAF_SHADOW, MAP_IMG, MAP_SRC, md, placeLabels, PROVINCE, PROVINCES, labelBoxes, placeProvinces, rankNow, spread, useFoliage, useLabelSize } from './foliage' @@ -14,7 +15,7 @@ const TAP_R = 24 const RANK_N = 7 /** 피드의 단풍 지도 카드: 1장은 지금 절정인 곳만 잎 아이콘으로(누르면 카드 안에 정보), 2장은 지금 가기 좋은 순위. '지도 크게 보기'로 단풍 지도 페이지 */ -export function FoliageCard() { +export function FoliageCard({ post }: { post?: PostReaction | null }) { const navigate = useNavigate() const { today, spots, inSeason } = useFoliage() const peak = useMemo(() => spots.filter((m) => m.stage === 'peak').sort((a, b) => Number(a.kind === 'ginkgo') - Number(b.kind === 'ginkgo') || a.y - b.y), [spots]) @@ -60,7 +61,7 @@ export function FoliageCard() { // 2번째 장: 지금 절정인 곳을 절정 예상일이 오늘과 가까운 순서로 const ranked = rankNow(spots).slice(0, RANK_N) return ( - m.name).join(' · ')}${peak.length > 5 ? ' 외' : ''}` : undefined}> + m.name).join(' · ')}${peak.length > 5 ? ' 외' : ''}` : undefined}>

단풍 지도 · {md(today)}

{headline(spots)}