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

+10 -4
View File
@@ -46,6 +46,7 @@ class Hour:
visibility_km: Optional[float] = None
gust_ms: Optional[float] = None
ground_c: Optional[float] = None
observed: bool = False # 예보가 아니라 초단기실황으로 관측한 시각 (비 확률이 뜻이 없다)
@dataclass(frozen=True)
@@ -311,12 +312,17 @@ def _summary(hours: list[Hour]) -> str:
return summary_line(hours[len(hours) // 2])
_RAINING_NOW = {RainType.RAIN: "비 오는 중", RainType.SHOWER: "비 오는 중", RainType.SLEET: "진눈깨비 오는 중", RainType.SNOW: "눈 오는 중"}
def summary_line(mid: Hour) -> str:
"""그 시각 날씨 한 줄 (오후 5시 13°, 비 60%)."""
"""그 시각 날씨 한 줄 (오후 5시 13°, 비 60%). 실황으로 관측한 시각은 확률 대신 본 대로 쓴다 (오후 4시 11°, 비 오는 중)."""
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]
)
calm = "바람 살랑" 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]
if mid.observed:
tag = _RAINING_NOW.get(mid.rain_type, calm)
else:
tag = f"비 {mid.rain_prob}%" if mid.rain_prob >= 50 else calm
return f"{hour_label(mid.hour % 24)} {round(mid.feels_c)}°, {tag}"
+1
View File
@@ -119,6 +119,7 @@ def _hour(r: WeatherHourly) -> Hour:
return Hour(
hour=r.forecast_at.astimezone(KST).hour, feels_c=float(r.feels_c), rain_type=RainType(r.rain_type), rain_prob=r.rain_prob,
wind_ms=float(r.wind_ms) if r.wind_ms is not None else None, humidity=r.humidity, sky=Sky(r.sky),
observed=getattr(r, "observed", False), # with_observed 가 실황으로 바꾼 행에만 붙인다
)
+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
+1
View File
@@ -93,6 +93,7 @@ def with_observed(by_at: dict[datetime, WeatherHourly], obs: Optional[Observed])
**cols, "rain_type": obs.rain_type.value, "rain_mm": obs.rain_mm, "temp_c": obs.temp_c, "humidity": obs.humidity, "wind_ms": obs.wind_ms,
"feels_c": feels_like_c(obs.temp_c, obs.humidity, obs.wind_ms, obs.at.month), "discomfort_index": discomfort_index(obs.temp_c, obs.humidity),
})
row.observed = True # DB 칸이 아니라 이 사본에만 붙는 표시: 한 줄 문구가 확률 대신 관측한 대로 쓴다
return {**by_at, obs.at: row}