fix: 각 점수에 중요도 배율을 반영해 화면 점수와 순위를 일치시킴

This commit is contained in:
skkim committed 2026-10-23 09:14:52 +09:00
1 parent 621a0cf90d
commit d5f8b148b4
12 files changed
+68 -33

No files matched your search

+17 -7
View File
@@ -79,8 +79,10 @@ async def test_index_list_ranks_every_gak_with_today_tomorrow_weekend_trend(fake
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 and i["in_season"]]
assert weighted == sorted(weighted, reverse=True)
scores = [i["score"] for i in body["items"] if i["active"] is group and i["in_season"]]
assert scores == sorted(scores, reverse=True)
order = [rank_score(i["score"], priority[i["code"]]) for i in body["items"] if i["active"] is group and i["in_season"]]
assert order == sorted(order, reverse=True)
today = now_kst().date()
for i in body["items"]:
assert [t["label"] for t in i["trend"]] == [slot_label(d, today) for d in slot_days(today)]
@@ -164,7 +166,7 @@ async def test_board_puts_out_of_season_gak_last_without_rank_or_badge(monkeypat
@pytest.mark.anyio
async def test_board_ranks_by_score_times_priority_weight(monkeypatch):
async def test_board_displays_and_ranks_by_priority_adjusted_score(monkeypatch):
today = now_kst().date()
defs = [
SimpleNamespace(index_id=1, code="low", priority=3),
@@ -172,17 +174,25 @@ async def test_board_ranks_by_score_times_priority_weight(monkeypatch):
SimpleNamespace(index_id=3, code="high", priority=1),
]
scores = [_board_score(x, today, v) for x, v in ((1, 90), (2, 80), (3, 70))]
scores += [_board_score(x, today + timedelta(days=1), v) for x, v in ((1, 90), (2, 80), (3, 70))]
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, {now_kst().date(): _WEATHER_50})))
err, board = await service.board(REGION)
assert err is ErrorType.SUCCESS
# 하 90점(63) < 중 80점(68) < 상 70점(70). 보이는 점수는 그대로
assert [(i.definition.code, i.score.score, i.rank) for i in board.items] == [("high", 70, 1), ("mid", 80, 2), ("low", 90, 3)]
assert [(i.definition.code, i.score.score, i.rank) for i in board.items] == [("high", 70, 1), ("mid", 68, 2), ("low", 63, 3)]
for item in board.items:
assert item.trend[0].score == item.score.score
assert item.trend[1].score == item.score.score
assert all(value == item.score.score for value in item.slots.values())
# 응답용 보정은 DB에서 읽은 원점수를 바꾸지 않으며, 같은 요청을 다시 해도 중복 적용하지 않는다.
assert [row.score for row in scores] == [90, 80, 70, 90, 80, 70]
_, again = await service.board(REGION)
assert [i.score.score for i in again.items] == [70, 68, 63]
@pytest.mark.anyio
async def test_board_ranks_each_slot_with_priority_weight(monkeypatch):
async def test_board_ranks_each_slot_by_displayed_score(monkeypatch):
today = now_kst().date()
defs = [SimpleNamespace(index_id=1, code="low", priority=3), SimpleNamespace(index_id=2, code="high", priority=1)]
every = ("morning", "day", "evening", "night", "early")
@@ -195,7 +205,7 @@ async def test_board_ranks_each_slot_with_priority_weight(monkeypatch):
monkeypatch.setattr("services.index_service._with_slot", lambda row, data: SimpleNamespace(score=data["score"]))
_, board = await service.board(REGION)
ranks = {i.definition.code: i.slot_ranks for i in board.items}
# 아침: 하 90(63) > 상 20(20). 낮·밤: 상 70(70) > 하 90(63).
# 하 90점은 표시 63점, 상 70점은 표시 70점으로 순위와 화면 숫자가 일치한다.
assert ranks["low"]["morning"] == 1 and ranks["high"]["morning"] == 2
assert ranks["high"]["day"] == 1 and ranks["low"]["day"] == 2
assert ranks["high"]["night"] == 1 and ranks["low"]["night"] == 2