From d020d27715ddf7ead5652dc9d79fba0cf255958e Mon Sep 17 00:00:00 2001 From: Mina Choi Date: Tue, 13 Oct 2026 09:44:22 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EA=B0=81=20=EC=A0=95=EC=9D=98=20?= =?UTF-8?q?=EA=B2=80=ED=86=A0=20=EB=B0=98=EC=98=81=20=E2=80=94=20=EC=A7=80?= =?UTF-8?q?=EA=B8=88=20=EB=B9=84=20=EC=98=A4=EB=A9=B4=20=EB=B0=94=EA=B9=A5?= =?UTF-8?q?=20=EA=B0=81=20=EC=83=81=ED=95=9C(=EB=B9=84=20=EC=86=8C?= =?UTF-8?q?=EC=8B=9D=20=EC=A1=B0=EA=B1=B4),=20=EC=8A=B5=EB=8F=84=20?= =?UTF-8?q?=EC=83=81=ED=95=9C,=20=EC=8B=9C=EA=B0=84=EB=8C=80=EA=B0=80=20?= =?UTF-8?q?=EA=B5=AC=EA=B0=84=EA=B3=BC=202=EC=8B=9C=EA=B0=84=20=EC=9D=B4?= =?UTF-8?q?=EC=83=81=20=EA=B2=B9=EC=B3=90=EC=95=BC=20=EA=B5=AC=EA=B0=84=20?= =?UTF-8?q?=EC=A0=90=EC=88=98,=20=EB=9C=A8=EC=95=84=C2=B7=ED=99=98?= =?UTF-8?q?=EA=B8=B0=C2=B7=EA=B9=80=EC=84=9C=EB=A6=BC=C2=B7=ED=99=94?= =?UTF-8?q?=EC=9E=A5=EB=B6=95=EA=B4=B4=C2=B7=EB=83=89=EB=A9=B4=C2=B7?= =?UTF-8?q?=ED=83=9D=EC=8B=9C=C2=B7=EB=B0=B0=EB=8B=AC=C2=B7=EC=95=BC?= =?UTF-8?q?=EA=B5=AC=C2=B7=EC=82=AC=EC=A7=84=C2=B7=EA=B3=B5=EB=B6=80=C2=B7?= =?UTF-8?q?=EB=84=B7=ED=94=8C=EB=A6=AD=EC=8A=A4=C2=B7=EA=B5=B0=EB=B0=A4?= =?UTF-8?q?=C2=B7=EC=97=B0=EB=82=A0=EB=A6=AC=EA=B8=B0=C2=B7=EC=9D=B4?= =?UTF-8?q?=EB=B6=88=EB=B9=A8=EB=9E=98=C2=B7=EC=8B=A4=EB=82=B4=EA=B1=B4?= =?UTF-8?q?=EC=A1=B0=C2=B7=EA=B7=A4=C2=B7=EA=B5=B0=EA=B3=A0=EA=B5=AC?= =?UTF-8?q?=EB=A7=88=C2=B7=EB=B6=95=EC=96=B4=EB=B9=B5=C2=B7=EB=88=88?= =?UTF-8?q?=EC=82=AC=EB=9E=8C=C2=B7=EB=B9=99=EC=88=98=C2=B7=EC=BA=A0?= =?UTF-8?q?=ED=95=91=C2=B7=EB=8B=A8=ED=92=8D=C2=B7=ED=95=B4=EB=8F=8B?= =?UTF-8?q?=EC=9D=B4=20=EB=B9=84=EC=A4=91=C2=B7=EC=A1=B0=EA=B1=B4=20?= =?UTF-8?q?=EC=A1=B0=EC=A0=95,=20=EC=83=88=20=EA=B0=81=20=EC=9A=B0?= =?UTF-8?q?=EC=82=B0=C2=B7=ED=8C=8C=EC=A0=84=C2=B7=EA=B0=90=EC=84=B1?= =?UTF-8?q?=EB=85=B8=EB=9E=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/seed/index_definition.json | 532 ++++++++++++++++++++++++---- backend/services/calc/index_calc.py | 9 +- backend/services/index_service.py | 4 +- backend/tests/test_day_slot.py | 14 +- backend/tests/test_feed.py | 2 +- backend/tests/test_index_api.py | 2 +- backend/tests/test_index_calc.py | 18 + 7 files changed, 505 insertions(+), 76 deletions(-) diff --git a/backend/seed/index_definition.json b/backend/seed/index_definition.json index aa1c345..5730b6c 100644 --- a/backend/seed/index_definition.json +++ b/backend/seed/index_definition.json @@ -52,10 +52,15 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes" + }, { "field": "rain_prob", "op": ">=", - "value": 80 + "value": 70 }, { "field": "wind_ms", @@ -135,6 +140,11 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes" + }, { "field": "rain_prob", "op": ">=", @@ -211,6 +221,11 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes" + }, { "field": "feels_c", "op": "<", @@ -219,7 +234,7 @@ { "field": "rain_prob", "op": ">=", - "value": 80 + "value": 70 } ], "limit_description": "야구 경기 같은 이벤트는 아직 반영하지 못해요", @@ -283,10 +298,15 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes" + }, { "field": "rain_prob", "op": ">=", - "value": 90 + "value": 70 }, { "field": "pm25", @@ -335,8 +355,8 @@ "weight_temp": 10, "weight_rain": 15, "weight_wind": 15, - "weight_humidity": 10, - "weight_air": 45, + "weight_humidity": 20, + "weight_air": 35, "weight_uv": 0, "weight_sun": 0, "weight_view": 0, @@ -365,10 +385,28 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes", + "cap": 20 + }, { "field": "pm25", "op": ">=", "value": 75 + }, + { + "field": "rain_prob", + "op": ">=", + "value": 70, + "cap": 20 + }, + { + "field": "humidity", + "op": ">=", + "value": 85, + "cap": 40 } ], "limit_description": "집 방향과 주변 공사 먼지는 반영하지 못해요", @@ -448,6 +486,11 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes" + }, { "field": "rain_prob", "op": ">=", @@ -533,6 +576,12 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes", + "cap": 20 + }, { "field": "rain_prob", "op": ">=", @@ -566,10 +615,10 @@ "to": 32 } ], - "weight_temp": 30, + "weight_temp": 40, "weight_rain": 25, "weight_wind": 15, - "weight_humidity": 15, + "weight_humidity": 5, "weight_air": 10, "weight_uv": 0, "weight_sun": 0, @@ -600,6 +649,11 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes" + }, { "field": "rain_prob", "op": ">=", @@ -685,6 +739,12 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes", + "cap": 20 + }, { "field": "feels_c", "op": ">=", @@ -693,7 +753,7 @@ { "field": "rain_prob", "op": ">=", - "value": 90 + "value": 70 } ], "limit_description": "노면 상태는 반영하지 못해요", @@ -757,10 +817,20 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes" + }, { "field": "cloudy_ratio", "op": ">=", "value": 80 + }, + { + "field": "rain_prob", + "op": ">=", + "value": 60 } ], "limit_description": "도시 불빛은 지역 평균으로만 반영해요", @@ -800,9 +870,9 @@ "to": 20 } ], - "weight_temp": 40, + "weight_temp": 50, "weight_rain": 25, - "weight_wind": 15, + "weight_wind": 5, "weight_humidity": 10, "weight_air": 5, "weight_uv": 0, @@ -857,8 +927,8 @@ } ], "weight_temp": 15, - "weight_rain": 50, - "weight_wind": 10, + "weight_rain": 55, + "weight_wind": 5, "weight_humidity": 15, "weight_air": 5, "weight_uv": 0, @@ -914,11 +984,11 @@ "to": 10 } ], - "weight_temp": 50, - "weight_rain": 10, - "weight_wind": 15, - "weight_humidity": 10, - "weight_air": 5, + "weight_temp": 90, + "weight_rain": 0, + "weight_wind": 0, + "weight_humidity": 0, + "weight_air": 0, "weight_uv": 0, "weight_sun": 0, "weight_view": 0, @@ -1004,6 +1074,11 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes" + }, { "field": "rain_prob", "op": ">=", @@ -1082,6 +1157,11 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes" + }, { "field": "rain_prob", "op": ">=", @@ -1163,6 +1243,12 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes", + "cap": 20 + }, { "field": "feels_c", "op": ">=", @@ -1177,6 +1263,12 @@ "field": "ground_c", "op": ">=", "value": 45 + }, + { + "field": "rain_prob", + "op": ">=", + "value": 70, + "cap": 20 } ], "limit_description": "지표면 온도는 예보 모델 값이라 실제 노면 온도와 달라요", @@ -1205,10 +1297,10 @@ "to": 9 } ], - "weight_temp": 50, + "weight_temp": 70, "weight_rain": 10, - "weight_wind": 5, - "weight_humidity": 30, + "weight_wind": 0, + "weight_humidity": 15, "weight_air": 0, "weight_uv": 0, "weight_sun": 0, @@ -1261,9 +1353,9 @@ "to": 18 } ], - "weight_temp": 40, - "weight_rain": 10, - "weight_wind": 10, + "weight_temp": 55, + "weight_rain": 5, + "weight_wind": 0, "weight_humidity": 35, "weight_air": 0, "weight_uv": 0, @@ -1317,10 +1409,10 @@ "to": 14 } ], - "weight_temp": 55, + "weight_temp": 65, "weight_rain": 15, "weight_wind": 5, - "weight_humidity": 15, + "weight_humidity": 5, "weight_air": 5, "weight_uv": 0, "weight_sun": 0, @@ -1379,10 +1471,10 @@ "to": 26 } ], - "weight_temp": 15, - "weight_rain": 55, - "weight_wind": 10, - "weight_humidity": 5, + "weight_temp": 20, + "weight_rain": 65, + "weight_wind": 0, + "weight_humidity": 0, "weight_air": 0, "weight_uv": 0, "weight_sun": 0, @@ -1391,7 +1483,7 @@ "factor_rules": { "temp": { "type": "lower", - "zero": 15, + "zero": 25, "full": -5 }, "rain": { @@ -1438,19 +1530,19 @@ } ], "weight_temp": 20, - "weight_rain": 50, - "weight_wind": 10, - "weight_humidity": 5, - "weight_air": 5, + "weight_rain": 65, + "weight_wind": 5, + "weight_humidity": 0, + "weight_air": 0, "weight_uv": 0, "weight_sun": 0, "weight_view": 0, "weight_time": 10, "factor_rules": { "temp": { - "type": "lower", - "zero": 22, - "full": 0 + "type": "away", + "lo": 10, + "hi": 25 }, "rain": { "dir": "wet" @@ -1539,6 +1631,12 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes", + "cap": 20 + }, { "field": "rain_prob", "op": ">=", @@ -1609,10 +1707,15 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes" + }, { "field": "rain_prob", "op": ">=", - "value": 80 + "value": 70 } ], "limit_description": "장소 혼잡도는 반영하지 못해요", @@ -1641,10 +1744,10 @@ "to": 22 } ], - "weight_temp": 25, - "weight_rain": 40, + "weight_temp": 35, + "weight_rain": 35, "weight_wind": 10, - "weight_humidity": 5, + "weight_humidity": 0, "weight_air": 10, "weight_uv": 0, "weight_sun": 0, @@ -1677,6 +1780,11 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes" + }, { "field": "rain_prob", "op": ">=", @@ -1692,7 +1800,16 @@ }, "sort_order": 24, "priority": 3, - "months": [] + "months": [ + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10 + ] }, { "code": "study", @@ -1709,9 +1826,9 @@ "to": 18 } ], - "weight_temp": 35, + "weight_temp": 40, "weight_rain": 35, - "weight_wind": 10, + "weight_wind": 5, "weight_humidity": 5, "weight_air": 5, "weight_uv": 0, @@ -1739,6 +1856,10 @@ "sun": 50, "holiday": 50, "default": 100 + }, + "air": { + "zero": 15, + "full": 75 } }, "zero_rules": [], @@ -1769,9 +1890,9 @@ } ], "weight_temp": 30, - "weight_rain": 35, - "weight_wind": 15, - "weight_humidity": 5, + "weight_rain": 50, + "weight_wind": 5, + "weight_humidity": 0, "weight_air": 0, "weight_uv": 0, "weight_sun": 0, @@ -1826,9 +1947,9 @@ "to": 21 } ], - "weight_temp": 55, + "weight_temp": 60, "weight_rain": 25, - "weight_wind": 10, + "weight_wind": 5, "weight_humidity": 0, "weight_air": 5, "weight_uv": 0, @@ -1855,7 +1976,14 @@ "value": 100 } }, - "zero_rules": [], + "zero_rules": [ + { + "field": "feels_c", + "op": ">=", + "value": 18, + "cap": 20 + } + ], "limit_description": "군밤 노점이 있는지는 반영하지 못해요", "sentences": { "0": "아직 18° 넘어요. 군밤은 조금 더 추워지면!", @@ -1930,6 +2058,12 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes", + "cap": 20 + }, { "field": "rain_prob", "op": ">=", @@ -1972,9 +2106,9 @@ "to": 18 } ], - "weight_temp": 30, + "weight_temp": 35, "weight_rain": 30, - "weight_wind": 10, + "weight_wind": 5, "weight_humidity": 5, "weight_air": 20, "weight_uv": 0, @@ -2074,6 +2208,12 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes", + "cap": 40 + }, { "field": "rain_prob", "op": ">=", @@ -2158,10 +2298,16 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes", + "cap": 20 + }, { "field": "rain_prob", "op": ">=", - "value": 70, + "value": 60, "cap": 20 } ], @@ -2224,6 +2370,12 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes", + "cap": 20 + }, { "field": "rain_prob", "op": ">=", @@ -2239,6 +2391,12 @@ "op": "<", "value": 1, "cap": 30 + }, + { + "field": "wind_ms", + "op": ">=", + "value": 8, + "cap": 50 } ], "limit_description": "전깃줄·나무 없는 넓은 곳인지는 반영하지 못해요", @@ -2307,6 +2465,11 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes" + }, { "field": "rain_prob", "op": ">=", @@ -2384,10 +2547,22 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes", + "cap": 40 + }, { "field": "feels_c", "op": ">=", "value": 18 + }, + { + "field": "rain_prob", + "op": ">=", + "value": 70, + "cap": 40 } ], "limit_description": "배추 작황과 값, 집집마다 김장 날짜는 반영하지 못해요", @@ -2462,6 +2637,11 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes" + }, { "field": "rain_prob", "op": ">=", @@ -2532,6 +2712,11 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes" + }, { "field": "rain_prob", "op": ">=", @@ -2550,7 +2735,11 @@ "months": [ 3, 4, - 5 + 5, + 6, + 9, + 10, + 11 ] }, { @@ -2568,10 +2757,10 @@ "to": 18 } ], - "weight_temp": 60, + "weight_temp": 70, "weight_rain": 10, "weight_wind": 5, - "weight_humidity": 20, + "weight_humidity": 10, "weight_air": 0, "weight_uv": 0, "weight_sun": 0, @@ -2631,9 +2820,9 @@ } ], "weight_temp": 15, - "weight_rain": 40, + "weight_rain": 60, "weight_wind": 0, - "weight_humidity": 40, + "weight_humidity": 20, "weight_air": 0, "weight_uv": 0, "weight_sun": 0, @@ -2659,7 +2848,14 @@ "value": 100 } }, - "zero_rules": [], + "zero_rules": [ + { + "field": "rain_prob", + "op": "<", + "value": 40, + "cap": 20 + } + ], "limit_description": "집 안 습도·환기·제습기 여부는 반영하지 못해요", "sentences": { "0": "밖에 널어도 되는 날이에요. 빨래각을 봐요!", @@ -2727,6 +2923,11 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes" + }, { "field": "rain_prob", "op": ">=", @@ -2806,6 +3007,11 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes" + }, { "field": "rain_prob", "op": ">=", @@ -2822,7 +3028,6 @@ "sort_order": 40, "priority": 2, "months": [ - 9, 10, 11 ] @@ -2875,6 +3080,11 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes" + }, { "field": "rain_prob", "op": ">=", @@ -2911,9 +3121,9 @@ "to": 21 } ], - "weight_temp": 60, + "weight_temp": 65, "weight_rain": 20, - "weight_wind": 10, + "weight_wind": 5, "weight_humidity": 0, "weight_air": 5, "weight_uv": 0, @@ -2986,7 +3196,8 @@ "temp": { "type": "higher", "zero": -15, - "full": 5 + "full": 5, + "label": "덜 추움" }, "rain": { "dir": "dry" @@ -3008,6 +3219,11 @@ } }, "zero_rules": [ + { + "field": "rain", + "op": "==", + "value": "yes" + }, { "field": "rain_prob", "op": ">=", @@ -3084,6 +3300,18 @@ "field": "snow", "op": "==", "value": "no" + }, + { + "field": "feels_c", + "op": ">=", + "value": 4, + "cap": 30 + }, + { + "field": "feels_c", + "op": "<", + "value": -10, + "cap": 40 } ], "limit_description": "쌓인 눈의 양은 반영하지 못해요. 눈 오는 시간만 봐요", @@ -3116,9 +3344,9 @@ "to": 21 } ], - "weight_temp": 60, + "weight_temp": 70, "weight_rain": 15, - "weight_wind": 15, + "weight_wind": 5, "weight_humidity": 0, "weight_air": 5, "weight_uv": 0, @@ -3176,9 +3404,9 @@ "to": 24 } ], - "weight_temp": 50, - "weight_rain": 20, - "weight_wind": 20, + "weight_temp": 75, + "weight_rain": 5, + "weight_wind": 10, "weight_humidity": 0, "weight_air": 5, "weight_uv": 0, @@ -3220,5 +3448,173 @@ 1, 2 ] + }, + { + "code": "umbrella", + "name": "우산각", + "icon": "umbrella", + "category": 4, + "is_fun": false, + "is_core": false, + "has_detail": true, + "description": "오전 6시~자정, 밖에 나갈 때 우산을 챙겨야 하는 정도", + "windows": [ + { + "from": 6, + "to": 24 + } + ], + "weight_temp": 0, + "weight_rain": 90, + "weight_wind": 0, + "weight_humidity": 0, + "weight_air": 0, + "weight_uv": 0, + "weight_sun": 0, + "weight_view": 0, + "weight_time": 10, + "factor_rules": { + "temp": { + "type": "range", + "lo": 0, + "hi": 40 + }, + "rain": { + "dir": "wet" + }, + "wind": { + "type": "ignore" + }, + "humidity": { + "type": "ignore" + }, + "time": { + "type": "fixed", + "value": 100 + } + }, + "zero_rules": [], + "limit_description": "소나기처럼 갑자기 오는 비는 놓칠 수 있어요", + "sentences": { + "0": "하늘이 말짱해요. 우산은 두고 가도 돼요.", + "30": "비 소식이 조금 있어요. 작은 우산 하나 챙기면 든든해요.", + "60": "비가 와요. 우산 꼭 챙기세요.", + "80": "비가 제법 쏟아져요. 큰 우산에 신발도 신경 써요." + }, + "sort_order": 47, + "priority": 2, + "months": [] + }, + { + "code": "pajeon", + "name": "파전각", + "icon": "makgeolli", + "category": 2, + "is_fun": true, + "is_core": false, + "has_detail": true, + "description": "오전 11시~밤 9시, 비 오는 날 파전이 당기는 정도", + "windows": [ + { + "from": 11, + "to": 21 + } + ], + "weight_temp": 20, + "weight_rain": 70, + "weight_wind": 0, + "weight_humidity": 0, + "weight_air": 0, + "weight_uv": 0, + "weight_sun": 0, + "weight_view": 0, + "weight_time": 10, + "factor_rules": { + "temp": { + "type": "lower", + "zero": 26, + "full": 10 + }, + "rain": { + "dir": "wet" + }, + "wind": { + "type": "ignore" + }, + "humidity": { + "type": "ignore" + }, + "time": { + "type": "fixed", + "value": 100 + } + }, + "zero_rules": [], + "limit_description": "실제 판매량으로 검증하기 전이에요", + "sentences": { + "0": "맑은 날엔 파전보다 바깥 나들이!", + "30": "꾸물꾸물한 하늘, 파전 생각이 슬슬 나요.", + "60": "빗소리 들리면 파전 부칠 시간이에요.", + "80": "지글지글 빗소리, 오늘은 무조건 파전!" + }, + "sort_order": 48, + "priority": 3, + "months": [] + }, + { + "code": "mood_song", + "name": "감성노래각", + "icon": "rain", + "category": 3, + "is_fun": true, + "is_core": false, + "has_detail": true, + "description": "오후 6시~자정, 비 오는 날 감성 노래 듣기 좋은 정도", + "windows": [ + { + "from": 18, + "to": 24 + } + ], + "weight_temp": 25, + "weight_rain": 60, + "weight_wind": 0, + "weight_humidity": 0, + "weight_air": 0, + "weight_uv": 0, + "weight_sun": 0, + "weight_view": 0, + "weight_time": 15, + "factor_rules": { + "temp": { + "type": "lower", + "zero": 26, + "full": 8 + }, + "rain": { + "dir": "wet" + }, + "wind": { + "type": "ignore" + }, + "humidity": { + "type": "ignore" + }, + "time": { + "type": "fixed", + "value": 100 + } + }, + "zero_rules": [], + "limit_description": "음악 취향은 반영하지 못해요", + "sentences": { + "0": "쨍한 날엔 신나는 노래가 더 어울려요.", + "30": "구름 낀 하늘, 잔잔한 노래 한 곡 어때요?", + "60": "창밖에 빗소리, 플레이리스트 꺼낼 시간이에요.", + "80": "빗소리에 옛날 노래까지, 감성 가득한 밤이에요." + }, + "sort_order": 49, + "priority": 3, + "months": [] } ] diff --git a/backend/services/calc/index_calc.py b/backend/services/calc/index_calc.py index db52844..4dcc185 100644 --- a/backend/services/calc/index_calc.py +++ b/backend/services/calc/index_calc.py @@ -229,7 +229,7 @@ def axis_label(axis: str, rules: dict) -> str: rule = rules.get("air", _AIR_RULE) return "공기 탁함" if rule["full"] > rule["zero"] else "공기 맑음" table = {"temp": _TEMP_LABEL, "wind": _WIND_LABEL, "humidity": _HUMIDITY_LABEL, "time": _TIME_LABEL}[axis] - return table[rules[axis]["type"]] + return rules[axis].get("label") or table[rules[axis]["type"]] def _zero(rules: list[dict], agg: dict) -> tuple[Optional[str], Optional[int]]: @@ -249,9 +249,9 @@ def _zero(rules: list[dict], agg: dict) -> tuple[Optional[str], Optional[int]]: _FIELD_TEXT = { "rain_prob": "비 확률", "wind_ms": "바람", "feels_c": "체감", "pm25": "초미세먼지", "cloudy_ratio": "흐린 하늘", - "gust_ms": "돌풍", "ground_c": "지표면 온도", + "gust_ms": "돌풍", "ground_c": "지표면 온도", "humidity": "습도", } -_UNIT = {"rain_prob": "%", "wind_ms": "m/s", "feels_c": "°", "pm25": "㎍/㎥", "cloudy_ratio": "%", "gust_ms": "m/s", "ground_c": "°"} +_UNIT = {"rain_prob": "%", "wind_ms": "m/s", "feels_c": "°", "pm25": "㎍/㎥", "cloudy_ratio": "%", "gust_ms": "m/s", "ground_c": "°", "humidity": "%"} def _cond(r: dict) -> tuple[str, str, str]: @@ -260,6 +260,8 @@ def _cond(r: dict) -> tuple[str, str, str]: return "강풍 특보가 있어", "강풍 특보가 있거나", "강풍 특보가 있으면" if r["field"] == "snow": return "눈 소식이 없어", "눈 소식이 없거나", "눈 소식이 없으면" + if r["field"] == "rain": + return "비 소식이 있어", "비 소식이 있거나", "비 소식이 있으면" base = f"{_FIELD_TEXT[r['field']]} {r['value']}{_UNIT[r['field']]} {'이상' if r['op'] == '>=' else '미만'}" return f"{base}이라", f"{base}이거나", f"{base}이면" @@ -341,6 +343,7 @@ def evaluate(definition, windows: list[list[Hour]], ctx: Context) -> Optional[Re "warning": "wind" if ctx.wind_warning else None, "gust_ms": max(gusts, default=None), "ground_c": max(grounds, default=None), "snow": "yes" if any(h.rain_type in (RainType.SNOW, RainType.SLEET) for h in hours) else "no", + "rain": "yes" if raining else "no", "humidity": round(mean(h.humidity for h in hours)), } reason, cap = _zero(definition.zero_rules, agg) if reason is not None: diff --git a/backend/services/index_service.py b/backend/services/index_service.py index f2099b8..1cd60db 100644 --- a/backend/services/index_service.py +++ b/backend/services/index_service.py @@ -189,6 +189,7 @@ def with_ultra_rain(by_at: dict[datetime, WeatherHourly], ultra: Optional[list[R EARLY = "early" # 0~5시: 전날 밤 구간 +MIN_SLOT_HOURS = 2 # 각 시간대가 구간과 이만큼은 겹쳐야 그 구간 점수를 낸다 (한 시간짜리 각은 한 시간) def current_slot(now: datetime, sunset_at: datetime) -> str: @@ -211,9 +212,10 @@ def slot_results( """그날 아침·낮·저녁·밤과 0~5시(전날 밤) 점수. 각 시간대와 겹치지 않는 구간은 빠진다.""" parts = {k: windows_for(defn, day, region, by_at, by_om, only=hours) for k, hours in slot_hours(day, sunset_at).items()} parts[EARLY] = windows_for(defn, day - timedelta(days=1), region, by_at, by_om, only=set(range(24, 24 + NIGHT_END_HOUR))) + need = min(MIN_SLOT_HOURS, max((len(h) for h in window_hours(defn, day, region)), default=0)) out = {} for key, windows in parts.items(): - result = evaluate(defn, windows, ctx) + result = evaluate(defn, [w for w in windows if len(w) >= need], ctx) if result is not None: out[key] = result return out diff --git a/backend/tests/test_day_slot.py b/backend/tests/test_day_slot.py index d4a363d..1c63323 100644 --- a/backend/tests/test_day_slot.py +++ b/backend/tests/test_day_slot.py @@ -49,8 +49,10 @@ def test_current_slot_before_5_is_previous_night(): def test_gak_hidden_in_slots_outside_its_window(): - parts = slot_results(_defn([{"from": 18, "to": 24}]), DAY, REGION, _rows(), {}, CTX, SUNSET) + parts = slot_results(_defn([{"from": 17, "to": 24}]), DAY, REGION, _rows(), {}, CTX, SUNSET) assert set(parts) == {"evening", "night"} + # 18시 한 시간만 저녁 구간(16~18시)과 겹치면 저녁 점수는 내지 않는다 + assert set(slot_results(_defn([{"from": 18, "to": 24}]), DAY, REGION, _rows(), {}, CTX, SUNSET)) == {"night"} def test_rain_in_evening_lowers_only_later_slots(): @@ -91,8 +93,16 @@ def test_ultra_rain_marks_dry_forecast_hours_as_rain(): def test_ultra_rain_lowers_slot_score(): - defn = _defn([{"from": 10, "to": 17}]) + defn = _defn([{"from": 9, "to": 17}]) by_at = {r.forecast_at: r for r in (_hourly(h) for h in range(5, 30))} rainy = with_ultra_rain(by_at, [RainHour(at=kst_midnight(DAY) + timedelta(hours=10), rain_type=RainType.RAIN, rain_mm=2.0)]) dry, wet = (slot_results(defn, DAY, REGION, b, {}, CTX, SUNSET)["morning"].score for b in (by_at, rainy)) assert wet < dry + + +def test_slot_needs_two_overlapping_hours(): + """10~17시 각은 아침 구간(5~11시)과 10시 한 시간만 겹쳐서 아침 점수를 내지 않는다. 한 시간짜리 각은 한 시간이면 된다.""" + by_at = _rows() + assert "morning" not in slot_results(_defn([{"from": 10, "to": 17}]), DAY, REGION, by_at, {}, CTX, SUNSET) + assert "morning" in slot_results(_defn([{"from": 9, "to": 17}]), DAY, REGION, by_at, {}, CTX, SUNSET) + assert "morning" in slot_results(_defn([{"from": 10, "to": 11}]), DAY, REGION, by_at, {}, CTX, SUNSET) diff --git a/backend/tests/test_feed.py b/backend/tests/test_feed.py index 75cd592..5c0ef3f 100644 --- a/backend/tests/test_feed.py +++ b/backend/tests/test_feed.py @@ -61,7 +61,7 @@ async def test_feed_assembles_hero_stories_posts_and_bands(offline): body = (await client.get("/v1/feed", params={"region": REGION})).json() assert body["result"]["success"] is True assert body["hero"]["temp_c"] == 20 and body["hero"]["top1"]["rank"] == 1 and "top3" not in body["hero"] - assert len(body["stories"]) == 34 + assert len(body["stories"]) == 38 assert body["hero"]["weather_score"] == body["hero"]["weather_slots"][body["slot"]] assert all(g["slots"][body["slot"]] == g["score"] and g["slot_ranks"][body["slot"]] == g["rank"] for g in body["stories"] if g["active"]) weather = next(p for p in body["posts"] if p["post_type"] == PostType.WEATHER.value) diff --git a/backend/tests/test_index_api.py b/backend/tests/test_index_api.py index d4ecba8..dacdb5b 100644 --- a/backend/tests/test_index_api.py +++ b/backend/tests/test_index_api.py @@ -92,7 +92,7 @@ async def test_index_detail_has_six_factors_and_rules(fakes): assert body["index"]["code"] == "yajang" assert [f["label"] for f in body["factors"]] == ["기온 알맞음", "비 안 옴", "바람 잔잔", "습도 알맞음", "공기 맑음", "요일 알맞음"] assert sum(f["weight"] for f in body["factors"]) == 100 - assert body["zero_rules"] == "비 확률 80% 이상이거나 바람 14m/s 이상이면 0점" + assert body["zero_rules"] == "비 소식이 있거나 비 확률 70% 이상이거나 바람 14m/s 이상이면 0점" assert body["limit"].startswith("모기") diff --git a/backend/tests/test_index_calc.py b/backend/tests/test_index_calc.py index 9556ae2..ff95e2f 100644 --- a/backend/tests/test_index_calc.py +++ b/backend/tests/test_index_calc.py @@ -290,3 +290,21 @@ def test_weather_score_100_only_on_perfect_day(): good = [_h(h, feels=22.5, prob=10, wind=2.5, hum=62, sunshine_ratio=0.7) for h in range(9, 22)] assert evaluate(WEATHER_SCORE_DEF, [good], replace(perfect, pm25=15)).score < 95 + + +def test_raining_now_caps_even_with_low_rain_prob(): + """초단기예보로 비가 들어온 시각은 예보 확률이 낮아도 '비 소식' 상한이 걸린다.""" + defn = _defn(zero_rules=[{"field": "rain", "op": "==", "value": "yes", "cap": 20}]) + r = evaluate(defn, [[_h(19, prob=30, rain=RainType.RAIN)]], CTX) + assert r.score <= 20 and r.zero_reason == "비 소식이 있어 최대 20점" + assert evaluate(defn, [[_h(19, prob=30)]], CTX).zero_reason is None + + +def test_humidity_cap(): + defn = _defn(zero_rules=[{"field": "humidity", "op": ">=", "value": 85, "cap": 40}]) + assert evaluate(defn, [[_h(19, hum=92)]], CTX).zero_reason == "습도 85% 이상이라 최대 40점" + assert zero_rules_text([{"field": "rain", "op": "==", "value": "yes"}]) == "비 소식이 있으면 0점" + + +def test_axis_label_can_be_overridden(): + assert axis_label("temp", {"temp": {"type": "higher", "label": "덜 추움"}}) == "덜 추움"