feat: 각 7개 추가 (골프·집콕·낚시·드라이브·연날리기·물놀이·김장)
This commit is contained in:
1 parent
e8382f450b
commit
b130b32f0b
15 files changed
+726
-13
No files matched your search
@@ -70,7 +70,13 @@ def zero(z):
|
||||
return s + (f" 최대 {z['cap']}점" if "cap" in z else " 0점")
|
||||
|
||||
|
||||
AX = [("temp", "기온", temp), ("rain", "비", rain), ("wind", "바람", wind), ("humidity", "습도", hum), ("air", "미세먼지", None),
|
||||
def air(r):
|
||||
if r["full"] > r["zero"]:
|
||||
return f"초미세먼지 높을수록 좋음 ({r['zero']}㎍/㎥=0점 → {r['full']}㎍/㎥=100점)"
|
||||
return "초미세먼지 낮을수록 좋음"
|
||||
|
||||
|
||||
AX = [("temp", "기온", temp), ("rain", "비", rain), ("wind", "바람", wind), ("humidity", "습도", hum), ("air", "미세먼지", air),
|
||||
("uv", "자외선", lambda r: f"자외선 {r['full']} 이하면 만점, {r['zero']} 이상이면 0점 (Open-Meteo)"),
|
||||
("sun", "햇빛", lambda r: f"해 난 비율 {round(r['full'] * 100)}% 이상이면 만점, {round(r['zero'] * 100)}% 이하면 0점 (Open-Meteo)"),
|
||||
("view", "가시거리", lambda r: f"{r['full']}km 이상이면 만점, {r['zero']}km 이하면 0점 (Open-Meteo)"),
|
||||
@@ -91,7 +97,7 @@ def main() -> None:
|
||||
P("- 최종 점수 = 비중대로 섞은 점수 × (0.75 + 0.25 × 가장 낮은 요소 점수 ÷ 100). 비중 0%인 요소는 '가장 낮은 요소'에서 뺍니다. 가장 낮은 요소가 0점이면 25%가 깎입니다.")
|
||||
P("- '0점 조건'에 걸리면 0점, '최대 N점' 조건에 걸리면 N점을 넘지 못합니다.")
|
||||
P("- 시간대가 여러 개면 그중 가장 좋은 시간대 점수를 씁니다.")
|
||||
P("- 미세먼지는 모든 각이 같은 규칙입니다: 초미세먼지 15㎍/㎥ 이하 100점 → 75㎍/㎥ 이상 0점.")
|
||||
P("- 미세먼지는 초미세먼지 15㎍/㎥ 이하 100점 → 75㎍/㎥ 이상 0점입니다. 집콕각처럼 규칙을 따로 적은 각만 거꾸로(탁할수록 좋음) 셉니다.")
|
||||
P("- 바람·미세먼지·노을 정보가 없으면 70점으로 둡니다.\n")
|
||||
P("## 한눈에 보기\n")
|
||||
P("| 순서 | 각 | 코드 | 분류 | 시간대 | 기온 | 비 | 바람 | 습도 | 미세먼지 | 시간 | 재미 각 | 계절 핵심 |")
|
||||
@@ -111,7 +117,7 @@ def main() -> None:
|
||||
w = x.get("weight_" + key, 0)
|
||||
if key in _OPTIONAL and not w:
|
||||
continue
|
||||
rule = "초미세먼지 낮을수록 좋음" if fn is None else fn(x["factor_rules"][key])
|
||||
rule = fn(x["factor_rules"].get(key, {"zero": 75, "full": 15}))
|
||||
P(f" - {label} {w}%: {rule}")
|
||||
zs = [zero(z) for z in x["zero_rules"]]
|
||||
P(f"- 점수 깎이는 조건: {', '.join(zs) if zs else '없음'}")
|
||||
|
||||
@@ -1764,5 +1764,515 @@
|
||||
"80": "영하 가까운 저녁, 군밤 품고 걷는 날 🌰"
|
||||
},
|
||||
"sort_order": 27
|
||||
},
|
||||
{
|
||||
"code": "golf",
|
||||
"name": "골프각",
|
||||
"icon": "golf",
|
||||
"category": 1,
|
||||
"is_fun": false,
|
||||
"is_core": false,
|
||||
"has_detail": true,
|
||||
"description": "오전 7시~오후 5시, 필드에서 라운딩하기 좋은 정도",
|
||||
"windows": [
|
||||
{
|
||||
"from": 7,
|
||||
"to": 12
|
||||
},
|
||||
{
|
||||
"from": 12,
|
||||
"to": 17
|
||||
}
|
||||
],
|
||||
"weight_temp": 30,
|
||||
"weight_rain": 30,
|
||||
"weight_wind": 25,
|
||||
"weight_humidity": 5,
|
||||
"weight_air": 5,
|
||||
"weight_uv": 0,
|
||||
"weight_sun": 0,
|
||||
"weight_view": 0,
|
||||
"weight_time": 5,
|
||||
"factor_rules": {
|
||||
"temp": {
|
||||
"type": "range",
|
||||
"lo": 15,
|
||||
"hi": 24
|
||||
},
|
||||
"rain": {
|
||||
"dir": "dry"
|
||||
},
|
||||
"wind": {
|
||||
"type": "calm",
|
||||
"ok": 3,
|
||||
"limit": 9
|
||||
},
|
||||
"humidity": {
|
||||
"type": "range",
|
||||
"lo": 30,
|
||||
"hi": 60,
|
||||
"best": 35
|
||||
},
|
||||
"time": {
|
||||
"type": "weekday",
|
||||
"sat": 100,
|
||||
"sun": 100,
|
||||
"holiday": 100,
|
||||
"default": 70
|
||||
}
|
||||
},
|
||||
"zero_rules": [
|
||||
{
|
||||
"field": "rain_prob",
|
||||
"op": ">=",
|
||||
"value": 70
|
||||
},
|
||||
{
|
||||
"field": "wind_ms",
|
||||
"op": ">=",
|
||||
"value": 12
|
||||
},
|
||||
{
|
||||
"field": "warning",
|
||||
"op": "==",
|
||||
"value": "wind"
|
||||
}
|
||||
],
|
||||
"limit_description": "골프장 예약, 잔디 상태, 낙뢰는 반영하지 못해요",
|
||||
"sentences": {
|
||||
"0": "비 70% 넘거나 바람이 너무 세요. 오늘은 스크린으로!",
|
||||
"30": "춥거나 덥거나 바람이 공을 흔들어요. 타수는 기대 말기!",
|
||||
"60": "칠 만해요! 바람 방향만 잘 읽으면 돼요.",
|
||||
"80": "15~24°에 바람 잔잔, 인생 라운딩 노려볼 날 ⛳"
|
||||
},
|
||||
"sort_order": 28
|
||||
},
|
||||
{
|
||||
"code": "jipkok",
|
||||
"name": "집콕각",
|
||||
"icon": "jipkok",
|
||||
"category": 3,
|
||||
"is_fun": true,
|
||||
"is_core": false,
|
||||
"has_detail": true,
|
||||
"description": "오전 10시~오후 6시, 나가기 싫어 집에 있고 싶은 정도",
|
||||
"windows": [
|
||||
{
|
||||
"from": 10,
|
||||
"to": 18
|
||||
}
|
||||
],
|
||||
"weight_temp": 30,
|
||||
"weight_rain": 30,
|
||||
"weight_wind": 10,
|
||||
"weight_humidity": 5,
|
||||
"weight_air": 20,
|
||||
"weight_uv": 0,
|
||||
"weight_sun": 0,
|
||||
"weight_view": 0,
|
||||
"weight_time": 5,
|
||||
"factor_rules": {
|
||||
"temp": {
|
||||
"type": "away",
|
||||
"lo": 15,
|
||||
"hi": 24
|
||||
},
|
||||
"rain": {
|
||||
"dir": "wet"
|
||||
},
|
||||
"wind": {
|
||||
"type": "strong"
|
||||
},
|
||||
"humidity": {
|
||||
"type": "higher"
|
||||
},
|
||||
"air": {
|
||||
"zero": 15,
|
||||
"full": 75
|
||||
},
|
||||
"time": {
|
||||
"type": "weekday",
|
||||
"sat": 100,
|
||||
"sun": 100,
|
||||
"holiday": 100,
|
||||
"default": 60
|
||||
}
|
||||
},
|
||||
"zero_rules": [],
|
||||
"limit_description": "재미로 보는 지수예요",
|
||||
"sentences": {
|
||||
"0": "밖이 너무 좋아요. 집에만 있기 아까운 날!",
|
||||
"30": "나갈까 말까, 소파와 밀당 중이에요.",
|
||||
"60": "덥거나 춥거나 공기가 탁해요. 집이 최고!",
|
||||
"80": "비 오고 공기까지 탁해요. 이불 밖은 위험해 🛋️"
|
||||
},
|
||||
"sort_order": 29
|
||||
},
|
||||
{
|
||||
"code": "fishing",
|
||||
"name": "낚시각",
|
||||
"icon": "fishing",
|
||||
"category": 1,
|
||||
"is_fun": false,
|
||||
"is_core": false,
|
||||
"has_detail": true,
|
||||
"description": "새벽 5~9시·오후 4~7시, 물가에서 낚시하기 좋은 정도",
|
||||
"windows": [
|
||||
{
|
||||
"from": 5,
|
||||
"to": 9
|
||||
},
|
||||
{
|
||||
"from": 16,
|
||||
"to": 19
|
||||
}
|
||||
],
|
||||
"weight_temp": 25,
|
||||
"weight_rain": 25,
|
||||
"weight_wind": 35,
|
||||
"weight_humidity": 0,
|
||||
"weight_air": 5,
|
||||
"weight_uv": 0,
|
||||
"weight_sun": 0,
|
||||
"weight_view": 0,
|
||||
"weight_time": 10,
|
||||
"factor_rules": {
|
||||
"temp": {
|
||||
"type": "range",
|
||||
"lo": 12,
|
||||
"hi": 24
|
||||
},
|
||||
"rain": {
|
||||
"dir": "dry"
|
||||
},
|
||||
"wind": {
|
||||
"type": "calm",
|
||||
"ok": 4,
|
||||
"limit": 10
|
||||
},
|
||||
"humidity": {
|
||||
"type": "ignore"
|
||||
},
|
||||
"time": {
|
||||
"type": "weekday",
|
||||
"sat": 100,
|
||||
"sun": 100,
|
||||
"holiday": 100,
|
||||
"default": 60
|
||||
}
|
||||
},
|
||||
"zero_rules": [
|
||||
{
|
||||
"field": "rain_prob",
|
||||
"op": ">=",
|
||||
"value": 70
|
||||
},
|
||||
{
|
||||
"field": "wind_ms",
|
||||
"op": ">=",
|
||||
"value": 10
|
||||
},
|
||||
{
|
||||
"field": "warning",
|
||||
"op": "==",
|
||||
"value": "wind"
|
||||
}
|
||||
],
|
||||
"limit_description": "물때·수온·파도 높이는 반영하지 못해요",
|
||||
"sentences": {
|
||||
"0": "비 70% 넘거나 바람이 거세요. 물가는 위험, 오늘은 쉬어요!",
|
||||
"30": "바람에 찌가 흔들리거나 손이 시려요. 짧게 손맛만!",
|
||||
"60": "물가 나가볼 만해요! 새벽엔 쌀쌀하니 겉옷 챙기기.",
|
||||
"80": "12~24°에 물결 잔잔, 입질 기다리기 딱 좋은 날 🎣"
|
||||
},
|
||||
"sort_order": 30
|
||||
},
|
||||
{
|
||||
"code": "drive",
|
||||
"name": "드라이브각",
|
||||
"icon": "drive",
|
||||
"category": 1,
|
||||
"is_fun": false,
|
||||
"is_core": false,
|
||||
"has_detail": true,
|
||||
"description": "오전 10시~오후 5시, 창문 열고 드라이브하기 좋은 정도",
|
||||
"windows": [
|
||||
{
|
||||
"from": 10,
|
||||
"to": 17
|
||||
}
|
||||
],
|
||||
"weight_temp": 20,
|
||||
"weight_rain": 30,
|
||||
"weight_wind": 5,
|
||||
"weight_humidity": 5,
|
||||
"weight_air": 15,
|
||||
"weight_uv": 0,
|
||||
"weight_sun": 0,
|
||||
"weight_view": 15,
|
||||
"weight_time": 10,
|
||||
"factor_rules": {
|
||||
"temp": {
|
||||
"type": "range",
|
||||
"lo": 15,
|
||||
"hi": 25
|
||||
},
|
||||
"rain": {
|
||||
"dir": "dry"
|
||||
},
|
||||
"wind": {
|
||||
"type": "calm",
|
||||
"ok": 6,
|
||||
"limit": 15
|
||||
},
|
||||
"humidity": {
|
||||
"type": "range",
|
||||
"lo": 30,
|
||||
"hi": 60,
|
||||
"best": 35
|
||||
},
|
||||
"time": {
|
||||
"type": "weekday",
|
||||
"sat": 100,
|
||||
"sun": 100,
|
||||
"holiday": 100,
|
||||
"default": 60
|
||||
},
|
||||
"view": {
|
||||
"zero": 5,
|
||||
"full": 20
|
||||
}
|
||||
},
|
||||
"zero_rules": [
|
||||
{
|
||||
"field": "rain_prob",
|
||||
"op": ">=",
|
||||
"value": 70,
|
||||
"cap": 20
|
||||
}
|
||||
],
|
||||
"limit_description": "길 막힘과 도로 공사는 반영하지 못해요",
|
||||
"sentences": {
|
||||
"0": "비가 쏟아져요. 와이퍼만 바쁜 날, 드라이브는 다음에!",
|
||||
"30": "하늘이 뿌옇거나 비 기운이 있어요. 가까운 곳만 슬쩍!",
|
||||
"60": "달릴 만해요! 창문 반쯤 열고 음악 크게.",
|
||||
"80": "공기 맑고 멀리까지 보여요. 해안도로 달리고 싶은 날 🚗"
|
||||
},
|
||||
"sort_order": 31
|
||||
},
|
||||
{
|
||||
"code": "kite",
|
||||
"name": "연날리기각",
|
||||
"icon": "kite",
|
||||
"category": 1,
|
||||
"is_fun": false,
|
||||
"is_core": false,
|
||||
"has_detail": true,
|
||||
"description": "오전 11시~오후 4시, 연 날리기 좋은 정도",
|
||||
"windows": [
|
||||
{
|
||||
"from": 11,
|
||||
"to": 16
|
||||
}
|
||||
],
|
||||
"weight_temp": 20,
|
||||
"weight_rain": 25,
|
||||
"weight_wind": 45,
|
||||
"weight_humidity": 0,
|
||||
"weight_air": 5,
|
||||
"weight_uv": 0,
|
||||
"weight_sun": 0,
|
||||
"weight_view": 0,
|
||||
"weight_time": 5,
|
||||
"factor_rules": {
|
||||
"temp": {
|
||||
"type": "range",
|
||||
"lo": 8,
|
||||
"hi": 22
|
||||
},
|
||||
"rain": {
|
||||
"dir": "dry"
|
||||
},
|
||||
"wind": {
|
||||
"type": "moderate"
|
||||
},
|
||||
"humidity": {
|
||||
"type": "ignore"
|
||||
},
|
||||
"time": {
|
||||
"type": "weekday",
|
||||
"sat": 100,
|
||||
"sun": 100,
|
||||
"holiday": 100,
|
||||
"default": 70
|
||||
}
|
||||
},
|
||||
"zero_rules": [
|
||||
{
|
||||
"field": "rain_prob",
|
||||
"op": ">=",
|
||||
"value": 70
|
||||
},
|
||||
{
|
||||
"field": "gust_ms",
|
||||
"op": ">=",
|
||||
"value": 13
|
||||
},
|
||||
{
|
||||
"field": "wind_ms",
|
||||
"op": "<",
|
||||
"value": 1,
|
||||
"cap": 30
|
||||
}
|
||||
],
|
||||
"limit_description": "전깃줄·나무 없는 넓은 곳인지는 반영하지 못해요",
|
||||
"sentences": {
|
||||
"0": "비가 오거나 돌풍이 불어요. 연이 날아가 버려요!",
|
||||
"30": "바람이 너무 약하거나 너무 세요. 뛰어다녀야 겨우 떠요.",
|
||||
"60": "연 띄울 만해요! 실은 넉넉하게 감아 가요.",
|
||||
"80": "초속 2~5m 딱 좋은 바람, 연이 하늘 높이 쭉쭉 🪁"
|
||||
},
|
||||
"sort_order": 32
|
||||
},
|
||||
{
|
||||
"code": "waterplay",
|
||||
"name": "물놀이각",
|
||||
"icon": "waterplay",
|
||||
"category": 1,
|
||||
"is_fun": false,
|
||||
"is_core": false,
|
||||
"has_detail": true,
|
||||
"description": "오전 11시~오후 5시, 바다·계곡에서 물놀이하기 좋은 정도",
|
||||
"windows": [
|
||||
{
|
||||
"from": 11,
|
||||
"to": 17
|
||||
}
|
||||
],
|
||||
"weight_temp": 40,
|
||||
"weight_rain": 25,
|
||||
"weight_wind": 10,
|
||||
"weight_humidity": 0,
|
||||
"weight_air": 0,
|
||||
"weight_uv": 0,
|
||||
"weight_sun": 20,
|
||||
"weight_view": 0,
|
||||
"weight_time": 5,
|
||||
"factor_rules": {
|
||||
"temp": {
|
||||
"type": "range",
|
||||
"lo": 27,
|
||||
"hi": 34,
|
||||
"best": 30
|
||||
},
|
||||
"rain": {
|
||||
"dir": "dry"
|
||||
},
|
||||
"wind": {
|
||||
"type": "calm",
|
||||
"ok": 4,
|
||||
"limit": 12
|
||||
},
|
||||
"humidity": {
|
||||
"type": "ignore"
|
||||
},
|
||||
"time": {
|
||||
"type": "weekday",
|
||||
"sat": 100,
|
||||
"sun": 100,
|
||||
"holiday": 100,
|
||||
"default": 60
|
||||
},
|
||||
"sun": {
|
||||
"zero": 0.2,
|
||||
"full": 0.8
|
||||
}
|
||||
},
|
||||
"zero_rules": [
|
||||
{
|
||||
"field": "rain_prob",
|
||||
"op": ">=",
|
||||
"value": 60
|
||||
},
|
||||
{
|
||||
"field": "feels_c",
|
||||
"op": "<",
|
||||
"value": 20
|
||||
}
|
||||
],
|
||||
"limit_description": "수온, 파도 높이, 계곡 물살은 반영하지 못해요",
|
||||
"sentences": {
|
||||
"0": "체감 20° 아래거나 비 소식이 있어요. 물놀이는 여름에!",
|
||||
"30": "물에 들어가면 으슬으슬해요. 발만 담그기!",
|
||||
"60": "물놀이 괜찮아요! 그늘막이랑 선크림 챙기기.",
|
||||
"80": "30° 안팎에 쨍쨍, 튜브 들고 풍덩 🏖️"
|
||||
},
|
||||
"sort_order": 33
|
||||
},
|
||||
{
|
||||
"code": "kimjang",
|
||||
"name": "김장각",
|
||||
"icon": "kimchi",
|
||||
"category": 3,
|
||||
"is_fun": false,
|
||||
"is_core": false,
|
||||
"has_detail": true,
|
||||
"description": "오전 9시~오후 4시, 김장하기 좋은 정도",
|
||||
"windows": [
|
||||
{
|
||||
"from": 9,
|
||||
"to": 16
|
||||
}
|
||||
],
|
||||
"weight_temp": 50,
|
||||
"weight_rain": 25,
|
||||
"weight_wind": 10,
|
||||
"weight_humidity": 0,
|
||||
"weight_air": 5,
|
||||
"weight_uv": 0,
|
||||
"weight_sun": 0,
|
||||
"weight_view": 0,
|
||||
"weight_time": 10,
|
||||
"factor_rules": {
|
||||
"temp": {
|
||||
"type": "range",
|
||||
"lo": 0,
|
||||
"hi": 10,
|
||||
"best": 5
|
||||
},
|
||||
"rain": {
|
||||
"dir": "dry"
|
||||
},
|
||||
"wind": {
|
||||
"type": "calm",
|
||||
"ok": 4,
|
||||
"limit": 10
|
||||
},
|
||||
"humidity": {
|
||||
"type": "ignore"
|
||||
},
|
||||
"time": {
|
||||
"type": "weekday",
|
||||
"sat": 100,
|
||||
"sun": 100,
|
||||
"holiday": 100,
|
||||
"default": 50
|
||||
}
|
||||
},
|
||||
"zero_rules": [
|
||||
{
|
||||
"field": "feels_c",
|
||||
"op": ">=",
|
||||
"value": 18
|
||||
}
|
||||
],
|
||||
"limit_description": "배추 작황과 값, 집집마다 김장 날짜는 반영하지 못해요",
|
||||
"sentences": {
|
||||
"0": "아직 18° 넘어요. 지금 담그면 김치가 금방 쉬어요!",
|
||||
"30": "조금 이르거나 손이 꽁꽁 얼어요. 날을 다시 골라 봐요.",
|
||||
"60": "김장할 만해요! 고무장갑 안에 면장갑 하나 더.",
|
||||
"80": "0~10°에 비 없고 바람 잔잔, 김장 날 잡는 날 🥬"
|
||||
},
|
||||
"sort_order": 34
|
||||
}
|
||||
]
|
||||
@@ -154,10 +154,15 @@ def humidity_score(rule: dict, humidity: float) -> tuple[int, str]:
|
||||
return 50, f"{note}, 이 각엔 상관없어 50점으로 둬요"
|
||||
|
||||
|
||||
def air_score(pm25: Optional[int], label: Optional[str]) -> tuple[int, str]:
|
||||
_AIR_RULE = {"zero": 75, "full": 15}
|
||||
|
||||
|
||||
def air_score(pm25: Optional[int], label: Optional[str], rule: Optional[dict] = None) -> tuple[int, str]:
|
||||
"""rule 이 없으면 맑을수록 좋음. 집콕각처럼 탁할수록 좋은 각은 {"zero": 15, "full": 75} 로 뒤집는다."""
|
||||
if pm25 is None:
|
||||
return _UNKNOWN, f"미세먼지 정보가 없어 {_UNKNOWN}점으로 둬요"
|
||||
return _linear(pm25, 75, 15), f"초미세먼지 {pm25}㎍/㎥{', ' + label if label else ''}"
|
||||
rule = rule or _AIR_RULE
|
||||
return _linear(pm25, rule["zero"], rule["full"]), f"초미세먼지 {pm25}㎍/㎥{', ' + label if label else ''}"
|
||||
|
||||
|
||||
def uv_score(rule: dict, uv: Optional[float]) -> tuple[int, str]:
|
||||
@@ -208,7 +213,8 @@ def axis_label(axis: str, rules: dict) -> str:
|
||||
if axis == "rain":
|
||||
return "비 옴" if rules["rain"]["dir"] == "wet" else "비 안 옴"
|
||||
if axis == "air":
|
||||
return "공기 맑음"
|
||||
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"]]
|
||||
|
||||
@@ -304,7 +310,7 @@ def evaluate(definition, windows: list[list[Hour]], ctx: Context) -> Optional[Re
|
||||
"rain": rain_score(rules["rain"], max_prob, raining, until if max_prob > own_prob else ""),
|
||||
"wind": wind_score(rules["wind"], max(winds) if winds else None),
|
||||
"humidity": humidity_score(rules["humidity"], mean(h.humidity for h in hours)),
|
||||
"air": air_score(ctx.pm25, ctx.air_label),
|
||||
"air": air_score(ctx.pm25, ctx.air_label, rules.get("air")),
|
||||
"uv": uv_score(rules["uv"], max(uvs, default=None)) if weights["uv"] else (0, ""),
|
||||
"sun": sun_score(rules["sun"], mean(suns) if suns else None) if weights["sun"] else (0, ""),
|
||||
"view": view_score(rules["view"], min(views, default=None)) if weights["view"] else (0, ""),
|
||||
|
||||
@@ -58,7 +58,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"]) == 27
|
||||
assert len(body["stories"]) == 34
|
||||
weather = next(p for p in body["posts"] if p["post_type"] == PostType.WEATHER.value)
|
||||
assert [s["kind"] for s in weather["slides"]] == ["hours", "hours"]
|
||||
assert len(weather["slides"][0]["hours"]) == 8
|
||||
|
||||
@@ -51,11 +51,11 @@ def fakes(monkeypatch):
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_index_list_ranks_all_27_with_today_tomorrow_weekend_trend(fakes):
|
||||
async def test_index_list_ranks_all_34_with_today_tomorrow_weekend_trend(fakes):
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
body = (await client.get("/v1/index/list", params={"region": REGION})).json()
|
||||
assert body["result"]["success"] is True
|
||||
assert len(body["items"]) == 27 and len(body["top3"]) == 3
|
||||
assert len(body["items"]) == 34 and len(body["top3"]) == 3
|
||||
scores = [i["score"] for i in body["items"]]
|
||||
assert scores == sorted(scores, reverse=True)
|
||||
today = now_kst().date()
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import json
|
||||
from dataclasses import replace
|
||||
from datetime import date, datetime, timezone
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from common.enums import RainType, Sky
|
||||
from services.calc.index_calc import (
|
||||
OUTING_HOURS, Context, DayForecast, Hour, axis_label, estimate, evaluate, hour_temp, outing, outing_estimate, rain_score, sun_score, temp_score,
|
||||
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,
|
||||
)
|
||||
from services.calc.moon import illumination
|
||||
@@ -222,3 +226,40 @@ def test_outing_estimate_from_mid_forecast():
|
||||
assert r.reason.startswith("비 20% · 낮 ")
|
||||
assert outing_estimate(_fc(pm=60)).score <= 30
|
||||
assert outing_estimate(_fc(lo=None, hi=None)) is None
|
||||
|
||||
|
||||
def test_air_rule_can_reverse_so_dusty_air_scores_high():
|
||||
rule = {"zero": 15, "full": 75}
|
||||
assert air_score(80, None, rule)[0] == 100 and air_score(10, None, rule)[0] == 0
|
||||
assert air_score(10, None)[0] == 100
|
||||
assert axis_label("air", {"air": rule}) == "공기 탁함" and axis_label("air", {}) == "공기 맑음"
|
||||
|
||||
|
||||
_SEED = {x["code"]: SimpleNamespace(**x) for x in json.loads((Path(__file__).parents[1] / "seed" / "index_definition.json").read_text(encoding="utf-8"))}
|
||||
_SAT, _WED = date(2026, 10, 10), date(2026, 10, 7)
|
||||
|
||||
|
||||
def _seed_score(code, day=_SAT, pm25=10, **hour):
|
||||
d = _SEED[code]
|
||||
windows = [[_h(h, **hour) for h in range(w["from"], w["to"])] for w in d.windows]
|
||||
return evaluate(d, windows, replace(CTX, day=day, pm25=pm25)).score
|
||||
|
||||
|
||||
@pytest.mark.parametrize("code, good, bad", [
|
||||
("golf", dict(feels=19.0, wind=2.0, hum=45), dict(feels=18.0, prob=80, rain=RainType.RAIN)),
|
||||
("jipkok", dict(feels=4.0, prob=90, rain=RainType.RAIN, wind=7.0, hum=85), dict(feels=20.0, wind=1.0, hum=40)),
|
||||
("fishing", dict(feels=22.0, wind=3.0), dict(feels=17.0, wind=11.0)),
|
||||
("drive", dict(feels=23.0, wind=4.0, hum=45, visibility_km=18.0), dict(feels=18.0, prob=80, rain=RainType.RAIN, visibility_km=5.0)),
|
||||
("kite", dict(feels=19.0, wind=6.0), dict(feels=14.0, wind=0.5)),
|
||||
("waterplay", dict(feels=28.0, wind=3.0, sunshine_ratio=0.7), dict(feels=18.0, wind=2.0, sunshine_ratio=0.3)),
|
||||
("kimjang", dict(feels=9.0, wind=3.0), dict(feels=20.0, wind=2.0)),
|
||||
])
|
||||
def test_new_gak_good_day_high_bad_day_low(code, good, bad):
|
||||
assert 80 <= _seed_score(code, pm25=60 if code == "jipkok" else 10, **good) < 100
|
||||
assert _seed_score(code, **bad) <= 30
|
||||
|
||||
|
||||
def test_new_gak_100_only_when_every_factor_is_perfect():
|
||||
perfect = dict(feels=19.5, wind=1.0, hum=35)
|
||||
assert _seed_score("golf", **perfect) == 100
|
||||
assert _seed_score("golf", day=_WED, **perfect) < 100
|
||||
Reference in new issue
Block a user