No description
  • Python 43.9%
  • Vue 34.6%
  • CSS 16.9%
  • PowerShell 3%
  • JavaScript 1.2%
  • Other 0.4%
Find a file
rainyblue a03ebc637f test
2026-09-02 09:33:03 +08:00
frontend test 2026-09-02 09:33:03 +08:00
database.py test 2026-09-02 09:33:03 +08:00
main.py test 2026-09-02 09:33:03 +08:00
models.py test 2026-09-02 09:33:03 +08:00
README.md test 2026-09-02 09:33:03 +08:00
requirements.txt test 2026-09-02 09:33:03 +08:00
schema.sql test 2026-09-02 09:33:03 +08:00
start.ps1 test 2026-09-02 09:33:03 +08:00

台风大数据分析后端

FastAPI 只向前端输出 MySQL 中的清洗数据和后端计算结果。台风说原始响应 仅用于后台同步,不存在原样透传路由。

运行

要求 Python 3.10+、MySQL 8.0+。

python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt
Copy-Item .env.example .env
mysql -u root -p < schema.sql

编辑 .env 中的数据库配置。默认已对接台风说公开 V1 接口,该接口无需 密钥。首次导入历史数据并生成年度统计、路径聚类:

python main.py sync --years 2020 2021 2022 2023 2024 2025 2026

启动 API

python main.py serve --host 0.0.0.0 --port 8000

OpenAPI 文档位于 http://127.0.0.1:8000/docs

本地接口

  • GET /api/typhoon/years
  • GET /api/typhoon/list?year=2026
  • GET /api/typhoon/detail/{typhoon_code}
  • GET /api/typhoon/search?kw=台风名
  • GET /api/typhoon/stat/year?year=2026
  • GET /api/typhoon/cluster

所有成功响应均为 {"code": 200, "data": ...}。详情接口中的 metrics 和每个路径点的 intensity_change_rate_mps_24h 为后端衍生数据; 年度统计与空间聚类分别从 typhoon_stat_yeartyphoon_path_cluster 读取预计算结果。

离线任务

# 仅重算年度统计
python main.py aggregate

# 仅重算路径 DBSCAN
python main.py cluster

一键启动

.\start.ps1

脚本会自动检查 MySQL3306、启动后端8000和前端5173等待 就绪后打开浏览器,按 Ctrl+C 同时关闭两个服务。

服务内置 APScheduler每日按 .env 的时间运行采集、聚合和聚类。生产环境 多进程部署时应仅在一个独立 worker 中设置 ENABLE_SCHEDULER=true,避免 多个进程重复执行任务。