Explorar o código

fix: use page chart images inline, remove re-drawn figures

zhouyang.xie hai 6 días
pai
achega
fc940e178c
Modificáronse 2 ficheiros con 23 adicións e 19 borrados
  1. 8 3
      app/report/page_chart.py
  2. 15 16
      app/report/template_builder.py

+ 8 - 3
app/report/page_chart.py

@@ -130,13 +130,18 @@ def capture_fault(page, out_dir: str) -> List[str]:
 def capture_vibration(page, out_dir: str) -> List[str]:
     _goto(page, "/home/health/vibration")
     try:
-        page.locator(".searchbox .el-button", has_text="查询").first.click()
+        page.locator("button", has_text="查询").first.click()
         time.sleep(7)
     except Exception:
         pass
+    # 直接通过组件状态选中第一条波形并生成频谱图,避免 el-table 行点击未触发 current-change
     try:
-        page.locator(".picture", has_text="频谱图").first.click()
-        time.sleep(8)
+        page.evaluate(
+            "()=>{const el=document.querySelector('.global-variable');const vm=el&&el.__vue__;"
+            "if(vm&&vm.tableDataList&&vm.tableDataList.length){vm.currentRow=vm.tableDataList[0];"
+            "vm.currentIndex=0;vm.generate('2');}}"
+        )
+        time.sleep(12)
     except Exception:
         pass
     paths = []

+ 15 - 16
app/report/template_builder.py

@@ -224,11 +224,10 @@ def _section_reliability(doc, data: Dict[str, Any], tmp: str):
         L._para(doc, f"故障日志数据不足:{f.get('error', '未取得有效记录')}。")
     else:
         L._table(doc, ["指标", "数值"], [["故障总次数", f.get("total")], ["影响机组数", f.get("affected_turbines")]], [5.0, 9.0])
-        L._image(doc, L.charts.fault_monthly(f.get("monthly", []), os.path.join(tmp, "fault_monthly.png")), "图 5-1 月度故障次数")
+        _page_image(doc, data, "fault", "图 5-1 故障诊断页面图")
         rows = [[c.get("code"), c.get("count"), c.get("turbines")] for c in f.get("top_codes", [])]
         if rows:
             L._table(doc, ["故障码", "次数", "影响机组数"], rows, [8.0, 3.0, 4.0])
-        L._image(doc, L.charts.fault_top(f.get("top_codes", []), os.path.join(tmp, "fault_top.png")), "图 5-2 高频故障码")
     L._heading(doc, "5.2 大部件温度异常检测", 2)
     if not h.get("available"):
         L._para(doc, f"健康评估数据不足:{h.get('error', '未取得有效记录')}。")
@@ -245,7 +244,6 @@ def _section_reliability(doc, data: Dict[str, Any], tmp: str):
             ],
             [4.5, 4.0, 8.0],
         )
-        L._image(doc, L.charts.health_subsystems(sub, os.path.join(tmp, "health_subsys.png")), "图 5-3 子系统平均健康得分")
         L._para(
             doc,
             "大部件温度异常检测需要温度测点与工况数据的完整配对。本期健康评估已对发电机、机舱、"
@@ -331,17 +329,12 @@ def _section_risk(doc, data: Dict[str, Any], tmp: str):
             ],
             [5.0, 9.0],
         )
-        L._image(doc, L.charts.vibration_monthly(v.get("monthly", []), os.path.join(tmp, "vib_monthly.png")), "图 6-1 月度振动波形记录量")
-        spec = v.get("spectrum")
-        if spec:
-            L._para(
-                doc,
-                f"示例波形来自 {spec.get('point')},采样频率 {spec.get('fs')} Hz,"
-                f"振动有效值约 {spec.get('rms')}。频谱仅用于展示波形特征,部件级诊断需结合轴承参数和历史趋势。",
-            )
-            L._image(doc, L.charts.vibration_spectrum(spec, os.path.join(tmp, "vib_spectrum.png")), "图 6-2 典型振动频谱")
-        else:
-            L._para(doc, "所选时间段内未找到可解析的波形记录,无法生成频谱示例。")
+        _page_image(doc, data, "vibration", "图 6-1 振动分析页面频谱图")
+        L._para(
+            doc,
+            "上图为振动分析页面实际频谱图,报告不再使用重绘频谱,保证与页面展示一致。"
+            "部件级诊断需结合轴承特征频率与历史趋势复核。",
+        )
 
 
 def _section_power_curve(doc, data: Dict[str, Any]):
@@ -349,8 +342,9 @@ def _section_power_curve(doc, data: Dict[str, Any]):
     L._para(
         doc,
         "功率曲线分析应基于机组风速-功率散点、合同功率曲线和机舱传递函数,对机组发电性能与一致性进行评价。"
-        "本期报告生成数据中未包含功率曲线专项数据集,暂不输出功率曲线拟合结果和机组性能结论。",
+        "本期报告使用分析概览页面有功功率曲线原图,确保与页面展示一致。",
     )
+    _page_image(doc, data, "overview", "图 7-1 分析概览页面有功功率曲线")
 
 
 
@@ -436,6 +430,12 @@ def _section_conclusion(doc, data: Dict[str, Any]):
     L._para(doc, summary, indent=False)
 
 
+def _page_image(doc, data: Dict[str, Any], key: str, caption: str):
+    paths = (data.get("page_charts") or {}).get(key) or []
+    for path in paths[:1]:
+        L._image(doc, path, caption)
+
+
 def _section_page_images(doc, data: Dict[str, Any]):
     charts = data.get("page_charts") or {}
     labels = {
@@ -494,7 +494,6 @@ def build_template_report(data: Dict[str, Any], tmp_dir: str, output_path: str,
     _section_risk(doc, data, tmp_dir)
     _section_power_curve(doc, data)
     _section_conclusion(doc, data)
-    _section_page_images(doc, data)
     L._appendix(doc, data)
     doc.core_properties.title = report_title
     doc.core_properties.author = L.HEADER_TEXT