From 305e2e7a6b593650bf95f50b2b3032ee64790840 Mon Sep 17 00:00:00 2001 From: "2569718930@qq.com" <2569718930@qq.com> Date: Fri, 27 Feb 2026 22:08:13 +0800 Subject: [PATCH] feat: auto-prune DEB records older than 14 days to prevent unbounded growth --- src/analysis/deb_algorithm.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/analysis/deb_algorithm.py b/src/analysis/deb_algorithm.py index c37d2bc4..db544569 100644 --- a/src/analysis/deb_algorithm.py +++ b/src/analysis/deb_algorithm.py @@ -70,6 +70,13 @@ def update_daily_record(city_name, date_str, forecasts, actual_high): # 只要仍在更新或者已经结束,都记录最新高点 data[city_name][date_str]['actual_high'] = actual_high + # 自动清理:只保留最近 14 天的记录(DEB 只用 7 天,14 天留足余量) + cutoff = (datetime.now() - timedelta(days=14)).strftime("%Y-%m-%d") + for city in list(data.keys()): + old_dates = [d for d in data[city] if d < cutoff] + for d in old_dates: + del data[city][d] + save_history(history_file, data) def calculate_dynamic_weights(city_name, current_forecasts, lookback_days=7):