Procházet zdrojové kódy

fix: use latest valid month turbines for yearly health aggregation

zhouyang.xie před 1 týdnem
rodič
revize
80b72f706b
1 změnil soubory, kde provedl 13 přidání a 13 odebrání
  1. 13 13
      app/report/collector.py

+ 13 - 13
app/report/collector.py

@@ -317,6 +317,19 @@ def collect_health(wind: Dict[str, Any], months: List[str]) -> Dict[str, Any]:
         except Exception as exc:
             errors.append(f"{month}: {exc}")
 
+    # 年度区间下,健康评估页面可能只有部分月份有有效结果;
+    # 取最后一个月有有效结果的月份作为单机明细(总分布按所有月份汇总)。
+    last_valid_month = None
+    for m in reversed(monthly):
+        if m.get("valid_count"):
+            last_valid_month = m.get("month")
+            break
+    latest_turbines = []
+    for m in monthly:
+        if m.get("month") == last_valid_month:
+            latest_turbines = m.get("turbines") or []
+            break
+
     turbines = []
     for x in latest_turbines:
         subsystems = x.get("subsystems") or {}
@@ -339,19 +352,6 @@ def collect_health(wind: Dict[str, Any], months: List[str]) -> Dict[str, Any]:
         vals = [t[key] for t in valid_turbines if t[key] is not None and t[key] >= 0]
         subsys_avg[key] = round(sum(vals) / len(vals), 2) if vals else None
 
-    # 年度区间下,健康评估页面可能只有部分月份有有效结果;
-    # 取最后一个月有有效结果的月份作为单机明细(总分布按所有月份汇总)。
-    last_valid_month = None
-    for m in reversed(monthly):
-        if m.get("valid_count"):
-            last_valid_month = m.get("month")
-            break
-    latest_turbines = []
-    for m in monthly:
-        if m.get("month") == last_valid_month:
-            latest_turbines = m.get("turbines") or []
-            break
-    valid_turbines = [t for t in latest_turbines if t.get("score", -1) >= 0]
     latest_dist = (monthly[-1] if monthly else {}).get("distribution") or {}
     return {
         "available": bool(monthly) and bool(valid_turbines),