fix: 지금 비가 오는데 '비 60%'·'5시쯤 비가 와요'로 나오던 문구 — 실황으로 본 대로

- 지금 구간 한 줄(히어로·각): 실황으로 관측한 시각은 예보 확률 대신 본 대로 씀. 비가 오면 '비 오는 중'(눈·진눈깨비도), 비가 없으면 확률 없이 바람·하늘. 비가 관측됐는데 예보 확률이 낮아 '바람 조금'으로 나오던 것도 같이 고쳐짐. 예보 시각(다른 구간·내일)은 그대로 확률
- 2시간 비 안내: 실황이 지금 비를 관측했으면 앞으로의 예보보다 먼저 '지금 비가 와요. 우산 챙기세요'
- 매시 00~10분은 그 시각 실황이 아직 없어 예보 문구가 나옴
This commit is contained in:
skkim committed 2026-11-23 16:22:50 +09:00
1 parent 4fd757e5b4
commit b0e6a01157
6 files changed
+105 -9

No files matched your search

+11 -5
View File
@@ -15,7 +15,7 @@ from crud.region_crud import RegionCRUD
from crud.weather_crud import WeatherCRUD
from services.air_service import GRADE_LABEL, AirService
from services.warning_service import WarningItem, WarningService
from services.weather_service import RainHour, WeatherService, ultra_hours
from services.weather_service import RainHour, WeatherService, observed_now, ultra_hours
_COMMUTE = (("내일 출근 8시", 8), ("내일 퇴근 7시", 19))
@@ -52,7 +52,13 @@ def _weather_word(rain: RainType, sky: Sky, rain_mm: float) -> tuple[str, str]:
return {Sky.CLEAR: ("sun", "맑음"), Sky.PARTLY: ("sun_cloud", "구름 많음"), Sky.CLOUDY: ("cloud", "흐림")}[sky]
def _rain_2h_text(hours: list[RainHour]) -> tuple[bool, str]:
_NOW_WORD = {RainType.SNOW: "눈이", RainType.SLEET: "진눈깨비가"}
def _rain_2h_text(hours: list[RainHour], now_rain: Optional[RainType] = None) -> tuple[bool, str]:
"""now_rain: 실황으로 관측한 지금 비 형태 (관측이 없으면 None). 지금 오는 중이면 앞으로의 예보보다 먼저 알린다."""
if now_rain is not None and now_rain is not RainType.NONE:
return True, f"지금 {_NOW_WORD.get(now_rain, '비가')} 와요. 우산 챙기세요"
rainy = [h for h in hours if h.rain_type is not RainType.NONE]
if not rainy:
return False, "앞으로 2시간, 우산 없어도 돼요"
@@ -98,9 +104,9 @@ class NowService:
return ErrorType.NOT_FOUND, None
now = now_kst()
ultra, _, _, warnings = await asyncio.gather(
ultra, _, _, warnings, observed = await asyncio.gather(
self._ultra(region, now), self.weather_service.ensure_vilage(region, now), self.air_service.ensure(now),
self.warning_service.for_region(region, now),
self.warning_service.for_region(region, now), observed_now(region, now),
)
tomorrow_start = kst_midnight(now.date() + timedelta(days=1))
err, next_rows = await DB_SESSION_MNG.execute_lambda(
@@ -115,7 +121,7 @@ class NowService:
hours = [h for h in hours if now < h.at <= now + timedelta(hours=2)]
if not hours and not next_rows:
return ErrorType.EXTERNAL_API_ERROR, None
will_rain, rain_text = _rain_2h_text(hours)
will_rain, rain_text = _rain_2h_text(hours, observed.rain_type if observed else None)
rain_from, tomorrow_text, commute = _tomorrow([r for r in next_rows if r.forecast_at >= tomorrow_start])
air = await self.air_service.nearest(region)
air_text = None