Add 3 new data-driven insight cards (daily cases, district risk comparison, weather impact) with real parquet data. Fix season card to use current date instead of data date. Expand to 11 cards. Add POST /api/chat endpoint proxying to ai.2890.ltd with JWT auth. Create ChatBot frontend component with collapsible chat panel, message bubbles, and auto-scroll. Chat API key stored in .env only. Clean up duplicate typing imports in insights.py, export cachedPost.
94 lines
3.0 KiB
Python
94 lines
3.0 KiB
Python
"""
|
|
Centralized configuration and named constants for CBPOA backend.
|
|
Eliminates magic numbers scattered across routers.
|
|
"""
|
|
import os
|
|
from pathlib import Path
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
|
|
# ============================================================================
|
|
# Paths
|
|
# ============================================================================
|
|
|
|
PROJECT_ROOT = Path(__file__).parent.parent
|
|
DATA_DIR = PROJECT_ROOT / "outputs" / "daily"
|
|
REPORTS_DIR = PROJECT_ROOT / "outputs" / "reports"
|
|
WUHAN_BOUNDARY_PATH = PROJECT_ROOT / "Datas" / "武汉市.geojson"
|
|
PRECOMPUTED_GRID_PATH = PROJECT_ROOT / "outputs" / "grid_risk_summary.csv"
|
|
|
|
# ============================================================================
|
|
# Wuhan Geographic Bounds
|
|
# ============================================================================
|
|
|
|
WUHAN_BOUNDS = {
|
|
"min_lon": 113.702281,
|
|
"max_lon": 115.082378,
|
|
"min_lat": 29.969132,
|
|
"max_lat": 31.361260,
|
|
}
|
|
|
|
# 100m grid step in degrees (at Wuhan center latitude ~30.66)
|
|
LAT_STEP = 0.0009
|
|
LON_STEP = 0.001046
|
|
|
|
# ============================================================================
|
|
# Risk Thresholds
|
|
# ============================================================================
|
|
|
|
RISK_HIGH = 0.8
|
|
RISK_MEDIUM_HIGH = 0.6
|
|
RISK_MEDIUM = 0.4
|
|
RISK_MEDIUM_LOW = 0.2
|
|
|
|
# ============================================================================
|
|
# LOD Configuration
|
|
# ============================================================================
|
|
|
|
LOD_GRID_DIMS = {
|
|
"lod1": {"lat_count": 100, "lon_count": 150},
|
|
"lod2": {"lat_count": 250, "lon_count": 350},
|
|
"lod3": {"lat_count": 1400, "lon_count": 2000},
|
|
}
|
|
|
|
LOD_CONFIG = {
|
|
"lod1": {"zoom_range": (1, 9), "aggregate": 200, "name": "coarse"},
|
|
"lod2": {"zoom_range": (10, 13), "aggregate": 50, "name": "medium"},
|
|
"lod3": {"zoom_range": (14, 20), "aggregate": 1, "name": "fine"},
|
|
}
|
|
|
|
# Max radius for KDTree neighbor lookup (degrees, ~5km)
|
|
LOD_MAX_RADIUS = 0.05
|
|
|
|
# ============================================================================
|
|
# Alert Thresholds
|
|
# ============================================================================
|
|
|
|
ALERT_P1_RISK = 0.8
|
|
ALERT_P2_RISK = 0.6
|
|
ALERT_RISK_7D_WEIGHT = 0.5
|
|
MAX_ALERTS = 2000
|
|
|
|
# ============================================================================
|
|
# Trend Analysis
|
|
# ============================================================================
|
|
|
|
TREND_SLOPE_THRESHOLD = 0.05
|
|
|
|
# ============================================================================
|
|
# Date Format
|
|
# ============================================================================
|
|
|
|
DATE_FORMAT_GEOJSON = "%Y%m%d"
|
|
DATE_FORMAT_ISO = "%Y-%m-%d"
|
|
|
|
# ============================================================================
|
|
# Chat Proxy Configuration
|
|
# ============================================================================
|
|
|
|
CHAT_API_KEY = os.getenv("CHAT_API_KEY", "")
|
|
CHAT_API_BASE = os.getenv("CHAT_API_BASE", "https://ai.2890.ltd/v1")
|
|
CHAT_MODEL = os.getenv("CHAT_MODEL", "gpt-4o-mini")
|