Explorar o código

feat: integrate data integrity and yaw error page results

zhouyang.xie hai 1 semana
pai
achega
199aef0251
Modificáronse 3 ficheiros con 99 adicións e 14 borrados
  1. 7 0
      app/report/collector.py
  2. 63 2
      app/report/page_source.py
  3. 29 12
      app/report/template_builder.py

+ 7 - 0
app/report/collector.py

@@ -566,6 +566,7 @@ def collect_all(wind_code: str, start_month: str, end_month: str, sections=None)
         "overview": page_source.collect_overview_from_page(wind, months) if "overview" in selected else {"available": False, "error": "未勾选分析概览章节", "monthly": [], "turbines": []},
         "health": collect_health(wind, months) if "health" in selected else {"available": False, "error": "未勾选健康评估章节"},
         "algorithm_health": page_source.collect_algorithm_health_from_page(wind, months),
+        "yaw": page_source.collect_yaw_from_page(wind, months),
         "fault": page_source.collect_fault_from_page(wind, months) if "fault" in selected else {"available": False, "error": "未勾选故障诊断章节", "monthly": [], "top_codes": []},
         "vibration": collect_vibration(wind, months) if "vibration" in selected else {"available": False, "error": "未勾选振动分析章节", "points": [], "monthly": []},
         "meta": {
@@ -585,6 +586,12 @@ def collect_all(wind_code: str, start_month: str, end_month: str, sections=None)
                 "period": months,
                 "filter": "fieldCode + period,读取 health.json",
             },
