fix: 저녁 시작을 17시보다 이르지 않게 — 겨울에 오후 3시가 저녁이던 것
This commit is contained in:
1 parent
639ca83553
commit
96e40d00c8
7 files changed
+53
-20
No files matched your search
@@ -6,15 +6,22 @@ SLOTS = ("morning", "day", "evening", "night")
|
||||
SLOT_LABEL = {"morning": "아침", "day": "낮", "evening": "저녁", "night": "밤"}
|
||||
NIGHT_AFTER_SUNSET = timedelta(hours=1) # 해 지고 이만큼 지나면 밤
|
||||
NIGHT_END_HOUR = 5
|
||||
EVENING_EARLIEST_HOUR = 17 # 겨울엔 일몰 2시간 전이 15시대라, 사람들이 아직 낮으로 느끼는 오후 3시가 저녁이 되지 않게
|
||||
|
||||
|
||||
def evening_start(sunset_at: datetime) -> datetime:
|
||||
"""저녁이 시작하는 시각: 일몰 2시간 전, 단 17시보다 이르지 않게."""
|
||||
sunset = sunset_at.astimezone(KST)
|
||||
return max(sunset - timedelta(hours=2), sunset.replace(hour=EVENING_EARLIEST_HOUR, minute=0, second=0, microsecond=0))
|
||||
|
||||
|
||||
def slot_of(now: datetime, sunset_at: datetime) -> str:
|
||||
"""아침 05–11 · 낮 11–일몰 2시간 전 · 저녁 일몰 2시간 전–일몰 1시간 뒤 · 밤 일몰 1시간 뒤–05. 밤은 계절 따라 18시대~21시대에 온다."""
|
||||
"""아침 05–11 · 낮 11–저녁 시작 · 저녁 일몰 2시간 전(17시보다 이르지 않게)–일몰 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 "day" if now < evening_start(sunset_at) else "evening"
|
||||
return "night"
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ from dataclasses import dataclass
|
||||
from types import SimpleNamespace
|
||||
from typing import Literal, Optional
|
||||
|
||||
from services.calc.day_slot import NIGHT_END_HOUR, SLOTS
|
||||
from services.calc.day_slot import EVENING_EARLIEST_HOUR, NIGHT_END_HOUR, SLOTS
|
||||
|
||||
Rain = Literal["dry", "wet"]
|
||||
Air = Literal["good", "normal"]
|
||||
@@ -59,11 +59,12 @@ _TEMP_MIN, _TEMP_MAX = -20, 40
|
||||
|
||||
def _slot_of_hour(h: int) -> str:
|
||||
h %= 24
|
||||
evening_from = max(_SUNSET_HOUR - 2, EVENING_EARLIEST_HOUR)
|
||||
if NIGHT_END_HOUR <= h < 11:
|
||||
return "morning"
|
||||
if 11 <= h < _SUNSET_HOUR - 2:
|
||||
if 11 <= h < evening_from:
|
||||
return "day"
|
||||
if _SUNSET_HOUR - 2 <= h < _SUNSET_HOUR + 1:
|
||||
if evening_from <= h < _SUNSET_HOUR + 1:
|
||||
return "evening"
|
||||
return "night"
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ from router.v1.index.protocol import TrendPoint
|
||||
from services.air_service import GRADE_LABEL as AIR_GRADE_LABEL
|
||||
from services.air_service import pm10_grade, pm25_grade
|
||||
from services.bot_comment import fill_bot_comments
|
||||
from services.calc.day_slot import NIGHT_AFTER_SUNSET, slot_of
|
||||
from services.calc.day_slot import NIGHT_AFTER_SUNSET, evening_start, slot_of
|
||||
from services.calc.index_calc import rank_score
|
||||
from services.calc.moon import MoonNight, nearest, night, view_line
|
||||
from services.calc.sky_score import GRADE_LABEL, sky_title
|
||||
@@ -177,7 +177,7 @@ def feed_ttl_sec(now: datetime, sunset_at: datetime) -> int:
|
||||
day = now.date()
|
||||
at = lambda d, h: datetime.combine(d, time(h), tzinfo=KST) # noqa: E731
|
||||
sunset = sunset_at.astimezone(KST)
|
||||
changes = [at(day, _FEED_DAY_START), at(day, 5), at(day, 11), sunset - timedelta(hours=2), sunset, sunset + NIGHT_AFTER_SUNSET,
|
||||
changes = [at(day, _FEED_DAY_START), at(day, 5), at(day, 11), evening_start(sunset), sunset, sunset + NIGHT_AFTER_SUNSET,
|
||||
at(day + timedelta(days=1), _FEED_DAY_START), next_vilage_available(now), latest_ultra_base(now) + timedelta(hours=1) + ULTRA_DELAY,
|
||||
latest_ncst_base(now) + timedelta(hours=1) + NCST_DELAY, now.replace(minute=0, second=0, microsecond=0) + timedelta(hours=1)]
|
||||
air = now.replace(minute=20, second=0, microsecond=0)
|
||||
|
||||
Reference in new issue
Block a user