Parcourir la source

fix: pick latest available algorithm health period within range

zhouyang.xie il y a 1 semaine
Parent
commit
b593f7bbcb
1 fichiers modifiés avec 17 ajouts et 1 suppressions
  1. 17 1
      app/report/page_source.py

+ 17 - 1
app/report/page_source.py

@@ -239,7 +239,23 @@ def collect_fault_from_page(wind: Dict[str, Any], months: List[str]) -> Dict[str
 def collect_algorithm_health_from_page(wind: Dict[str, Any], months: List[str]) -> Dict[str, Any]:
     """算法健康评估页面数据:/AnalysisMulti/health-assessment/detail。"""
     code = wind["code"]
-    month = months[-1]
+    month = None
+    # 在所选时间段内取页面最新可用期次(例如选择 2024-12 时回退到 2024-11)
+    try:
+        pr = requests.get(
+            "http://127.0.0.1:8888/health-assessment/periods",
+            params={"fieldCode": code},
+            timeout=30,
+        )
+        pr.raise_for_status()
+        periods = [x.get("period") for x in (pr.json().get("data") or [])]
+        periods = [x for x in periods if x and months[0] <= x <= months[-1]]
+        if periods:
+            month = max(periods)
+    except Exception:
+        month = None
+    if not month:
+        return {"available": False, "error": "算法健康评估页面在所选时间段内无可用期次", "turbines": []}
     try:
         r = requests.get(
             "http://127.0.0.1:8888/health-assessment/detail",