6c08a68413
性能与用户体验全面优化
前端性能:
- 移除 Three.js 依赖(~600KB),天气粒子改为纯 CSS 动画 + Canvas 2D
- Google Fonts 切换为 next/font 自托管,消除跨域字体请求
- 合并 ScanTerminalLightTheme.module.css (37KB) 到主 CSS,亮/暗主题统一用 CSS 变量
- 新增 /api/dashboard/init 聚合端点,首次加载 4 次往返 → 1 次
- 添加 Service Worker 静态资源缓存,修复 PWA manifest 配置
用户体验:
- 新增全局错误边界 error.tsx / global-error.tsx,崩溃不再白屏
- 决策卡和城市详情的更新时间改为相对时间("15秒前"),每秒自动刷新
- 数据陈旧时状态标签从青色切换为琥珀色提示
DEB 算法增强:
- 市场扫描路径接入 Open-Meteo 多模型数据(ECMWF/GFS/ICON/JMA/HRDPS 等)
- MAE 计算加入时间衰减(decay_factor=0.85),近期模型误差权重更高
Scope-risk: MEDIUM — 全量 170 测试通过,前端 TypeScript/build 通过,ruff 零告警
Tested: python -m pytest -q (170 passed), npx tsc --noEmit (0 errors), npm run build (success), ruff check .
@
70 lines
1.8 KiB
Python
70 lines
1.8 KiB
Python
"""System and observability API routes for PolyWeather."""
|
|
|
|
from typing import Optional
|
|
|
|
from fastapi import APIRouter, BackgroundTasks, Request
|
|
from fastapi.responses import PlainTextResponse
|
|
|
|
from web.services.dashboard_init_api import build_dashboard_init_payload
|
|
from web.services.system_api import (
|
|
get_health_payload,
|
|
get_prometheus_metrics_response,
|
|
get_system_cache_status,
|
|
get_system_status_payload,
|
|
run_system_prewarm,
|
|
run_system_priority_warm,
|
|
)
|
|
|
|
router = APIRouter(tags=["system"])
|
|
|
|
|
|
@router.get("/healthz")
|
|
async def healthz():
|
|
return get_health_payload()
|
|
|
|
|
|
@router.get("/api/system/status")
|
|
async def system_status():
|
|
return await get_system_status_payload()
|
|
|
|
|
|
@router.post("/api/system/prewarm")
|
|
async def system_prewarm(
|
|
request: Request,
|
|
cities: Optional[str] = None,
|
|
force_refresh: bool = False,
|
|
include_detail: bool = False,
|
|
include_market: bool = False,
|
|
):
|
|
return run_system_prewarm(
|
|
request,
|
|
cities=cities,
|
|
force_refresh=force_refresh,
|
|
include_detail=include_detail,
|
|
include_market=include_market,
|
|
)
|
|
|
|
|
|
@router.get("/api/system/cache-status")
|
|
async def system_cache_status(request: Request, cities: Optional[str] = None):
|
|
return get_system_cache_status(request, cities=cities)
|
|
|
|
|
|
@router.post("/api/system/priority-warm")
|
|
async def system_priority_warm(
|
|
request: Request,
|
|
background_tasks: BackgroundTasks,
|
|
timezone: Optional[str] = None,
|
|
):
|
|
return run_system_priority_warm(request, background_tasks, timezone=timezone)
|
|
|
|
|
|
@router.get("/metrics", response_class=PlainTextResponse)
|
|
async def metrics():
|
|
return get_prometheus_metrics_response()
|
|
|
|
|
|
@router.get("/api/dashboard/init")
|
|
async def dashboard_init(request: Request):
|
|
return await build_dashboard_init_payload(request)
|