feat: 각 순위에 중요도(상·중·하) 가중치 반영

This commit is contained in:
minaChoi committed 2026-10-08 09:19:59 +09:00
1 parent 471353212a
commit 116f644bb7
11 files changed
+207 -121

No files matched your search

+7
View File
@@ -18,6 +18,13 @@ _FALL_FLOOR = exp(-0.5)
# 편한 범위 안에서 최적값 ±이만큼은 100점 (기온 °, 습도 %p)
_TEMP_PLATEAU = 2
_HUMIDITY_PLATEAU = 5
# 각 중요도(index_definition.priority)별 순위 가중치: 1=상 2=중 3=하. 순위만 바꾸고 보이는 점수는 그대로 둔다.
PRIORITY_WEIGHT = {1: 1.0, 2: 0.85, 3: 0.7}
def rank_score(score: int, priority: int) -> float:
"""각 순위를 정하는 값 = 점수 × 중요도 가중치."""
return score * PRIORITY_WEIGHT[priority]
@dataclass(frozen=True)
+2 -1
View File
@@ -25,6 +25,7 @@ from router.v1.feed.protocol import (
)
from services.air_service import GRADE_LABEL as AIR_GRADE_LABEL
from services.air_service import pm10_grade, pm25_grade
from services.calc.index_calc import rank_score
from services.calc.moon import illumination, nearest, phase_name
from services.calc.sky_score import GRADE_LABEL, SITUATION_LINE
from services.calc.sun import sun_times
@@ -658,7 +659,7 @@ class FeedService:
best = None
for i in c.board.items if c.board else []:
s = next((x for x in i.trend if x.score_date == tomorrow), None)
if s is not None and (best is None or s.score > best[1].score):
if s is not None and (best is None or rank_score(s.score, i.definition.priority) > rank_score(best[1].score, best[0].definition.priority)):
best = (i, s)
if best is not None:
rows.append(Row(label="내일 1위 각", value=f"{best[0].definition.name} {best[1].score}점"))
+2 -2
View File
@@ -16,7 +16,7 @@ from crud.sky_crud import SkyCRUD
from crud.weather_crud import WeatherCRUD
from crud.week_crud import WeekCRUD
from services.air_service import GRADE_LABEL, AirService
from services.calc.index_calc import AXES, Context, DayForecast, Hour, Result, estimate, evaluate
from services.calc.index_calc import AXES, Context, DayForecast, Hour, Result, estimate, evaluate, rank_score
from services.calc.moon import illumination
from services.calc.sun import sun_times
from services.external.open_meteo import is_dark_slot
@@ -210,7 +210,7 @@ class IndexService:
if ErrorType.DB_ERROR in (err, err2):
return ErrorType.DB_ERROR, None
by_key = {(x.index_id, x.score_date): x for x in scores}
ranked = sorted((d for d in defs if (d.index_id, today) in by_key), key=lambda d: by_key[(d.index_id, today)].score, reverse=True)
ranked = sorted((d for d in defs if (d.index_id, today) in by_key), key=lambda d: rank_score(by_key[(d.index_id, today)].score, d.priority), reverse=True)
items = [
IndexItem(
definition=d, score=by_key[(d.index_id, today)], rank=i + 1,
+3 -1
View File
@@ -21,6 +21,7 @@ from crud.index_crud import IndexCRUD
from crud.region_crud import RegionCRUD
from crud.weather_crud import WeatherCRUD
from crud.week_crud import WeekCRUD
from services.calc.index_calc import rank_score
from services.external.culture_api import IMAGE_CREDIT as CULTURE_CREDIT
from services.external.culture_api import SOURCE_PREFIX as CULTURE_PREFIX
from services.external.culture_api import CONCERT, EXHIBITION, fetch_exhibitions, parse_exhibitions
@@ -227,11 +228,12 @@ class WeekService:
if err is not ErrorType.SUCCESS:
return err, []
names = {d.index_id: d.name for d in defs or []}
priority = {d.index_id: d.priority for d in defs or []}
plans = []
for d in daily:
rows = [r for r in hourly or [] if r.forecast_at.astimezone(KST).date() == d.forecast_date]
rain_hours = _rain_hours(rows)
top = sorted((x for x in scores or [] if x.score_date == d.forecast_date and not x.estimated), key=lambda x: x.score, reverse=True)[:2]
top = sorted((x for x in scores or [] if x.score_date == d.forecast_date and not x.estimated), key=lambda x: rank_score(x.score, priority.get(x.index_id, 2)), reverse=True)[:2]
holiday = (holidays or {}).get(d.forecast_date)
weekday = _WEEKDAY_KO[d.forecast_date.weekday()]
word = _weather_word(d, rain_hours)