feat: 주말 나들이 점수를 평균 60 정규분포로 보정, 지금 날씨·나들이 점수 100점은 완벽한 날만
- 나들이 점수(주말 전국 순위·당일치기)에 지금 날씨 점수와 같은 방식의 바꾸기 표를 적용: 원래 점수를 1년 치 분포의 순위로 보고 평균 60·표준편차 15 정규분포 점수로 바꿈 (weekend_rank.py, outing_score_table.json, scripts/gen_outing_score_table.py) - 나들이 점수 만점 조건을 엄격하게: 체감온도 최적 21°±0.5°, 바람 초속 1m 이하일 때만 100점 (같은 예보를 받는 여러 지역이 한꺼번에 100점이 되던 것을 줄임) - 표 맨 위가 100으로 잘려 비슷한 원래 점수(96·97·99)가 모두 100점이 되던 것을 막기 위해 straighten_top 추가: 표시 점수 83 이하인 마지막 원래 점수에서 100점까지 직선으로 이어, 100점은 구간에서 나올 수 있는 가장 높은 원래 점수(밤은 85)일 때만 나옴. 지금 날씨 점수 표도 다시 만듦 (90점 이상 약 2.4% → 1.5%) - 당일치기 최소 점수는 원래 50점과 같은 날씨 수준(표시 62점)으로 옮김 - 주말 순위 캐시 키를 weekend_rank:v2:<날짜>로 올려 옛 점수 캐시를 쓰지 않게 함 - 테스트 추가: test_outing_score_table, test_weather_score_table(straighten_top·100점 조건) - docs/점수_계산식.md의 지금 날씨 점수·나들이 점수 항목을 새 기준과 숫자로 갱신
This commit is contained in:
1 parent
b2470d80ed
commit
0edb7059c8
9 files changed
+337
-39
No files matched your search
@@ -0,0 +1,76 @@
|
||||
"""나들이 점수 바꾸기 표(services/calc/outing_score_table.json)를 다시 만든다.
|
||||
|
||||
나들이 점수(index_calc.outing: 낮 10~17시, 기온·비·하늘·바람)의 원래 점수를 1년 치 분포의 순위로 보고,
|
||||
평균 60·표준편차 15 정규분포의 같은 위치 점수로 바꾼다 (지금 날씨 점수와 같은 방식, scripts/gen_weather_score_table.py).
|
||||
1년 치 날씨는 Open-Meteo 과거 예보로, region.csv 에서 8개마다 1곳(32곳)을 쓴다. 하늘은 구름양 40%·80% 이상을 구름 많음·흐림으로 본다.
|
||||
|
||||
나들이 점수 규칙(OUTING_*)이 바뀌면 실행: cd backend && python scripts/gen_outing_score_table.py
|
||||
"""
|
||||
|
||||
import csv
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
from datetime import date, timedelta
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from common.enums import RainType, Sky # noqa: E402
|
||||
from common.logger import LOG # noqa: E402
|
||||
from scripts.gen_weather_score_table import _WEATHER, DAYS, EVERY, MEAN, SIGMA, fetch, straighten_top, table # noqa: E402
|
||||
from services.calc.index_calc import OUTING_HOURS, Hour, outing # noqa: E402
|
||||
|
||||
BACKEND = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
REGIONS = os.path.join(BACKEND, "seed", "region.csv")
|
||||
OUT = os.path.join(BACKEND, "services", "calc", "outing_score_table.json")
|
||||
_HOURLY = "apparent_temperature,precipitation,precipitation_probability,wind_speed_10m,cloud_cover"
|
||||
|
||||
|
||||
def region_scores(lat: float, lon: float, start: date, end: date) -> list[int]:
|
||||
"""한 지점의 날마다 나들이 점수(원래 점수). 10~17시가 모두 있는 날만."""
|
||||
base = dict(latitude=lat, longitude=lon, start_date=start.isoformat(), end_date=end.isoformat(), timezone="Asia/Seoul")
|
||||
w = fetch(_WEATHER, base | dict(hourly=_HOURLY, wind_speed_unit="ms"))["hourly"]
|
||||
at_index = {t: i for i, t in enumerate(w["time"])}
|
||||
out = []
|
||||
day = start
|
||||
while day <= end:
|
||||
hours = []
|
||||
for h in range(*OUTING_HOURS):
|
||||
i = at_index.get(f"{day.isoformat()}T{h:02d}:00")
|
||||
if i is None or w["apparent_temperature"][i] is None:
|
||||
break
|
||||
cloud = w["cloud_cover"][i] or 0
|
||||
hours.append(Hour(
|
||||
hour=h, feels_c=w["apparent_temperature"][i], rain_type=RainType.RAIN if (w["precipitation"][i] or 0) >= 0.1 else RainType.NONE,
|
||||
rain_prob=int(w["precipitation_probability"][i] or 0), wind_ms=w["wind_speed_10m"][i], humidity=50,
|
||||
sky=Sky.CLOUDY if cloud >= 80 else Sky.PARTLY if cloud >= 40 else Sky.CLEAR,
|
||||
))
|
||||
result = outing(hours) if len(hours) == OUTING_HOURS[1] - OUTING_HOURS[0] else None
|
||||
if result is not None:
|
||||
out.append(result.score)
|
||||
day += timedelta(days=1)
|
||||
return out
|
||||
|
||||
|
||||
def main() -> None:
|
||||
end = date.today() - timedelta(days=2)
|
||||
start = end - timedelta(days=DAYS)
|
||||
regions = list(csv.DictReader(open(REGIONS, encoding="utf-8")))[::EVERY]
|
||||
scores: list[int] = []
|
||||
for r in regions:
|
||||
scores += region_scores(float(r["lat"]), float(r["lon"]), start, end)
|
||||
LOG.info(f"[outing-table] {r['name']} 완료")
|
||||
time.sleep(1)
|
||||
doc = {
|
||||
"about": f"나들이 점수 바꾸기 표: 원래 점수 0~100 → 표시 점수. 평균 {MEAN}·표준편차 {SIGMA}. scripts/gen_outing_score_table.py 가 만든다",
|
||||
"period": [start.isoformat(), end.isoformat()], "regions": len(regions), "samples": len(scores),
|
||||
"table": straighten_top(table(scores)), # 100점은 원래 점수 100(완벽한 날)일 때만
|
||||
}
|
||||
with open(OUT, "w", encoding="utf-8") as f:
|
||||
json.dump(doc, f, ensure_ascii=False, indent=1)
|
||||
print(len(regions), "regions", len(scores), "samples")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,7 +1,7 @@
|
||||
"""지금 날씨 점수 바꾸기 표(services/calc/weather_score_table.json)를 다시 만든다.
|
||||
|
||||
지금 날씨 점수 공식(WEATHER_SCORE_DEF)으로 나온 원래 점수를 구간(아침·낮·저녁·밤)마다 1년 치 분포의 순위로 바꾼 뒤,
|
||||
평균 60·표준편차 15 정규분포의 같은 위치 점수로 바꾼다. 90점 이상은 구간마다 약 2.5%가 나온다.
|
||||
평균 60·표준편차 15 정규분포의 같은 위치 점수로 바꾼다. 90점 이상은 구간마다 약 2.5%가 나온다. 맨 위는 straighten_top 으로 100점이 가장 좋은 원래 점수에서만 나오게 한다.
|
||||
1년 치 날씨는 Open-Meteo 과거 예보(강수확률 포함)와 대기질(초미세먼지)로, region.csv 에서 8개마다 1곳(32곳)을 쓴다.
|
||||
|
||||
WEATHER_SCORE_DEF 가 바뀌면 실행: cd backend && python scripts/gen_weather_score_table.py
|
||||
@@ -109,6 +109,20 @@ def table(scores: list[int]) -> list[int]:
|
||||
return out
|
||||
|
||||
|
||||
ANCHOR_SCORE = 83 # 위쪽 끝을 직선으로 잇기 시작하는 표시 점수
|
||||
|
||||
|
||||
def straighten_top(t: list[int], top: int = 100) -> list[int]:
|
||||
"""표 맨 위가 100으로 잘려 비슷한 원래 점수(96·97·99)가 모두 100점이 되던 것을 막는다.
|
||||
표시 점수가 ANCHOR_SCORE 이하인 마지막 원래 점수에서 top(그 구간에서 나올 수 있는 가장 높은 원래 점수)의 100점까지 직선으로 잇는다.
|
||||
100점은 원래 점수가 top 이상일 때만 나온다. 그 아래 점수는 바뀌지 않는다."""
|
||||
anchor = max(i for i, v in enumerate(t[: top + 1]) if v <= ANCHOR_SCORE)
|
||||
out = list(t)
|
||||
for raw in range(anchor + 1, 101):
|
||||
out[raw] = 100 if raw >= top else min(99, round(t[anchor] + (100 - t[anchor]) * (raw - anchor) / (top - anchor)))
|
||||
return out
|
||||
|
||||
|
||||
def main() -> None:
|
||||
end = date.today() - timedelta(days=2)
|
||||
start = end - timedelta(days=DAYS)
|
||||
@@ -122,7 +136,8 @@ def main() -> None:
|
||||
doc = {
|
||||
"about": f"지금 날씨 점수 바꾸기 표: 원래 점수 0~100 → 표시 점수. 평균 {MEAN}·표준편차 {SIGMA}. scripts/gen_weather_score_table.py 가 만든다",
|
||||
"period": [start.isoformat(), end.isoformat()], "regions": len(regions), "samples": {s: len(v) for s, v in scores.items()},
|
||||
"slots": {s: table(v) for s, v in scores.items()},
|
||||
# 밤은 해 난 비율이 늘 0점이라 원래 점수가 100 - 그 비중까지만 나온다
|
||||
"slots": {s: straighten_top(table(v), 100 - WEATHER_SCORE_DEF.weight_sun if s == "night" else 100) for s, v in scores.items()},
|
||||
}
|
||||
with open(OUT, "w", encoding="utf-8") as f:
|
||||
json.dump(doc, f, ensure_ascii=False, indent=1)
|
||||
|
||||
Reference in new issue
Block a user