fix: 각 점수에 중요도 배율을 반영해 화면 점수와 순위를 일치시킴
This commit is contained in:
1 parent
621a0cf90d
commit
d5f8b148b4
12 files changed
+68
-33
No files matched your search
@@ -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
|
||||
|
||||
@@ -9,7 +9,7 @@ import pytest
|
||||
from common.enums import RainType, Sky
|
||||
from services.calc.index_calc import (
|
||||
OUTING_HOURS, Context, DayForecast, Hour, air_score, axis_label, estimate, evaluate, hour_temp, outing, outing_estimate, rain_score, sun_score, temp_score,
|
||||
uv_score, view_score, zero_rules_text,
|
||||
priority_score, rank_score, uv_score, view_score, zero_rules_text,
|
||||
)
|
||||
from services.calc.moon import illumination
|
||||
|
||||
@@ -38,6 +38,20 @@ def test_perfect_evening_scores_100():
|
||||
assert r.notes["temp"] == "체감 21°, 편한 범위 18~24° 안"
|
||||
|
||||
|
||||
def test_rank_and_display_share_priority_adjusted_screenshot_scores():
|
||||
items = [(83, 1), (82, 1), (80, 1), (91, 2), (77, 1), (77, 1), (76, 1), (89, 2), (87, 2)]
|
||||
shown = [(priority_score(score, priority), priority) for score, priority in items]
|
||||
ranked = sorted(shown, key=lambda item: rank_score(*item), reverse=True)
|
||||
assert [score for score, _ in ranked] == [83, 82, 80, 77, 77, 77, 76, 76, 74]
|
||||
assert priority_score(91, 2) == 77
|
||||
assert priority_score(89, 2) == 76
|
||||
|
||||
|
||||
def test_rank_uses_priority_only_to_break_ties():
|
||||
items = [(80, 3), (80, 1), (81, 3), (80, 2)]
|
||||
assert sorted(items, key=lambda item: rank_score(*item), reverse=True) == [(81, 3), (80, 1), (80, 2), (80, 3)]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("weight", [5, 10, 20])
|
||||
def test_time_match_adds_only_its_weight_without_extra_penalty(weight):
|
||||
rules = _defn().factor_rules | {"time": {"type": "fixed", "value": 55}}
|
||||
|
||||
Reference in new issue
Block a user