架构重构:拆分 core/ops/DBManager,统一 SQLite 锁,DEB 改进,新增注意力模型

- web/core.py 858→236行,拆出 schemas/middleware/auth/diagnostics
- ops_api.py 2876→4个 domain 模块 (users/payments/health/config)
- DBManager Supabase HTTP 调用提取到 SupabaseAdminClient
- 新增 LockedSQLiteConnection 统一多进程读写锁
- 新增 WeatherCacheManager 替代 12 个独立缓存字典
- METAR 缓存迁移至统一缓存管理器
- analysis_service 提取 _build_intraday_meteorology 到独立模块
- DEB 改进:偏差惩罚、分歧回退、自适应 lookback (MAE ↓12.6%)
- 新增 PyTorch 注意力模型 deb_attention.py (数据积累后启用)
- 新增 torch 到 requirements.lock
This commit is contained in:
2569718930@qq.com
2026-06-16 02:00:22 +08:00
parent ed0447f408
commit dca4f2d618
26 changed files with 5010 additions and 3974 deletions
+2
View File
@@ -28,6 +28,8 @@ class _DummyMetarSource(MetarSourceMixin):
def __init__(self):
self._metar_cache = {}
self._metar_cache_lock = threading.Lock()
from src.data_collection.weather_cache import WeatherCacheManager
self.cache = WeatherCacheManager()
self.metar_timeout_sec = 0.0
self.metar_latest_timeout_sec = 0.0
self.timeout = 0.0
+2 -1
View File
@@ -2,6 +2,7 @@ import sqlite3
from datetime import datetime, timezone
from src.database.db_manager import DBManager
from src.database.sqlite_connection import connect_sqlite
from web.realtime_event_store import RealtimeEventStore
from web.realtime_patch_schema import normalize_observation_patch
@@ -75,7 +76,7 @@ def test_event_store_cleanup_uses_short_replay_retention(tmp_path):
old_event = store.append_event(_event("taipei", 30.0))
fresh_event = store.append_event(_event("taipei", 31.0))
with sqlite3.connect(db_path) as conn:
with connect_sqlite(db_path) as conn:
conn.execute(
"UPDATE observation_patch_events SET created_at = ? WHERE revision = ?",
("2026-05-26T00:00:00+00:00", old_event["revision"]),