chore: add test infrastructure and update risk router
- Add vitest config and unit tests for components, api, stores - Add Playwright e2e test for user flows - Add backend test files - Update risk.py with LOD grid KDTree optimization
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
Router for CBPOA risk assessment endpoints
|
||||
Reads from GeoJSON files in outputs/daily/ directory
|
||||
"""
|
||||
from fastapi import APIRouter, HTTPException, Query
|
||||
from fastapi import APIRouter, HTTPException, Path, Query
|
||||
from datetime import datetime, timedelta
|
||||
from pathlib import Path
|
||||
from typing import Annotated, List, Literal
|
||||
@@ -420,7 +420,7 @@ async def get_risk_history(grid_id: str, days: int = 7):
|
||||
|
||||
@router.get("/forecast/{days}", response_model=RiskMapResponse)
|
||||
async def get_forecast_map(
|
||||
days: Annotated[int, Query(ge=1, le=7, description="Forecast horizon in days")]
|
||||
days: Annotated[int, Path(ge=1, le=7, description="Forecast horizon in days")]
|
||||
):
|
||||
"""
|
||||
Get forecast risk map for specified horizon (1, 3, or 7 days).
|
||||
@@ -439,23 +439,16 @@ async def get_forecast_map(
|
||||
raise HTTPException(status_code=404, detail="No grid data found")
|
||||
|
||||
# Adjust risk values by forecast horizon (small noise proportional to days)
|
||||
rng = np.random.default_rng(hash(days + latest_date) % (2**31))
|
||||
rng = np.random.default_rng(hash(str(days) + latest_date) % (2**31))
|
||||
result = []
|
||||
for g in grids[:5000]:
|
||||
adjusted = min(1.0, max(0.0, g["risk_value"] + (rng.random() - 0.5) * 0.1 * days))
|
||||
risk_level = (
|
||||
"high" if adjusted >= 0.7 else
|
||||
"medium_high" if adjusted >= 0.5 else
|
||||
"medium" if adjusted >= 0.3 else
|
||||
"medium_low" if adjusted >= 0.2 else
|
||||
"low"
|
||||
)
|
||||
result.append(GridRisk(
|
||||
grid_id=g["grid_id"],
|
||||
latitude=g.get("latitude", 0),
|
||||
longitude=g.get("longitude", 0),
|
||||
risk_value=round(adjusted, 4),
|
||||
risk_level=risk_level
|
||||
risk_level=risk_value_to_level(adjusted)
|
||||
))
|
||||
|
||||
return RiskMapResponse(
|
||||
|
||||
Reference in New Issue
Block a user