feat: 각 점수를 아침·낮·저녁·밤 구간별로 — 지금 구간 점수로 순위, 구간이 안 겹치는 각은 순위·피드에서 빼고 목록 끝에

This commit is contained in:
minaChoi committed 2026-10-08 17:07:26 +09:00
1 parent ffc330d478
commit d6525f592c
12 files changed
+226 -40

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
from datetime import date, datetime, time, timedelta
from common.utils.kma_time import KST
SLOTS = ("morning", "day", "evening", "night")
SLOT_LABEL = {"morning": "아침", "day": "낮", "evening": "저녁", "night": "밤"}
NIGHT_AFTER_SUNSET = timedelta(hours=1) # 해 지고 이만큼 지나면 밤
NIGHT_END_HOUR = 5
def slot_of(now: datetime, sunset_at: datetime) -> str:
"""아침 05–11 · 낮 11–일몰 2시간 전 · 저녁 일몰 2시간 전–일몰 1시간 뒤 · 밤 일몰 1시간 뒤–05. 밤은 계절 따라 18시대~21시대에 온다."""
h = now.hour
if NIGHT_END_HOUR <= h < 11:
return "morning"
if h >= 11 and now < sunset_at + NIGHT_AFTER_SUNSET:
return "day" if now < sunset_at - timedelta(hours=2) else "evening"
return "night"
def slot_hours(day: date, sunset_at: datetime) -> dict[str, set[int]]:
"""그날 5시~다음 날 5시를 구간별 시각으로 나눈다. 24 이상은 다음 날 시각. 한 시간은 그 30분 시점의 구간에 넣는다."""
out: dict[str, set[int]] = {s: set() for s in SLOTS}
start = datetime.combine(day, time(0), tzinfo=KST)
for h in range(NIGHT_END_HOUR, 24 + NIGHT_END_HOUR):
out[slot_of(start + timedelta(hours=h, minutes=30), sunset_at)].add(h)
return out