|
@@ -67,31 +67,36 @@ def get_card_details(id: int, db_conn: PooledMySQLConnection = db_dependency):
|
|
|
images = [CardImageResponse.model_validate(row) for row in image_records]
|
|
images = [CardImageResponse.model_validate(row) for row in image_records]
|
|
|
|
|
|
|
|
# 计算总分数(只有当图片数量为 4 时才计算)
|
|
# 计算总分数(只有当图片数量为 4 时才计算)
|
|
|
- card_data['score'] = None
|
|
|
|
|
|
|
+ # 初始化
|
|
|
|
|
+ card_data["detection_score"] = None
|
|
|
|
|
+ card_data["modified_score"] = None
|
|
|
if len(images) == 4:
|
|
if len(images) == 4:
|
|
|
try:
|
|
try:
|
|
|
- final_score = 10
|
|
|
|
|
|
|
+ # ---------- detection_score ----------
|
|
|
|
|
+ detection_score = 10.0
|
|
|
for img in images:
|
|
for img in images:
|
|
|
- # 优先使用 modified_json,否则使用 detection_json
|
|
|
|
|
- src = img.modified_json if img.modified_json is not None else img.detection_json
|
|
|
|
|
-
|
|
|
|
|
- # src 可能为 None 或者不是 dict;做稳健检查
|
|
|
|
|
- if not isinstance(src, dict):
|
|
|
|
|
- logger.warning(f"图片 {img.id} 的 JSON 数据格式异常: {type(src)}")
|
|
|
|
|
- add_score = 0
|
|
|
|
|
- else:
|
|
|
|
|
- # 取嵌套键值:result -> _used_compute_deduct_score
|
|
|
|
|
- add_score = 0
|
|
|
|
|
|
|
+ try:
|
|
|
|
|
+ add_val = img.detection_json.get("result", {}).get("_used_compute_deduct_score", 0)
|
|
|
|
|
+ detection_score += float(add_val or 0)
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ logger.warning(f"解析 detection_json 分数失败 (image_id={img.id}): {e}")
|
|
|
|
|
+ card_data["detection_score"] = detection_score
|
|
|
|
|
+
|
|
|
|
|
+ # ---------- modified_score ----------
|
|
|
|
|
+ all_modified_none = all(img.modified_json is None for img in images)
|
|
|
|
|
+ if not all_modified_none:
|
|
|
|
|
+ modified_score = 10.0
|
|
|
|
|
+ for img in images:
|
|
|
|
|
+ src = img.modified_json if img.modified_json is not None else img.detection_json
|
|
|
try:
|
|
try:
|
|
|
add_val = src.get("result", {}).get("_used_compute_deduct_score", 0)
|
|
add_val = src.get("result", {}).get("_used_compute_deduct_score", 0)
|
|
|
- add_score = float(add_val) if add_val is not None else 0
|
|
|
|
|
|
|
+ modified_score += float(add_val or 0)
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
- logger.warning(f"从图片 {img.id} 的 JSON 中解析分数失败: {e}")
|
|
|
|
|
- add_score = 0
|
|
|
|
|
|
|
+ logger.warning(f"解析 modified_json 分数失败 (image_id={img.id}): {e}")
|
|
|
|
|
+ card_data["modified_score"] = modified_score
|
|
|
|
|
+ else:
|
|
|
|
|
+ card_data["modified_score"] = None
|
|
|
|
|
|
|
|
- final_score += add_score
|
|
|
|
|
-
|
|
|
|
|
- card_data['score'] = final_score
|
|
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
logger.error(f"计算分数过程异常: {e}")
|
|
logger.error(f"计算分数过程异常: {e}")
|
|
|
|
|
|