feat: 계절 각 — 각마다 제철 달(months), 제철 각에 지금 계절 표시·철 지난 각은 순위 밖 맨 끝, 새 각 12개(꽃구경·이불빨래·빙수·실내건조·한강밤바람·단풍·억새·군고구마·해돋이·눈사람·붕어빵·귤까먹기), 해 뜰 무렵 시간대·일출 점수·눈 조건

This commit is contained in:
minaChoi committed 2026-10-12 17:20:00 +09:00
1 parent 43e1925d70
commit 5c05824ce0
14 files changed
+1130 -66

No files matched your search

+38 -7
View File
@@ -15,7 +15,7 @@ from crud.region_crud import RegionCRUD
from crud.weather_crud import WeatherCRUD
from router.router import app
from services.calc.index_calc import rank_score
from services.index_service import IndexService, _nearest_slot_end_hour, _slot_end_hour, slot_days, slot_label, windows_for
from services.index_service import IndexService, _nearest_slot_end_hour, _slot_end_hour, season_of, slot_days, slot_label, windows_for
REGION = "1141000000"
@@ -54,17 +54,19 @@ def fakes(monkeypatch):
@pytest.mark.anyio
async def test_index_list_ranks_all_34_with_today_tomorrow_weekend_trend(fakes):
async def test_index_list_ranks_every_gak_with_today_tomorrow_weekend_trend(fakes):
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
body = (await client.get("/v1/index/list", params={"region": REGION})).json()
assert body["result"]["success"] is True
assert len(body["items"]) == 34 and len(body["top3"]) == 3
assert len(body["items"]) == len(_seed()) and len(body["top3"]) == 3
priority = {d["code"]: d["priority"] for d in _seed()}
# 지금 구간에 해당하는 각이 먼저(순위), 해당 없는 각은 그 뒤. 각 묶음 안에서는 점수 × 중요도 순
# 지금 구간에 해당하는 각이 먼저(순위), 해당 없는 각은 그 뒤, 제철 아닌 각은 맨 끝. 앞 두 묶음 안에서는 점수 × 중요도 순
actives = [i["active"] for i in body["items"]]
assert actives == sorted(actives, reverse=True) and all(i["active"] for i in body["top3"])
seasons = [i["in_season"] for i in body["items"]]
assert seasons == sorted(seasons, reverse=True) and all(i["active"] is False for i in body["items"] if not i["in_season"])
for group in (True, False):
weighted = [rank_score(i["score"], priority[i["code"]]) for i in body["items"] if i["active"] is group]
weighted = [rank_score(i["score"], priority[i["code"]]) for i in body["items"] if i["active"] is group and i["in_season"]]
assert weighted == sorted(weighted, reverse=True)
today = now_kst().date()
for i in body["items"]:
@@ -75,10 +77,12 @@ async def test_index_list_ranks_all_34_with_today_tomorrow_weekend_trend(fakes):
@pytest.mark.anyio
async def test_index_list_filters_core(fakes):
async def test_index_list_filters_core_to_gak_in_season_now(fakes):
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
body = (await client.get("/v1/index/list", params={"region": REGION, "core": True})).json()
assert {i["code"] for i in body["items"]} == {"picnic", "hiking", "camping", "stars"}
month = now_kst().month
assert {i["code"] for i in body["items"]} == {d["code"] for d in _seed() if month in d["months"]}
assert all(i["season"] == season_of(month) for i in body["items"])
@pytest.mark.anyio
@@ -119,6 +123,33 @@ def test_every_index_has_priority():
assert all(d["priority"] in (1, 2, 3) for d in _seed())
def test_every_index_has_valid_months_and_weights():
for d in _seed():
assert isinstance(d["months"], list) and all(1 <= m <= 12 for m in d["months"]), d["code"]
assert sum(d[f"weight_{a}"] for a in ("temp", "rain", "wind", "humidity", "air", "uv", "sun", "view", "time")) == 100, d["code"]
@pytest.mark.anyio
async def test_board_puts_out_of_season_gak_last_without_rank_or_badge(monkeypatch):
today = now_kst().date()
other = [m for m in range(1, 13) if m != today.month]
defs = [
SimpleNamespace(index_id=1, code="always", priority=2, months=[], sort_order=1),
SimpleNamespace(index_id=2, code="now", priority=2, months=[today.month], sort_order=2),
SimpleNamespace(index_id=3, code="off", priority=1, months=other[:3], sort_order=3),
]
scores = [SimpleNamespace(index_id=x, score_date=today, score=v, slots={}) for x, v in ((1, 50), (2, 60), (3, 99))]
crud = SimpleNamespace(definitions=lambda s: _async(defs), scores=lambda s, *a: _async(scores))
service = IndexService(RegionCRUD(), crud, None, None, None, None, None, None)
monkeypatch.setattr(service, "ensure", lambda *a: _async((ErrorType.SUCCESS, {"morning": 50, "day": 50, "evening": 50, "night": 50, "early": 50})))
_, board = await service.board(REGION)
view = [(i.definition.code, i.active, i.in_season, i.season) for i in board.items]
# 점수가 가장 높아도 제철이 아니면 순위 밖 맨 끝. 계절 표시는 제철 달이 정해진 각에만
assert view == [("now", True, True, season_of(today.month)), ("always", True, True, None), ("off", False, False, None)]
assert [i.definition.code for i in board.ranked] == ["now", "always"]
assert all(not i.slot_ranks for i in board.items if not i.in_season)
@pytest.mark.anyio
async def test_board_ranks_by_score_times_priority_weight(monkeypatch):
today = now_kst().date()