+            "yaw": {
+                "page": "偏航误差分析",
+                "source": "platform.analysis_general_file(yaw_error)",
+                "period": [start_month, end_month],
+                "filter": "静态偏航误差分析文件",
+            },
             "health": {
                 "page": "健康评估",
                 "source": HEALTH_API,

+ 63 - 2
app/report/page_source.py

@@ -160,11 +160,32 @@ def collect_overview_from_page(wind: Dict[str, Any], months: List[str]) -> Dict[
                     t["wind_sum"] += avg_wind * max(points, 1)
                     t["wind_points"] += max(points, 1)
 
+    # 数据完整度(分钟级),读取页面同源 data_integrity_minute 文件
+    comp_total_valid = 0
+    comp_total_expected = 0
+    comp_by_month: Dict[str, Any] = {}
+    for file_addr in integ_files:
+        text = fetch_minio_text(file_addr)
+        if not text:
+            continue
+        for row in _csv_rows(text):
+            month = (row.get("month") or "").strip()
+            valid = int(_f(row.get("valid_count") or 0))
+            expected = int(_f(row.get("expected_count") or 0))
+            if expected <= 0:
+                continue
+            comp_total_valid += valid
+            comp_total_expected += expected
+            m = comp_by_month.setdefault(month, {"v": 0, "e": 0})
+            m["v"] += valid
+            m["e"] += expected
+
     monthly = []
     for m in monthly_map.values():
         m["gen_mwh"] = round(m["gen_kwh"] / 1000, 2)
         m["avg_wind"] = round(m["wind_sum"] / m["wind_points"], 2) if m["wind_points"] else None
-        m["completeness"] = None
+        cm = comp_by_month.get(m["month"])
+        m["completeness"] = round(cm["v"] / cm["e"] * 100, 2) if cm and cm["e"] else None
         monthly.append(m)
     monthly.sort(key=lambda x: x["month"])
 
@@ -192,11 +213,51 @@ def collect_overview_from_page(wind: Dict[str, Any], months: List[str]) -> Dict[
         "equivalent_hours": round(total_kwh / capacity, 1) if capacity else None,
         "avg_wind": round(weighted_wind / total_points, 2) if total_points else None,
         "capacity_factor": None,
-        "completeness": None,
+        "completeness": round(comp_total_valid / comp_total_expected * 100, 2) if comp_total_expected else None,
         "integrity_files": integ_files,
     }
 
 
+def collect_yaw_from_page(wind: Dict[str, Any], months: List[str]) -> Dict[str, Any]:
+    """静态偏航误差:读取页面同源 yaw_error 分析文件。"""
+    code = wind["code"]
+    start, end = months[0], months[-1]
+    batch = resolve_analysis_batch(code, start, end)
+    if not batch:
+        return {"available": False, "error": "偏航误差页面无覆盖所选时间段的分析批次", "turbines": []}
+    files = analysis_general_files(batch["batch_code"], ["yaw_error"]).get("yaw_error", [])
+    rows = []
+    for addr in files:
+        text = fetch_minio_text(addr)
+        if not text:
+            continue
+        rows.extend(_csv_rows(text))
+    if not rows:
+        return {"available": False, "error": "偏航误差页面无静态偏航结果", "turbines": []}
+    turbines = []
+    for r in rows:
+        turbines.append({
+            "name": r.get("wind_turbine_name") or r.get("wind_turbine_number"),
+            "code": r.get("wind_turbine_number"),
+            "avg": _f(r.get("avg_yaw_error")),
+            "abs_avg": _f(r.get("avg_abs_yaw_error")),
+            "abs_max": _f(r.get("max_abs_yaw_error")),
+            "count": int(_f(r.get("valid_count") or 0)),
+        })
+    turbines.sort(key=lambda x: x["abs_avg"], reverse=True)
+    over3 = [t for t in turbines if t["abs_avg"] > 3]
+    over5 = [t for t in turbines if t["abs_avg"] > 5]
+    return {
+        "available": True,
+        "turbines": turbines,
+        "avg_abs": round(sum(t["abs_avg"] for t in turbines) / len(turbines), 2) if turbines else None,
+        "over3": len(over3),
+        "over5": len(over5),
+        "over3_list": [t["name"] for t in over3],
+        "over5_list": [t["name"] for t in over5],
+    }
+
+
 def collect_fault_from_page(wind: Dict[str, Any], months: List[str]) -> Dict[str, Any]:
     """故障诊断页面数据:读取 autodiag 保存结果(vibration_diagnosis_result),不查故障日志表。"""
     code = wind["code"]

+ 29 - 12
app/report/template_builder.py

@@ -190,6 +190,33 @@ def _section_data_collection(doc, data: Dict[str, Any], tmp: str):
             L._para(doc, f"· {label}:{sec.get('error', '未取得有效记录')}。", indent=False, size=10)
 
 
+def _render_yaw(doc, data: Dict[str, Any]):
+    y = data.get("yaw") or {}
+    L._heading(doc, "4.2 偏航误差分析", 2)
+    if not y.get("available"):
+        L._para(
+            doc,
+            "偏航误差包括静态偏航误差和动态偏航误差。本期页面无静态偏航误差专项结果,"
+            "因此不对具体机组偏航误差数值作出判断。",
+        )
+        return
+    L._para(
+        doc,
+        f"本期静态偏航误差按机组统计,平均绝对偏航误差 {_num(y.get('avg_abs'), 2, '°')};"
+        f"绝对偏航误差 >3° 的机组 {y.get('over3', 0)} 台,>5° 的机组 {y.get('over5', 0)} 台。"
+        f"按模板判据,±3° 以内为可接受范围,超过 3° 建议校正。",
+    )
+    rows = []
+    for t in (y.get("turbines") or [])[:10]:
+        rows.append([t.get("name"), _num(t.get("avg"), 2), _num(t.get("abs_avg"), 2), _num(t.get("abs_max"), 2)])
+    if rows:
+        L._table(doc, ["机组", "平均偏航误差(°)", "平均绝对误差(°)", "最大绝对误差(°)"], rows, [4.0, 3.6, 3.6, 3.6])
+    if y.get("over3_list"):
+        L._para(doc, f"绝对偏航误差 >3° 的机组:{'、'.join(y['over3_list'])}。", indent=False, size=10)
+    if y.get("over5_list"):
+        L._para(doc, f"绝对偏航误差 >5° 的机组:{'、'.join(y['over5_list'])};建议优先校正,校正后积累 2~3 周数据复核。", indent=False, size=10)
+
+
 def _section_energy(doc, data: Dict[str, Any], tmp: str):
     ov = data.get("overview") or {}
     L._heading(doc, "4 能效分析", 1)
@@ -197,12 +224,7 @@ def _section_energy(doc, data: Dict[str, Any], tmp: str):
     L._heading(doc, "4.1 生产指标分析", 2)
     if not ov.get("available"):
         L._para(doc, f"分析概览数据不足:{ov.get('error', '未取得分钟级数据')}。")
-        L._heading(doc, "4.2 偏航误差分析", 2)
-        L._para(
-            doc,
-            "偏航误差包括静态偏航误差和动态偏航误差。本期报告生成数据中未包含可用的偏航误差专项结果,"
-            "因此不对具体机组偏航误差数值作出判断。建议后续接入偏航误差计算结果或秒级风向/机舱位置数据后补充本节。",
-        )
+        _render_yaw(doc, data)
         return
     L._para(
         doc,
@@ -240,12 +262,7 @@ def _section_energy(doc, data: Dict[str, Any], tmp: str):
     if rows:
         L._table(doc, ["排名", "机组", "发电量(MWh)", "平均风速(m/s)", "记录数"], rows, [2.0, 4.0, 4.5, 4.0, 3.0])
     L._image(doc, L.charts.turbine_generation(ov.get("turbines", []), os.path.join(tmp, "turbine_gen.png")), "图 4-2 机组发电量排名")
-    L._heading(doc, "4.2 偏航误差分析", 2)
-    L._para(
-        doc,
-        "偏航误差包括静态偏航误差和动态偏航误差。本期报告生成数据中未包含可用的偏航误差专项结果,"
-        "因此不对具体机组偏航误差数值作出判断。建议后续接入偏航误差计算结果或秒级风向/机舱位置数据后补充本节。",
-    )
+    _render_yaw(doc, data)
 
 
 def _section_reliability(doc, data: Dict[str, Any], tmp: str):