Context: Build a spatial risk assessment system correlating air quality data with children's respiratory disease incidence across Wuhan. Approach: FastAPI backend serving PostGIS spatial queries, React frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline for multi-day (1d/3d/7d) risk prediction. Changes: - backend/ — FastAPI API with auth (JWT), alerts, risk analysis, geocoded case data, grid statistics, and report endpoints - frontend/ — React dashboard with interactive risk maps, alert monitoring, district comparison charts, and timeline player - models/ — SpatialTemporalGCN model with trained weights and ONNX export for inference - scripts/ — ETL pipeline for weather + medical data, grid generation, feature engineering, training, and daily inference - deploy/ — Docker Compose configs for backend, frontend, and MLflow - docs/ — API docs, deployment guide, user guide, and code review Impact: Enables spatial risk visualization, alert monitoring, and ML-driven health risk forecasting for environmental health teams.
51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
"""
|
|
Date utilities: finding latest dates from GeoJSON files, parsing date strings.
|
|
"""
|
|
import glob
|
|
import re
|
|
from pathlib import Path
|
|
|
|
from fastapi import HTTPException
|
|
|
|
from config import DATA_DIR, DATE_FORMAT_GEOJSON
|
|
|
|
|
|
def get_latest_date() -> str:
|
|
"""Get latest available date from GeoJSON files in DATA_DIR."""
|
|
pattern = str(DATA_DIR / "risk_*.geojson")
|
|
files = glob.glob(pattern)
|
|
if not files:
|
|
raise HTTPException(status_code=500, detail="No risk data files found")
|
|
|
|
dates = []
|
|
for f in files:
|
|
match = re.search(r"risk_(\d{8})\.geojson", f)
|
|
if match:
|
|
dates.append(match.group(1))
|
|
|
|
if not dates:
|
|
raise HTTPException(status_code=500, detail="No valid risk data files found")
|
|
|
|
return max(dates)
|
|
|
|
|
|
def get_available_dates(days: int = 30) -> list[str]:
|
|
"""Get list of available dates, most recent first."""
|
|
pattern = str(DATA_DIR / "risk_*.geojson")
|
|
files = glob.glob(pattern)
|
|
|
|
dates: list[str] = []
|
|
for f in files:
|
|
match = re.search(r"risk_(\d{8})\.geojson", f)
|
|
if match:
|
|
dates.append(match.group(1))
|
|
|
|
dates.sort(reverse=True)
|
|
return dates[:days]
|
|
|
|
|
|
def validate_date_format(date: str) -> bool:
|
|
"""Check if date string matches YYYYMMDD format."""
|
|
import re
|
|
return bool(re.compile(r"^\d{8}$").match(date))
|