-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
25 lines (22 loc) · 828 Bytes
/
main.py
File metadata and controls
25 lines (22 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from fastapi import FastAPI, HTTPException
import json
import os
app = FastAPI()
DATA_DIR = "data/processed"
@app.get("/analyze/{year}")
def get_analysis(year: str):
file_path = os.path.join(DATA_DIR, f"stress_{year}.json")
if not os.path.exists(file_path):
raise HTTPException(status_code=404, detail="Data not found")
with open(file_path, "r") as f:
return json.load(f)
@app.get("/stats/annual_outbreak_counts")
def get_annual_outbreak_counts():
all_stats = []
for year in range(1984, 2026):
file_path = os.path.join(DATA_DIR, f"stress_{year}.json")
if os.path.exists(file_path):
with open(file_path, "r") as f:
data = json.load(f)
all_stats.append({"year": year, "outbreak_count": data["outbreak_count"]})
return all_stats