fix: 저녁 시작을 17시보다 이르지 않게 — 겨울에 오후 3시가 저녁이던 것
This commit is contained in:
1 parent
639ca83553
commit
96e40d00c8
7 files changed
+53
-20
No files matched your search
@@ -4,7 +4,7 @@ from types import SimpleNamespace
|
||||
from common.database.model.models import WeatherHourly
|
||||
from common.enums import RainType, Sky
|
||||
from common.utils.kma_time import KST, kst_midnight
|
||||
from services.calc.day_slot import slot_hours
|
||||
from services.calc.day_slot import slot_hours, slot_of
|
||||
from services.calc.index_calc import Context
|
||||
from services.index_service import EARLY, WEATHER_SCORE_DEF, _shown_parts, current_slot, slot_results
|
||||
from services.weather_service import RainHour, with_ultra_rain
|
||||
@@ -36,16 +36,34 @@ def _defn(windows):
|
||||
|
||||
|
||||
def test_slot_hours_split_by_sunset():
|
||||
"""일몰 18:00: 일몰 2시간 전은 16시지만 저녁은 17시부터, 밤은 일몰 1시간 뒤 19시부터."""
|
||||
hours = slot_hours(DAY, SUNSET)
|
||||
assert hours["morning"] == set(range(5, 11))
|
||||
assert hours["day"] == set(range(11, 16))
|
||||
assert hours["evening"] == {16, 17, 18}
|
||||
assert hours["day"] == set(range(11, 17))
|
||||
assert hours["evening"] == {17, 18}
|
||||
assert hours["night"] == set(range(19, 29))
|
||||
|
||||
|
||||
def test_evening_starts_no_earlier_than_17():
|
||||
"""겨울(일몰 17:14)엔 일몰 2시간 전이 15시대라 오후 3시가 저녁이던 것: 저녁은 17시보다 이르게 시작하지 않는다. 밤(일몰 1시간 뒤~)은 그대로."""
|
||||
winter = datetime(2026, 12, 21, 17, 14, tzinfo=KST)
|
||||
at = lambda h, m=0: datetime(2026, 12, 21, h, m, tzinfo=KST) # noqa: E731
|
||||
assert [slot_of(at(h, m), winter) for h, m in ((16, 59), (17, 0), (18, 13), (18, 14))] == ["day", "evening", "evening", "night"]
|
||||
hours = slot_hours(date(2026, 12, 21), winter)
|
||||
assert hours["day"] == set(range(11, 17))
|
||||
assert hours["evening"] == {17}
|
||||
|
||||
|
||||
def test_evening_follows_sunset_when_it_sets_late():
|
||||
"""일몰이 19시 넘으면 지금처럼 일몰 2시간 전부터 저녁."""
|
||||
summer = datetime(2026, 6, 21, 19, 57, tzinfo=KST)
|
||||
assert slot_of(datetime(2026, 6, 21, 17, 56, tzinfo=KST), summer) == "day"
|
||||
assert slot_of(datetime(2026, 6, 21, 17, 57, tzinfo=KST), summer) == "evening"
|
||||
|
||||
|
||||
def test_current_slot_before_5_is_previous_night():
|
||||
assert current_slot(datetime(2026, 10, 8, 2, 0, tzinfo=KST), SUNSET) == EARLY
|
||||
assert current_slot(datetime(2026, 10, 8, 16, 30, tzinfo=KST), SUNSET) == "evening"
|
||||
assert current_slot(datetime(2026, 10, 8, 17, 30, tzinfo=KST), SUNSET) == "evening"
|
||||
|
||||
|
||||
def test_gak_scores_every_slot_and_time_match_is_binary():
|
||||
@@ -213,10 +231,10 @@ def test_umbrella_now_follows_the_slot_the_screen_shows_even_at_a_slot_boundary(
|
||||
|
||||
|
||||
def test_umbrella_other_slots_have_no_raining_now_bonus():
|
||||
"""13:30 에 낮 구간이 지금. 저녁 구간(16시~)은 16시에만 비가 와도 지금 비 보너스 없이 평균 × 100 → 약 12점."""
|
||||
"""13:30 에 낮 구간이 지금. 저녁 구간(17시~)은 17시에만 비가 와도 지금 비 보너스 없이 평균 × 100 → 17~23시 7시간 중 1시간, 약 14점."""
|
||||
now = datetime(2026, 10, 8, 13, 30, tzinfo=KST)
|
||||
parts = slot_results(_umbrella_defn(), DAY, REGION, _rain_at({16}), {}, CTX, SUNSET, now)
|
||||
assert 10 <= parts["evening"].score <= 13
|
||||
parts = slot_results(_umbrella_defn(), DAY, REGION, _rain_at({17}), {}, CTX, SUNSET, now)
|
||||
assert 13 <= parts["evening"].score <= 15
|
||||
|
||||
|
||||
def test_umbrella_rest_of_day_stops_at_midnight():
|
||||
|
||||
@@ -157,7 +157,7 @@ def test_slot_follows_sunset():
|
||||
|
||||
sunset = datetime(2026, 10, 2, 18, 10, tzinfo=KST)
|
||||
at = lambda h, m=0: datetime(2026, 10, 2, h, m, tzinfo=KST) # noqa: E731
|
||||
assert [slot_of(at(h, m), sunset) for h, m in ((4, 59), (5, 0), (11, 0), (16, 9), (16, 10), (19, 9), (19, 10), (23, 0))] == [
|
||||
assert [slot_of(at(h, m), sunset) for h, m in ((4, 59), (5, 0), (11, 0), (16, 59), (17, 0), (19, 9), (19, 10), (23, 0))] == [
|
||||
"night", "morning", "day", "day", "evening", "evening", "night", "night"]
|
||||
summer = datetime(2026, 6, 21, 19, 57, tzinfo=KST)
|
||||
assert slot_of(datetime(2026, 6, 21, 20, 30, tzinfo=KST), summer) == "evening"
|
||||
|
||||
@@ -114,10 +114,10 @@ def test_running_muggy_morning_does_not_exceed_original_weather_score():
|
||||
|
||||
|
||||
def test_now_slot_summary_shows_current_hour_not_middle_of_rest():
|
||||
"""오후 4시 10분이면 지금 구간 줄은 남은 16~18시의 가운데(5시)가 아니라 지금(4시) 날씨로."""
|
||||
"""오후 5시 10분이면 지금 구간 줄은 남은 17~19시의 가운데(6시)가 아니라 지금(5시) 날씨로."""
|
||||
start = kst_midnight(SAT)
|
||||
hourly = _hourly(SAT) | _hourly(SAT + timedelta(days=1))
|
||||
sunset = start + timedelta(hours=17, minutes=30)
|
||||
results = slot_results(RUNNING, SAT, REGION, hourly, {}, CTX, sunset, now=start + timedelta(hours=16, minutes=10))
|
||||
assert results["evening"].summary.startswith("오후 4시"), results["evening"].summary
|
||||
assert results["night"].summary.startswith("오후 4시") is False
|
||||
sunset = start + timedelta(hours=19)
|
||||
results = slot_results(RUNNING, SAT, REGION, hourly, {}, CTX, sunset, now=start + timedelta(hours=17, minutes=10))
|
||||
assert results["evening"].summary.startswith("오후 5시"), results["evening"].summary
|
||||
assert results["night"].summary.startswith("오후 5시") is False
|
||||
@@ -113,6 +113,13 @@ def test_preset_copies_rules_that_fit_and_drops_the_rest():
|
||||
assert p == {"slots": ["evening"], "rain": "dry"}
|
||||
|
||||
|
||||
def test_preset_evening_starts_at_17_like_the_feed():
|
||||
"""피드와 같은 규칙: 저녁은 17시보다 이르게 시작하지 않으니 16시대는 낮."""
|
||||
rules = {"rain": {"dir": "dry"}, "temp": {"type": "range", "lo": 18, "hi": 24}}
|
||||
assert preset(_defn(rules, [{"from": 16, "to": 17}]))["slots"] == ["day"]
|
||||
assert preset(_defn(rules, [{"from": 17, "to": 19}]))["slots"] == ["evening"]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_presets_cover_every_gak_with_valid_rules():
|
||||
async with client() as c:
|
||||
|
||||
Reference in new issue
Block a user