Skip to content

Commit 364ea44

Browse files
committed
对外预测接口增加逐模型逐小时曲线
1 parent 5a78258 commit 364ea44

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎tests/test_city_forecast_api.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ def _fake_analyze(city, force_refresh=False, detail_mode="panel"):
3131
},
3232
"multi_model": {
3333
"model_keys": ["ecmwf", "gfs", "deb"],
34+
"hourly_times": [
35+
"2026-08-16T13:00",
36+
"2026-08-16T14:00",
37+
],
38+
"hourly_forecasts": {
39+
"ecmwf": [32.1, 33.2],
40+
"gfs": [31.8, 32.8],
41+
},
3442
"daily_forecasts": {
3543
"2026-08-16": {"ecmwf": 33.2, "gfs": 32.8, "deb": 33.5},
3644
"2026-08-17": {"ecmwf": 34.0, "gfs": 33.1, "deb": 34.2},
@@ -75,6 +83,11 @@ def test_deb_forecast_default_watchlist_shape(monkeypatch):
7583
assert beijing["deb_prediction"] == 33.5
7684
assert "ECMWF" in beijing["deb_weights"]
7785
assert beijing["models_daily"]["2026-08-17"]["gfs"] == 33.1
86+
assert beijing["models_hourly"]["times"] == [
87+
"2026-08-16T13:00",
88+
"2026-08-16T14:00",
89+
]
90+
assert beijing["models_hourly"]["curves"]["ecmwf"] == [32.1, 33.2]
7891
assert beijing["forecast_daily"][0]["max_temp"] == 33.0
7992
assert beijing["local_date"] == "2026-08-16"
8093

‎web/routers/city_forecast.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,23 @@ def _build_city_forecast(city: str) -> Optional[Dict[str, Any]]:
100100
)
101101
forecast = data.get("forecast") if isinstance(data.get("forecast"), dict) else {}
102102
daily_forecasts = multi_model.get("daily_forecasts") or {}
103+
hourly_times = multi_model.get("hourly_times") or []
104+
hourly_forecasts = multi_model.get("hourly_forecasts") or {}
103105

104106
return {
105107
"local_date": data.get("local_date"),
106108
"local_time": data.get("local_time"),
109+
"utc_offset_seconds": data.get("utc_offset_seconds"),
107110
"temp_symbol": data.get("temp_symbol"),
108111
"deb_prediction": deb.get("prediction"),
109112
"deb_weights": deb.get("weights_info"),
110113
"deb_quality": deb.get("quality_tier"),
111114
"forecast_daily": forecast.get("daily") or [],
112115
"models_daily": daily_forecasts,
116+
"models_hourly": {
117+
"times": hourly_times,
118+
"curves": hourly_forecasts,
119+
},
113120
"model_keys": multi_model.get("model_keys") or [],
114121
}
115122

0 commit comments

Comments
 (0)