fix: 代码审查问题修复
- unit_of_work.py: 简化为纯 session 上下文管理器,消除 double-close 风险 - validation.py: 移除未使用的 import,简化 _score_to_1x2 逻辑 - repositories.py: 将 func 导入移到模块顶层 - 更新所有 get_uow() 调用点使用新接口(yield session 而非 uow 对象)
This commit is contained in:
+4
-5
@@ -13,14 +13,13 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
async def settle_prediction(prediction_id: int, home_goals: int, away_goals: int) -> Prediction:
|
||||
"""回填实际结果。"""
|
||||
async with get_uow() as uow:
|
||||
pred = await uow.session.get(Prediction, prediction_id)
|
||||
async with get_uow() as session:
|
||||
pred = await session.get(Prediction, prediction_id)
|
||||
if pred is None:
|
||||
raise ValueError(f"prediction {prediction_id} not found")
|
||||
pred.actual_home_goals = home_goals
|
||||
pred.actual_away_goals = away_goals
|
||||
pred.settled = True
|
||||
await uow.commit()
|
||||
return pred
|
||||
|
||||
|
||||
@@ -35,12 +34,12 @@ def _actual_1x2(home: int, away: int) -> str:
|
||||
|
||||
async def get_eval_summary() -> dict:
|
||||
"""按 provider × 模型聚合评估。"""
|
||||
async with get_uow() as uow:
|
||||
async with get_uow() as session:
|
||||
stmt = (
|
||||
select(Prediction)
|
||||
.where(Prediction.settled == True)
|
||||
)
|
||||
result = await uow.session.execute(stmt)
|
||||
result = await session.execute(stmt)
|
||||
rows = list(result.scalars().all())
|
||||
|
||||
from collections import defaultdict
|
||||
|
||||
Reference in New Issue
Block a user