fix: 미세먼지 포스트 — 비 오는데 '창문 활짝 열어도 돼요'라던 것, 비 오면 '창문은 닫아 둬요'. 수치(㎍/㎥) 대신 등급만
This commit is contained in:
1 parent
a8871b9231
commit
2621db0450
2 files changed
+12
-7
No files matched your search
@@ -117,6 +117,7 @@ _AIR_LINE = {
|
||||
AirGrade.BAD: ("공기가 탁해요,\n마스크 챙겨요", "😷 마스크 챙겨!"),
|
||||
AirGrade.VERY_BAD: ("공기가 많이 탁해요,\n바깥은 짧게", "😷 오늘은 실내로!"),
|
||||
}
|
||||
_AIR_RAIN_LINE = ("공기는 맑은데 비가 와요,\n창문은 닫아 둬요", "☔ 창문은 닫아 둬!") # 맑음·보통인데 지금~2시간 안에 비
|
||||
_AIR_ADVICE = {
|
||||
AirGrade.BAD: "KF80 마스크 쓰고, 오래 뛰는 바깥 운동은 줄여요",
|
||||
AirGrade.VERY_BAD: "외출은 줄이고 창문은 닫아 둬요. 나가면 KF94 마스크",
|
||||
@@ -645,11 +646,12 @@ class FeedService:
|
||||
return None
|
||||
worst = max(g for _, _, g in values)
|
||||
label = AIR_GRADE_LABEL[worst]
|
||||
rows = [Row(label=name, value=f"{v}㎍/㎥ · {AIR_GRADE_LABEL[g]}") for name, v, g in values]
|
||||
rows = [Row(label=name, value=AIR_GRADE_LABEL[g]) for name, _, g in values]
|
||||
if worst in _AIR_ADVICE:
|
||||
rows.append(Row(label="이렇게 해요", value=_AIR_ADVICE[worst]))
|
||||
line, tail = _AIR_LINE[worst]
|
||||
icon = "vent" if worst <= AirGrade.NORMAL else "cloud"
|
||||
raining = worst <= AirGrade.NORMAL and c.now_w.will_rain_2h
|
||||
line, tail = _AIR_RAIN_LINE if raining else _AIR_LINE[worst]
|
||||
icon = "umbrella" if raining else "vent" if worst <= AirGrade.NORMAL else "cloud"
|
||||
return PostData(**base, title=f"미세먼지 {label}", icon=icon, caption=f"{air.station_name} 측정소 · {air.measured_at.astimezone(KST).hour}시 기준",
|
||||
slides=[RowsSlide(kind="rows", eyebrow=f"지금 공기 · {c.region.short_name}", line=line, icon=icon, rows=rows)],
|
||||
share_messages=[f"{c.region.short_name} 지금 미세먼지 {label} {tail}"])
|
||||
|
||||
@@ -72,7 +72,7 @@ async def test_feed_assembles_hero_stories_posts_and_bands(offline):
|
||||
assert body["bands"]["events"][0]["image_credit"] == "ⓒ한국관광공사"
|
||||
assert "미세먼지" not in weather["caption"]
|
||||
air = next(p for p in body["posts"] if p["post_type"] == PostType.AIR.value)
|
||||
assert [(r["label"], r["value"]) for r in air["slides"][0]["rows"]] == [("초미세먼지", "10㎍/㎥ · 좋음"), ("미세먼지", "20㎍/㎥ · 좋음")]
|
||||
assert [(r["label"], r["value"]) for r in air["slides"][0]["rows"]] == [("초미세먼지", "좋음"), ("미세먼지", "좋음")]
|
||||
event = next(p for p in body["posts"] if p["post_type"] == PostType.EVENT.value)
|
||||
assert event["slides"][0]["eyebrow"].startswith("가까운 행사 · ")
|
||||
|
||||
@@ -275,7 +275,7 @@ def test_text_helpers_short_day_and_compass():
|
||||
assert compass(263) == "서" and compass(247) == "서남서"
|
||||
|
||||
|
||||
def _air(pm25, pm10, measured_hours_ago=0):
|
||||
def _air(pm25, pm10, measured_hours_ago=0, rain=False):
|
||||
from datetime import datetime
|
||||
from types import SimpleNamespace
|
||||
|
||||
@@ -285,7 +285,7 @@ def _air(pm25, pm10, measured_hours_ago=0):
|
||||
now = datetime(2026, 10, 2, 9, 30, tzinfo=KST)
|
||||
air = None if pm25 is None and pm10 is None else SimpleNamespace(
|
||||
station_name="테스트", pm25=pm25, pm10=pm10, measured_at=now.replace(minute=0) - timedelta(hours=measured_hours_ago))
|
||||
ctx = SimpleNamespace(now=now, region=SimpleNamespace(short_name="종로구"), now_w=SimpleNamespace(air=air))
|
||||
ctx = SimpleNamespace(now=now, region=SimpleNamespace(short_name="종로구"), now_w=SimpleNamespace(air=air, will_rain_2h=rain))
|
||||
return FeedService._air(None, _base() | {"post_type": PostType.AIR}, ctx)
|
||||
|
||||
|
||||
@@ -294,8 +294,11 @@ def test_air_post_shows_both_values_and_advice_only_when_bad():
|
||||
assert [r.label for r in good.slides[0].rows] == ["초미세먼지", "미세먼지"] and good.title == "미세먼지 좋음"
|
||||
bad = _air(40, 60)
|
||||
assert bad.title == "미세먼지 나쁨" and bad.slides[0].rows[-1].label == "이렇게 해요"
|
||||
wet = _air(10, 20, rain=True)
|
||||
assert "창문은 닫아" in wet.slides[0].line and wet.icon == "umbrella"
|
||||
assert "창문은 닫아" not in _air(40, 60, rain=True).slides[0].line
|
||||
very = _air(20, 160)
|
||||
assert very.title == "미세먼지 매우나쁨" and "측정소" in very.caption and very.slides[0].rows[1].value == "160㎍/㎥ · 매우나쁨"
|
||||
assert very.title == "미세먼지 매우나쁨" and "측정소" in very.caption and very.slides[0].rows[1].value == "매우나쁨"
|
||||
|
||||
|
||||
def test_air_post_off_without_fresh_data():
|
||||
|
||||
Reference in new issue
Block a user