From 939edeedb6b722903d91c2e6c18c716a19f56c43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=84=B1=EA=B2=BD?= Date: Fri, 13 Nov 2026 13:59:08 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=A3=BC=EB=A7=90=20=EC=A0=84=EA=B5=AD?= =?UTF-8?q?=20=EB=82=A0=EC=94=A8=20=EC=88=9C=EC=9C=84=EA=B0=80=20=EC=A0=84?= =?UTF-8?q?=EA=B5=AD=20=EB=B9=84=EC=9D=B8=20=EB=82=A0=20=EC=A0=84=EB=B6=80?= =?UTF-8?q?=2047=EC=A0=90=EC=9D=B4=EB=8D=98=20=EA=B2=83=20=E2=80=94=20?= =?UTF-8?q?=EB=82=98=EB=93=A4=EC=9D=B4=20=EC=A0=90=EC=88=98=EC=9D=98=20?= =?UTF-8?q?=EB=B9=84=20=EC=83=81=ED=95=9C(=EC=B5=9C=EB=8C=80=2030=EC=A0=90?= =?UTF-8?q?)=EC=9D=84=20=EC=97=86=EC=95=A0=20=EB=B9=84=20=EC=98=A4?= =?UTF-8?q?=EB=8A=94=20=EB=82=A0=EB=8F=84=20=EA=B8=B0=EC=98=A8=C2=B7?= =?UTF-8?q?=ED=95=98=EB=8A=98=C2=B7=EB=B0=94=EB=9E=8C=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=9D=BC=20=EC=A0=90=EC=88=98=EA=B0=80=20=EA=B0=88=EB=A6=BC.?= =?UTF-8?q?=20=EB=B0=94=EA=BE=B8=EA=B8=B0=20=ED=91=9C=20=EB=8B=A4=EC=8B=9C?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1,=20=EC=88=9C=EC=9C=84=20=EC=BA=90?= =?UTF-8?q?=EC=8B=9C=20=ED=82=A4=20v3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/services/calc/index_calc.py | 8 +--- backend/services/calc/outing_score_table.json | 48 +++++++++---------- backend/services/weekend_rank.py | 2 +- backend/tests/test_index_calc.py | 20 ++++++-- backend/tests/test_outing_score_table.py | 2 +- docs/서비스_동작_안내.md | 2 +- docs/점수_계산식.md | 6 +-- 7 files changed, 46 insertions(+), 42 deletions(-) diff --git a/backend/services/calc/index_calc.py b/backend/services/calc/index_calc.py index 9e3a636..84bd8e6 100644 --- a/backend/services/calc/index_calc.py +++ b/backend/services/calc/index_calc.py @@ -433,7 +433,6 @@ _OUTING_WEIGHTS = {"temp": 35, "rain": 40, "sky": 15, "wind": 10} # 만점 조건을 엄격하게: 기온은 최적 21° ±0.5°, 바람은 초속 1m 이하(ok/2)여야 100점 — 같은 예보를 받는 여러 지역이 한꺼번에 100점이 되던 것을 줄인다 _OUTING_RULES = {"temp": {"type": "range", "lo": 17, "hi": 24, "best": 21, "plateau": 0.5}, "rain": {"dir": "dry"}, "wind": {"type": "calm", "ok": 2, "limit": 12}} _OUTING_SKY = {Sky.CLEAR: 100, Sky.PARTLY: 80, Sky.CLOUDY: 50} -_OUTING_RAIN_PROB, _OUTING_RAIN_CAP = 60, 30 @dataclass @@ -442,7 +441,6 @@ class Outing: factors: dict[str, int] notes: dict[str, str] reason: str # 순위 옆 한 줄 근거 ("비 10% · 체감 21° · 맑음") - capped: bool # 비 때문에 최대 30점으로 묶였는지 estimated: bool = False @@ -451,12 +449,8 @@ def _outing(scored: dict[str, tuple[int, str]], prob: int, raining: bool, temp_w notes = {a: n for a, (_, n) in scored.items()} worst = min(factors.values()) score = round(sum(factors[a] * w for a, w in _OUTING_WEIGHTS.items()) / 100 * (1 - _WORST_PULL + _WORST_PULL * worst / 100)) - capped = raining or prob >= _OUTING_RAIN_PROB - if capped: - score = min(score, _OUTING_RAIN_CAP) - notes["rain"] += f", 비 확률 {_OUTING_RAIN_PROB}% 이상이거나 비 소식이면 최대 {_OUTING_RAIN_CAP}점" reason = " · ".join(["비 소식" if raining else f"비 {prob}%", temp_word, _SKY_WORD[sky]]) - return Outing(score=score, factors=factors, notes=notes, reason=reason, capped=capped, estimated=estimated) + return Outing(score=score, factors=factors, notes=notes, reason=reason, estimated=estimated) def outing(hours: list[Hour]) -> Optional[Outing]: diff --git a/backend/services/calc/outing_score_table.json b/backend/services/calc/outing_score_table.json index a6efa74..9885602 100644 --- a/backend/services/calc/outing_score_table.json +++ b/backend/services/calc/outing_score_table.json @@ -1,8 +1,8 @@ { "about": "나들이 점수 바꾸기 표: 원래 점수 0~100 → 표시 점수. 평균 60·표준편차 15. scripts/gen_outing_score_table.py 가 만든다", "period": [ - "2025-10-22", - "2026-10-21" + "2025-11-12", + "2026-11-11" ], "regions": 32, "samples": 11680, @@ -20,14 +20,13 @@ 13, 17, 22, - 25, - 28, - 30, - 32, - 34, + 26, + 29, + 31, + 33, + 35, 36, 37, - 37, 38, 38, 39, @@ -37,23 +36,24 @@ 41, 42, 42, + 43, + 43, + 44, + 45, + 45, + 46, + 46, 47, - 50, - 50, - 50, - 50, - 50, - 50, - 50, - 50, + 48, + 48, + 49, + 49, + 49, 50, 50, 51, 51, - 51, - 51, - 52, - 54, + 53, 57, 61, 62, @@ -69,7 +69,6 @@ 64, 64, 64, - 64, 65, 65, 65, @@ -77,7 +76,6 @@ 66, 66, 66, - 66, 67, 67, 67, @@ -86,16 +84,18 @@ 68, 69, 69, + 69, 70, 70, 71, 72, 73, 74, + 74, 75, - 76, + 77, 78, - 79, + 80, 81, 83, 85, diff --git a/backend/services/weekend_rank.py b/backend/services/weekend_rank.py index 87f25ed..b19863e 100644 --- a/backend/services/weekend_rank.py +++ b/backend/services/weekend_rank.py @@ -30,7 +30,7 @@ from services.week_service import _icon # 주말 전국 날씨 순위·당일치기 추천. 대표 지역(노을 순위 30곳)과 당일치기 후보 도시의 토·일 나들이 점수를 # 워커가 하루 두 번(06:40·18:40) 미리 계산해 Redis 에 둔다. 없으면 순위 API 가 그 자리에서 계산한다. _SEED = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "seed", "trip_city.csv") -_KEY = "weekend_rank:v2:{:%Y%m%d}" # v2: 점수를 바꾸기 표로 보정한 값 (옛 점수 캐시를 쓰지 않게 키를 바꿨다) +_KEY = "weekend_rank:v3:{:%Y%m%d}" # v3: 비 상한(최대 30점)을 없앤 점수 (옛 점수 캐시를 쓰지 않게 키를 바꿨다) _TTL = 13 * 3600 _PARALLEL = 4 # 기상청 동시 호출 수 _WAIT_STEPS, _WAIT_SEC = 60, 0.5 diff --git a/backend/tests/test_index_calc.py b/backend/tests/test_index_calc.py index 549fb6c..0300e75 100644 --- a/backend/tests/test_index_calc.py +++ b/backend/tests/test_index_calc.py @@ -252,10 +252,20 @@ def test_outing_cloudy_and_hot_days_lose_points(): assert "흐림" in cloudy.reason -def test_outing_rain_caps_score(): - r = outing(_day(prob=70)) - assert r.score <= 30 and r.capped - assert outing([_h(10, prob=30, rain=RainType.RAIN)] + _day()[1:]).score <= 30 +def test_outing_rain_lowers_score_without_a_cap(): + """비가 오면 비 점수와 가장 낮은 요소 때문에 점수가 내려가지만, 따로 상한으로 묶지는 않는다.""" + clear = outing(_day()) + likely = outing(_day(prob=70)) + raining = outing([_h(10, prob=30, rain=RainType.RAIN)] + _day()[1:]) + assert raining.score < likely.score < clear.score + assert likely.score > 30 and raining.score > 30 + + +def test_outing_rainy_days_keep_their_differences(): + """전국이 비인 날에도 기온·하늘에 따라 점수가 갈린다 (예전엔 모두 상한 30점에 걸려 같은 점수였다).""" + mild = outing(_day(feels=16.0, sky=Sky.CLOUDY, rain=RainType.RAIN)) + chilly = outing(_day(feels=14.0, sky=Sky.CLOUDY, rain=RainType.RAIN)) + assert chilly.score < mild.score def test_outing_needs_all_hours(): @@ -266,7 +276,7 @@ def test_outing_estimate_from_mid_forecast(): r = outing_estimate(_fc(lo=12, hi=22, am=10, pm=20)) assert r.estimated is True and r.factors["wind"] == 70 assert r.reason.startswith("비 20% · 낮 ") - assert outing_estimate(_fc(pm=60)).score <= 30 + assert 30 < outing_estimate(_fc(pm=60)).score < outing_estimate(_fc(pm=0)).score assert outing_estimate(_fc(lo=None, hi=None)) is None diff --git a/backend/tests/test_outing_score_table.py b/backend/tests/test_outing_score_table.py index 0749b7d..b15a685 100644 --- a/backend/tests/test_outing_score_table.py +++ b/backend/tests/test_outing_score_table.py @@ -25,7 +25,7 @@ def test_calibrated_outing_reads_the_table(): def test_day_score_uses_calibrated_value_for_hourly_and_estimated_results(): for estimated in (False, True): - r = Outing(score=80, factors={}, notes={}, reason="비 0% · 체감 21° · 맑음", capped=False, estimated=estimated) + r = Outing(score=80, factors={}, notes={}, reason="비 0% · 체감 21° · 맑음", estimated=estimated) assert outing_day_score(r) == OUTING_SCORE_TABLE[80] diff --git a/docs/서비스_동작_안내.md b/docs/서비스_동작_안내.md index 18ded5d..f2eb092 100644 --- a/docs/서비스_동작_안내.md +++ b/docs/서비스_동작_안내.md @@ -593,7 +593,7 @@ - **켜지는 조건**: 후보 도시(`backend/seed/trip_city.csv`, 지금 강릉·속초·춘천·가평·양평·인천·대전·전주·태안·단양 10곳) 중 내 지역에서 직선 20~200km 안인 곳의 이번 주말(토·일, 오늘 이후) 나들이 점수 1위가 50점 이상일 때. 주말 플랜 바로 뒤. - **슬라이드**: 첫 장 "당일치기 · 토요일 10.10", 큰 줄 "토요일엔 강릉, 나들이 86점", 표(거리 "여기서 약 160km", 날씨 근거 "비 10% · 체감 21° · 맑음" — 중기예보로 어림하면 "예상 날씨", 기온, 볼거리). 뒤로 그날 그 도시 30km 안 행사 최대 2장(사진 + 장소·기간). - **본문**: 2위 도시: "다음은 춘천, 일요일 75점이에요." 후보가 하나뿐이면 "아침 일찍 출발하면 하루가 넉넉해요." -- **데이터**: 나들이 날씨 점수(`index_calc.py` `outing`·`outing_estimate`: 낮 10~17시 비 40%·기온 35%(체감 17~24°, 21° 최적)·하늘 15%·바람 10%, 비 확률 60% 이상이거나 비 소식이면 최대 30점). 단기예보 안이면 시간별, 밖이면 중기예보. 워커가 06:40·18:40에 계산해 Redis(`weekend_rank:토요일`)에 둔 값만 쓰고, 없으면 카드를 끄고 피드를 60초만 캐시. 행사는 `WeekService.events`를 그 도시 기준으로 (`weekend_rank.py`, `feed_service.py` `_day_trip`). +- **데이터**: 나들이 날씨 점수(`index_calc.py` `outing`·`outing_estimate`: 낮 10~17시 비 40%·기온 35%(체감 17~24°, 21° 최적)·하늘 15%·바람 10%, 비가 와도 상한 없이 계산한 점수 그대로). 단기예보 안이면 시간별, 밖이면 중기예보. 워커가 06:40·18:40에 계산해 Redis(`weekend_rank:토요일`)에 둔 값만 쓰고, 없으면 카드를 끄고 피드를 60초만 캐시. 행사는 `WeekService.events`를 그 도시 기준으로 (`weekend_rank.py`, `feed_service.py` `_day_trip`). 피드에 같이 나오지만 포스트가 아닌 것: 히어로(지금 기온·체감·불쾌지수·2시간 비·1위 각), 오늘의 각 줄(전체 순위), 띠 3종(행사 4개, TOP5, 계절 글 목록). diff --git a/docs/점수_계산식.md b/docs/점수_계산식.md index 6126368..9071b14 100644 --- a/docs/점수_계산식.md +++ b/docs/점수_계산식.md @@ -106,11 +106,11 @@ | 바람 | 10% | 초속 1m 이하 100 → 2m에서 85 → 12m에서 0 | - 1처럼 가장 낮은 요소로 깎습니다. -- 비 소식이 있거나 비 확률 60% 이상이면 **최대 30점**. +- 비가 와도 따로 상한으로 묶지 않습니다. 비 소식이 있으면 비 점수가 0점이라 원래 점수는 0~45점 안에서 기온·하늘·바람에 따라 갈립니다. (예전엔 최대 30점으로 묶어, 전국이 비인 날 모든 지역이 같은 점수가 됐습니다.) - 중기예보뿐인 날은 기온을 어림하고 바람은 70점입니다. - 위 계산으로 나온 점수가 **원래 점수**이고, 화면에는 지금 날씨 점수(3절)와 같은 방식으로 **표시 점수로 바꿔** 보여 줍니다. 1년 치 원래 점수 분포의 순위를 평균 60·표준편차 15 정규분포의 같은 위치 점수로 바꾸는 것으로, 순서는 그대로입니다. 구간은 낮 하나라 표도 하나입니다. 원래 점수 50은 62점이고, 90점 이상은 원래 점수 94 이상에서만 나옵니다. 위쪽 끝은 3절처럼 직선으로 이어(`straighten_top`) **100점은 원래 점수 100(완벽한 날)일 때만** 나오고, 그 아래는 99→98, 97→95, 96→93, 95→92, 94→90처럼 서로 다른 점수가 됩니다. 맑고 알맞은 날이 100점으로 몰려 동점이 되던 것을 막습니다. - 바꾸기 표: `backend/services/calc/outing_score_table.json` (`calibrated_outing`, `weekend_rank.py`). 만드는 법: `cd backend && python scripts/gen_outing_score_table.py`. 나들이 점수 규칙이 바뀌면 다시 만들어야 합니다. 표는 Open-Meteo 과거 예보(32개 지역, 364일)로 만들어 기상청 예보와 분포가 조금 다를 수 있습니다. 중기예보로 어림한 예상 점수에도 같은 표를 씁니다. -- 순위 캐시(`weekend_rank:v2:<토요일 날짜>`)는 표시 점수를 담습니다. 바꾸기 표를 적용하면서 키를 올려 옛 점수 캐시를 쓰지 않게 했습니다. +- 순위 캐시(`weekend_rank:v3:<토요일 날짜>`)는 표시 점수를 담습니다. 비 상한을 없애면서 키를 올려 옛 점수 캐시를 쓰지 않게 했습니다. - 전국 순위: 노을 순위 대표 30곳을 점수순으로 정렬합니다. - 당일치기: 내 지역에서 직선 20~200km 안 후보 도시 중 토·일 중 더 좋은 날 점수가 가장 높은 곳입니다. 동점이면 비 확률이 낮은 곳 → 이른 날 → 가까운 곳 순입니다. 1위가 50점 미만이면 카드를 보이지 않습니다. 표시 점수 기준 최소 62점(원래 점수 50과 같은 날씨 수준, `TRIP_MIN_SCORE`) 이상이어야 추천합니다. @@ -363,7 +363,7 @@ | 하늘 | 15% | 시간마다 맑음 100 · 구름많음 80 · 흐림 50 점의 평균 | | 바람 | 10% | ③ 괜찮은 바람 초속 4m, 한계 12m | -- 비 소식이 있거나 비 확률이 60% 이상이면 **최대 30점**입니다. +- 비가 와도 따로 상한으로 묶지 않습니다. 비 소식이 있으면 비 점수가 0점이라 원래 점수는 0~45점 안에서 갈립니다. - 중기예보뿐인 날은 기온을 어림하고(10-7), 하늘은 그날 하늘 하나, 바람은 70점입니다. - **전국 순위:** 대표 30곳을 점수 순으로 줄 세웁니다. - **당일치기:** 내 지역에서 직선 20~200km 안 후보 도시 중 토·일 가운데 더 좋은 날의 점수가 가장 높은 곳입니다. 동점이면 비 확률이 낮은 곳, 이른 날, 가까운 곳 순입니다. 1위가 50점 미만이면 카드를 보여 주지 않습니다.