feat: 지금 날씨를 초단기실황 관측값으로, 각 점수에서 시간대 알맞음 제거·우산각 계산식 변경
- 초단기실황(getUltraSrtNcst)을 받아 지금 정시 한 시각의 비·기온·습도·바람을 예보 대신 관측값으로 덮어씀 (체감·불쾌지수는 다시 계산). 지역별 1시간 캐시, 실패하면 초단기예보·단기예보로 되돌아감, 새 시각 실황이 나오면 각 점수를 다시 계산. 가이드대로 ±900 이상은 결측 처리. 테스트가 실제 기상청을 부르지 않게 실황 호출을 기본으로 막음 - 시간대 알맞음 요소를 31개 각에서 빼고 비중을 5% 단위로 나눔. 요소가 3개 미만이 된 뜨아각·파전각·감성노래각·감사각·선크림각에 요소를 더함. 러닝각의 활동 시간대 밖 점수 상한도 없앰. 요소가 하나뿐인 각은 가장 낮은 요소로 깎지 않음 - 우산각은 비 한 가지: 남은 하루(지금~자정) 비 확률 평균이 점수, 지금 비가 오면 70점에서 시작해 평균 × 30점을 더함. 내일·토·일 칸은 그날 6~24시 평균 × 100. 우산분실각도 비 한 가지 - 각 계산 기준 문서는 생성기를 새 규칙에 맞게 고쳐 다시 생성, 점수 계산식·서비스 동작 안내 문서 갱신
This commit is contained in:
1 parent
8ea9f8f04b
commit
5ab2381f79
19 files changed
+737
-243
No files matched your search
@@ -5,6 +5,7 @@ import pytest
|
||||
from httpx import ASGITransport, AsyncClient
|
||||
|
||||
import services.air_service as air_service
|
||||
import services.index_service as index_service
|
||||
import services.warning_service as warning_service
|
||||
import services.weather_service as weather_service
|
||||
from common.database.db_session_manager import DB_SESSION_MNG
|
||||
@@ -91,6 +92,53 @@ async def test_index_list_ranks_every_gak_with_today_tomorrow_weekend_trend(fake
|
||||
assert 0 <= body["weather_score"] <= 100
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_index_list_asks_for_the_observed_weather_once(fakes, monkeypatch):
|
||||
calls = []
|
||||
|
||||
async def fake_ncst(client, nx, ny, base):
|
||||
calls.append(base)
|
||||
return []
|
||||
|
||||
monkeypatch.setattr(weather_service, "fetch_ncst", fake_ncst)
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
assert (await client.get("/v1/index/list", params={"region": REGION})).json()["result"]["success"] is True
|
||||
assert len(calls) == 1
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_index_scores_are_recomputed_once_the_new_hours_observation_is_out(fakes, monkeypatch):
|
||||
"""14:05 에 계산한 점수는 14:08 에 그대로 쓰고, 14시 실황이 나오는 14:10 이후엔 다시 계산한다."""
|
||||
day = kst_midnight(now_kst().date())
|
||||
clock = [day + timedelta(hours=14, minutes=5)]
|
||||
computed = []
|
||||
real_day_result = index_service.day_result
|
||||
|
||||
def counting(*a, **k):
|
||||
computed.append(1)
|
||||
return real_day_result(*a, **k)
|
||||
|
||||
async def observed(*_a):
|
||||
return [{"category": c, "obsrValue": v} for c, v in {"PTY": "0", "REH": "50", "RN1": "0", "T1H": "21", "WSD": "1.5"}.items()]
|
||||
|
||||
monkeypatch.setattr(index_service, "now_kst", lambda: clock[0])
|
||||
monkeypatch.setattr(index_service, "day_result", counting)
|
||||
monkeypatch.setattr(weather_service, "fetch_ncst", observed)
|
||||
monkeypatch.setattr(air_service, "fetch_realtime", lambda *a: _async([{
|
||||
"stationName": "신촌동", "pm25Value": "10", "pm10Value": "20", "pm25Grade": "1", "pm10Grade": "1", "dataTime": f"{day:%Y-%m-%d} 14:00",
|
||||
}]))
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
await client.get("/v1/index/list", params={"region": REGION})
|
||||
first = len(computed)
|
||||
assert first > 0
|
||||
clock[0] = day + timedelta(hours=14, minutes=8)
|
||||
await client.get("/v1/index/list", params={"region": REGION})
|
||||
assert len(computed) == first
|
||||
clock[0] = day + timedelta(hours=14, minutes=12)
|
||||
await client.get("/v1/index/list", params={"region": REGION})
|
||||
assert len(computed) > first
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_index_list_filters_core_to_gak_in_season_now(fakes):
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
|
||||
Reference in new issue
Block a user