fix: 히어로 비 칸은 오늘 하루 기준(곧 와요 / 오후 6시쯤 와요 / 안 와요), 챙길 것 없는 값으로 칸 채우지 않기

- 2시간 안 비는 '지금 비', 그 뒤 오늘 안 비는 '오늘 비 · N시쯤 와요', 없으면 '오늘 비 · 안 와요'
- '미세먼지 좋음'·'자외선 낮음'으로 빈 칸을 채우던 것 삭제 (나쁠 때만 경고로)
- 칸이 하나면 한 줄 전체를 씀
This commit is contained in:
minaChoi committed 2026-10-07 16:33:23 +09:00
1 parent 794e70e419
commit 1af2faa6f4
4 files changed
+22 -9

No files matched your search

+4
View File
@@ -74,6 +74,7 @@ _FEED_TTL_MAX = 3600
_PARTIAL_TTL = 60 _PARTIAL_TTL = 60
_SUNSET_HOUR = 18 # 노을 시간대 각의 대략적인 순서용 _SUNSET_HOUR = 18 # 노을 시간대 각의 대략적인 순서용
_RAIN_PROB = 40 _RAIN_PROB = 40
_HERO_RAIN_PROB = 60 # 히어로 '오늘 비': 오늘 남은 칸 중 비 형태가 있거나 확률이 이만큼 넘는 첫 칸
_SUNSET_FULL = 60 _SUNSET_FULL = 60
_FEED_DAY_START = 3 # 03:00 에 그날 카드가 바뀐다 _FEED_DAY_START = 3 # 03:00 에 그날 카드가 바뀐다
_COMMUTE_HOURS = (("내일 출근 8시", 8), ("내일 퇴근 7시", 19)) _COMMUTE_HOURS = (("내일 출근 8시", 8), ("내일 퇴근 7시", 19))
@@ -120,8 +121,11 @@ def _discomfort_label(v: int) -> str:
def _hero_input(now: datetime, slot: str, cur: Optional[WeatherHourly], now_w: Optional[NowWeather], today: Optional[TodayWeather], uv: Optional[float]) -> HeroInput: def _hero_input(now: datetime, slot: str, cur: Optional[WeatherHourly], now_w: Optional[NowWeather], today: Optional[TodayWeather], uv: Optional[float]) -> HeroInput:
temps = [float(x.row.temp_c) for x in today.slots if x.row] if today else [] temps = [float(x.row.temp_c) for x in today.slots if x.row] if today else []
rainy = [h for h in now_w.rain_hours if h.rain_type is not RainType.NONE] if now_w else [] rainy = [h for h in now_w.rain_hours if h.rain_type is not RainType.NONE] if now_w else []
ahead = [x for x in today.slots if x.row and x.at > now] if today else []
later = next((x.at for x in ahead if x.row.rain_type != RainType.NONE.value or x.row.rain_prob >= _HERO_RAIN_PROB), None)
return HeroInput( return HeroInput(
now=now, night=slot in ("evening", "night"), rain_at=rainy[0].at if rainy else None, now=now, night=slot in ("evening", "night"), rain_at=rainy[0].at if rainy else None,
rain_later_at=later, today_known=bool(ahead),
air=AirGrade(now_w.air.grade) if now_w and now_w.air and now_w.air.grade is not None else None, uv=uv, air=AirGrade(now_w.air.grade) if now_w and now_w.air and now_w.air.grade is not None else None, uv=uv,
temp_min=min(temps, default=None), temp_max=max(temps, default=None), temp_min=min(temps, default=None), temp_max=max(temps, default=None),
temp=float(cur.temp_c) if cur else None, feels=float(cur.feels_c) if cur else None, discomfort=cur.discomfort_index if cur else None, temp=float(cur.temp_c) if cur else None, feels=float(cur.feels_c) if cur else None, discomfort=cur.discomfort_index if cur else None,
+8 -6
View File
@@ -29,7 +29,9 @@ class HeroStatItem:
class HeroInput: class HeroInput:
now: datetime now: datetime
night: bool night: bool
rain_at: Optional[datetime] = None rain_at: Optional[datetime] = None # 앞으로 2시간 안에 비 오는 첫 시각 (초단기)
rain_later_at: Optional[datetime] = None # 그 뒤 오늘 안에 비 오는 첫 시각 (단기예보)
today_known: bool = False # 오늘 남은 시간 예보가 있어 '오늘 비 안 와요'라고 말할 수 있는지
air: Optional[AirGrade] = None air: Optional[AirGrade] = None
uv: Optional[float] = None uv: Optional[float] = None
temp_min: Optional[float] = None temp_min: Optional[float] = None
@@ -57,6 +59,8 @@ def hero_stats(x: HeroInput) -> list[HeroStatItem]:
alerts: list[HeroStatItem] = [] alerts: list[HeroStatItem] = []
if x.rain_at is not None: if x.rain_at is not None:
alerts.append(HeroStatItem("rain", "umbrella", "지금 비", _rain_value(x.now, x.rain_at), "rain")) alerts.append(HeroStatItem("rain", "umbrella", "지금 비", _rain_value(x.now, x.rain_at), "rain"))
elif x.rain_later_at is not None:
alerts.append(HeroStatItem("rain", "umbrella", "오늘 비", _rain_value(x.now, x.rain_later_at), "rain"))
if x.air in (AirGrade.BAD, AirGrade.VERY_BAD): if x.air in (AirGrade.BAD, AirGrade.VERY_BAD):
alerts.append(HeroStatItem("air", "mask", "미세먼지", GRADE_LABEL[x.air], "warn")) alerts.append(HeroStatItem("air", "mask", "미세먼지", GRADE_LABEL[x.air], "warn"))
if not x.night and x.uv is not None and x.uv >= UV_HIGH: if not x.night and x.uv is not None and x.uv >= UV_HIGH:
@@ -68,12 +72,10 @@ def hero_stats(x: HeroInput) -> list[HeroStatItem]:
if x.discomfort is not None and x.discomfort >= MUGGY: if x.discomfort is not None and x.discomfort >= MUGGY:
alerts.append(HeroStatItem("muggy", "muggy", "불쾌지수", f"{x.discomfort} · {_discomfort_label(x.discomfort)}", "warn")) alerts.append(HeroStatItem("muggy", "muggy", "불쾌지수", f"{x.discomfort} · {_discomfort_label(x.discomfort)}", "warn"))
# 비는 올 때만 알린다 (안 온다는 칸은 두지 않음) # 챙길 게 없을 땐 하루 기준 비 소식과 밤의 달만. '미세먼지 좋음'·'자외선 낮음' 같은 값으로 칸을 채우지 않는다
fills: list[HeroStatItem] = [] fills: list[HeroStatItem] = []
if x.air is not None: if x.today_known and x.rain_at is None and x.rain_later_at is None:
fills.append(HeroStatItem("air", "vent", "미세먼지", GRADE_LABEL[x.air])) fills.append(HeroStatItem("rain", "moon" if x.night else "sun", "오늘 밤 비" if x.night else "오늘 비", "안 와요"))
if not x.night and x.uv is not None:
fills.append(HeroStatItem("uv", "glasses", "자외선", f"{round(x.uv)} · {uv_label(x.uv)}"))
if x.night and x.moon: if x.night and x.moon:
fills.append(HeroStatItem("moon", "moon", "오늘 밤 달", x.moon)) fills.append(HeroStatItem("moon", "moon", "오늘 밤 달", x.moon))
+9 -2
View File
@@ -18,7 +18,14 @@ def test_clear_day_shows_uv_warning_and_temp_swing():
def test_rain_comes_first(): def test_rain_comes_first():
x = HeroInput(now=NOW, night=False, rain_at=NOW + timedelta(minutes=40), air=AirGrade.GOOD, uv=1.0) x = HeroInput(now=NOW, night=False, rain_at=NOW + timedelta(minutes=40), air=AirGrade.GOOD, uv=1.0)
assert _view(x) == [("umbrella", "지금 비", "오후 3시쯤 와요", "rain"), ("vent", "미세먼지", "좋음", "normal")] assert _view(x) == [("umbrella", "지금 비", "오후 3시쯤 와요", "rain")]
def test_rain_later_today_and_no_rain_today():
later = HeroInput(now=NOW, night=False, rain_later_at=NOW.replace(hour=18), today_known=True, air=AirGrade.GOOD, uv=1.0)
assert _view(later) == [("umbrella", "오늘 비", "오후 6시쯤 와요", "rain")]
dry = HeroInput(now=NOW, night=False, today_known=True, air=AirGrade.GOOD, uv=1.0)
assert _view(dry) == [("sun", "오늘 비", "안 와요", "normal")]
def test_bad_air_beats_uv_and_wears_mask(): def test_bad_air_beats_uv_and_wears_mask():
@@ -33,7 +40,7 @@ def test_summer_night_muggy_then_moon_and_no_card_for_no_rain():
def test_one_coldwind_card_only(): def test_one_coldwind_card_only():
x = HeroInput(now=NOW, night=False, temp_min=5, temp_max=17, temp=10, feels=6, uv=2.0) x = HeroInput(now=NOW, night=False, temp_min=5, temp_max=17, temp=10, feels=6, uv=2.0)
assert [s.icon for s in hero_stats(x)] == ["coldwind", "glasses"] assert [s.icon for s in hero_stats(x)] == ["coldwind"] # 낮은 자외선으로 빈 칸을 채우지 않는다
def test_nothing_known_gives_nothing(): def test_nothing_known_gives_nothing():
+1 -1
View File
@@ -124,7 +124,7 @@ function Hero({ hero, today, feedLoad, todayLoad }: HeroProps) {
<span className="block text-[12.5px] font-bold opacity-85">{feelsLine ?? <Skel className="w-[118px]" />}</span> <span className="block text-[12.5px] font-bold opacity-85">{feelsLine ?? <Skel className="w-[118px]" />}</span>
</div> </div>
</div> </div>
<div className="relative z-[3] mt-3 grid grid-cols-2 gap-2.5"> <div className={cx('relative z-[3] mt-3 grid gap-2.5', hero?.stats?.length === 1 ? 'grid-cols-1' : 'grid-cols-2')}>
{/* 두 칸은 서버가 지금 챙길 것(비·미세먼지·자외선·일교차 등) 순서로 골라 준다 */} {/* 두 칸은 서버가 지금 챙길 것(비·미세먼지·자외선·일교차 등) 순서로 골라 준다 */}
{hero?.stats?.length {hero?.stats?.length
? hero.stats.map((s) => ( ? hero.stats.map((s) => (