fix: 달이 안 보일 때 이유를 붙여 말하기(삭·일찍 짐·늦게 뜸·흐림), 달 포스트 설명글을 본문 판정에 맞추기
This commit is contained in:
1 parent
ef57a47e29
commit
f4fe3e965c
6 files changed
+25
-13
No files matched your search
@@ -102,6 +102,7 @@ class MoonNight:
|
||||
"""그날 밤(19시~다음 날 5시) 달. lit 는 빛나는 면의 비율(모양), 밝기가 아니다."""
|
||||
name: str
|
||||
lit: float
|
||||
waxing: bool # 삭 → 보름 사이 (해 진 뒤 서쪽 하늘에 있다가 지는 쪽)
|
||||
rise_at: Optional[datetime] # 밤 사이에 뜨면 그 시각 (저녁부터 떠 있으면 None)
|
||||
set_at: Optional[datetime] # 밤 사이에 지면 그 시각 (새벽까지 떠 있으면 None)
|
||||
up_hours: tuple[int, ...] # 달이 떠 있는 시각 (19~28, 24 이상은 다음 날)
|
||||
@@ -124,7 +125,7 @@ def night(day: date, lat: float, lon: float) -> MoonNight:
|
||||
ups.add(int((at - start).total_seconds() // 3600))
|
||||
prev = up
|
||||
at += _STEP
|
||||
return MoonNight(name=phase_name(mid), lit=illumination(mid), rise_at=rise_at, set_at=set_at, up_hours=tuple(sorted(ups)))
|
||||
return MoonNight(name=phase_name(mid), lit=illumination(mid), waxing=_fraction(mid) < 0.5, rise_at=rise_at, set_at=set_at, up_hours=tuple(sorted(ups)))
|
||||
|
||||
|
||||
def up_ratio(m: MoonNight, hours: range) -> float:
|
||||
@@ -133,13 +134,15 @@ def up_ratio(m: MoonNight, hours: range) -> float:
|
||||
|
||||
|
||||
def view_line(m: MoonNight, cloudy: Optional[float]) -> str:
|
||||
"""오늘 밤 달이 잘 보이는지 한 마디. cloudy 는 달이 떠 있는 동안 흐린 정도 0~1 (모르면 None)."""
|
||||
if m.lit < 0.03 or not m.up_hours:
|
||||
return "달이 안 보여요"
|
||||
"""오늘 밤 달이 잘 보이는지 한 마디. 안 보이면 왜인지까지. cloudy 는 달이 떠 있는 동안 흐린 정도 0~1 (모르면 None)."""
|
||||
if m.lit < 0.03:
|
||||
return "해와 같은 쪽에 있어 안 보여요"
|
||||
if not m.up_hours:
|
||||
return "해 진 뒤 곧 져서 밤엔 안 보여요" if m.waxing else "새벽 늦게 떠서 밤엔 안 보여요"
|
||||
if m.rise_at is not None and m.rise_at.hour not in range(19, 22):
|
||||
return f"{_clock(m.rise_at)}에 떠요"
|
||||
if cloudy is not None and cloudy >= 0.6:
|
||||
return "구름에 가려요"
|
||||
return "흐려서 구름에 가려요"
|
||||
if cloudy is not None and cloudy >= 0.3:
|
||||
return "구름 사이로 보여요"
|
||||
if m.set_at is not None:
|
||||
|
||||
@@ -530,7 +530,9 @@ class FeedService:
|
||||
nxt = nearest(tonight + timedelta(days=15), True) if full < tonight else full
|
||||
nxt = nxt.astimezone(KST)
|
||||
waxing = name in ("초승달", "상현달", "차오르는 달")
|
||||
caption = ("구름이 많아 달은 숨바꼭질해요." if sky is Sky.CLOUDY
|
||||
# 본문(잘 보이는지)과 어긋나지 않게: 안 보이는 밤·흐린 밤은 그 이유에 맞춰서
|
||||
caption = ("달이 없는 만큼 별은 더 잘 보여요 ✨" if "안 보여요" in view
|
||||
else "구름 사이로 잠깐씩 보일 수도 있어요." if view.startswith("흐려서")
|
||||
else "하루하루 차오르는 중이에요. 보름까지 같이 세어 봐요 🌙" if waxing else "조금씩 기우는 중이에요. 그만큼 별은 더 잘 보여요 ✨")
|
||||
return PostData(**base, title=f"오늘 밤 {name}", icon="moon", caption=caption,
|
||||
slides=[RowsSlide(kind="rows", eyebrow=eyebrow, line=f"오늘 밤은 {name},\n{view}", icon="moon",
|
||||
@@ -539,7 +541,7 @@ class FeedService:
|
||||
when = f"{'내일 ' if at.date() > tonight.date() else ''}{at:%H:%M}"
|
||||
if is_full:
|
||||
line = f"오늘 밤 보름달,\n{when}에 가장 둥글어요"
|
||||
caption = "구름 사이로 잠깐씩 보일 수 있어요." if sky is Sky.CLOUDY else "소원 빌기 딱 좋은 밤이에요 🌕"
|
||||
caption = "구름 사이로 잠깐씩 보일 수 있어요." if view.startswith("흐려서") else "소원 빌기 딱 좋은 밤이에요 🌕"
|
||||
return PostData(**base, title="오늘 밤 보름달", icon="moon", caption=caption,
|
||||
slides=[RowsSlide(kind="rows", eyebrow=eyebrow, line=line, icon="moon", rows=[Row(label="보이는지", value=view), *rows])],
|
||||
share_messages=["오늘 밤 보름달이래 🌕 같이 볼래?"])
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
from dataclasses import replace
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from types import SimpleNamespace
|
||||
|
||||
from common.enums import PostType
|
||||
from common.utils.kma_time import KST
|
||||
from services.calc.moon import altitude, nearest, night, phase_name, view_line
|
||||
from services.calc.moon import MoonNight, altitude, nearest, night, phase_name, view_line
|
||||
from services.feed_service import FeedService, _tonight
|
||||
|
||||
|
||||
@@ -57,7 +58,7 @@ def test_full_moon_is_up_all_night_and_highest_near_solar_midnight():
|
||||
peak = max((start + timedelta(hours=22, minutes=10 * i) for i in range(24)), key=lambda t: altitude(t, *SEOUL))
|
||||
assert 23 <= (peak.hour if peak.hour >= 12 else peak.hour + 24) <= 25
|
||||
assert view_line(m, 0.0) == "밤새 잘 보여요"
|
||||
assert view_line(m, 0.8) == "구름에 가려요"
|
||||
assert view_line(m, 0.8) == "흐려서 구름에 가려요"
|
||||
|
||||
|
||||
def test_first_quarter_sets_around_midnight_and_new_moon_is_not_seen():
|
||||
@@ -65,7 +66,10 @@ def test_first_quarter_sets_around_midnight_and_new_moon_is_not_seen():
|
||||
quarter = night(_night_of(new + timedelta(days=7.4)), *SEOUL)
|
||||
assert quarter.set_at is not None and quarter.set_at.astimezone(KST).hour in (21, 22, 23, 0, 1, 2)
|
||||
assert view_line(quarter, 0.0).endswith("까지 보여요")
|
||||
assert view_line(night(_night_of(new), *SEOUL), 0.0) == "달이 안 보여요"
|
||||
assert view_line(night(_night_of(new), *SEOUL), 0.0) == "해와 같은 쪽에 있어 안 보여요"
|
||||
hidden = MoonNight(name="초승달", lit=0.05, waxing=True, rise_at=None, set_at=None, up_hours=())
|
||||
assert view_line(hidden, 0.0) == "해 진 뒤 곧 져서 밤엔 안 보여요"
|
||||
assert view_line(replace(hidden, name="그믐달", waxing=False), 0.0) == "새벽 늦게 떠서 밤엔 안 보여요"
|
||||
|
||||
|
||||
def test_waning_moon_rises_late():
|
||||
|
||||
Reference in new issue
Block a user