feat: auto-prune DEB records older than 14 days to prevent unbounded growth

This commit is contained in:
2569718930@qq.com
2026-02-27 22:08:13 +08:00
parent 2c3cbe9826
commit 305e2e7a6b
+7
View File
@@ -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):