소스 검색

feat: rebuild report chapters against reliability and efficiency template

zhouyang.xie 1 주 전
부모
커밋
c5b107340a
4개의 변경된 파일과 440개의 추가작업 그리고 9개의 파일을 삭제
  1. 4 4
      app/report/generator.py
  2. 7 5
      app/report/ollama_client.py
  3. 1 0
      app/report/reviewer.py
  4. 428 0
      app/report/template_builder.py

+ 4 - 4
app/report/generator.py

@@ -9,7 +9,7 @@ import traceback
 from datetime import datetime
 from typing import Any, Dict, List
 
-from app.report import collector, docx_builder, ollama_client, reviewer
+from app.report import collector, ollama_client, reviewer, template_builder
 
 BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 REPORT_DIR = os.path.join(BASE_DIR, "output", "reports")
@@ -81,12 +81,12 @@ def run_job(job_id: str, request: Dict[str, Any], store: Dict[str, Dict[str, Any
         update(65, "生成图表与 Word 文档…")
 
         ts = datetime.now().strftime("%Y%m%d_%H%M%S")
-        title = request.get("title") or f"{data['wind']['name']}风电机组健康度分析报告"
-        filename = f"{_safe_name(data['wind']['name'])}_{start_month}_{end_month}_健康度分析报告_{ts}.docx"
+        title = request.get("title") or f"{data['wind']['name']}风电机组可靠性和能效双提升数据分析报告"
+        filename = f"{_safe_name(data['wind']['name'])}_{start_month}_{end_month}_可靠性和能效双提升数据分析报告_{ts}.docx"
         output_path = os.path.join(REPORT_DIR, filename)
         tmp_dir = os.path.join(TMP_ROOT, job_id)
 
-        docx_builder.build_report(
+        template_builder.build_template_report(
             data, tmp_dir, output_path, title=title, sections=request.get("sections")
         )
 

+ 7 - 5
app/report/ollama_client.py

@@ -13,17 +13,18 @@ REVIEW_MODEL = os.getenv("REVIEW_MODEL", "deepseek-r1:14b")
 OLLAMA_TIMEOUT = int(os.getenv("OLLAMA_TIMEOUT", "900"))
 
 
-def _post(payload: dict) -> Optional[str]:
+def _post(payload: dict, timeout: Optional[int] = None) -> Optional[str]:
+    timeout = timeout or OLLAMA_TIMEOUT
     try:
         resp = requests.post(
             f"{OLLAMA_URL}/api/chat",
             json=payload,
-            timeout=OLLAMA_TIMEOUT,
+            timeout=timeout,
         )
         if resp.status_code == 400 and "think" in payload:
             payload = dict(payload)
             payload.pop("think", None)
-            resp = requests.post(f"{OLLAMA_URL}/api/chat", json=payload, timeout=OLLAMA_TIMEOUT)
+            resp = requests.post(f"{OLLAMA_URL}/api/chat", json=payload, timeout=timeout)
         resp.raise_for_status()
         data = resp.json()
         content = (data.get("message") or {}).get("content")
@@ -47,7 +48,7 @@ def _post(payload: dict) -> Optional[str]:
                 "stream": False,
                 "options": payload.get("options", {}),
             },
-            timeout=OLLAMA_TIMEOUT,
+            timeout=timeout,
         )
         resp.raise_for_status()
         return (resp.json().get("response") or "").strip() or None
@@ -61,6 +62,7 @@ def chat_model(
     user: str,
     temperature: float = 0.25,
     num_predict: int = 900,
+    timeout: Optional[int] = None,
 ) -> Optional[str]:
     payload = {
         "model": model,
@@ -77,7 +79,7 @@ def chat_model(
             "num_ctx": 8192,
         },
     }
-    return _post(payload)
+    return _post(payload, timeout=timeout)
 
 
 def chat(system: str, user: str, temperature: float = 0.25, num_predict: int = 900) -> Optional[str]:

+ 1 - 0
app/report/reviewer.py

@@ -91,6 +91,7 @@ def review_report(path: str, data: Dict[str, Any]) -> Optional[str]:
             prompt,
             temperature=0.1,
             num_predict=700,
+            timeout=int(os.getenv("REVIEW_TIMEOUT", "300")),
         )
         return text.strip() if text else None
     except Exception:

+ 428 - 0
app/report/template_builder.py

@@ -0,0 +1,428 @@
+"""按《风电机组可靠性和能效双提升数据分析报告》模板重组 Word 报告。
+
+现有 collector 已提供:概览(发电量/风速/完整率)、健康评估、故障、振动。
+本构建器把这些数据映射到模板章节;模板中的偏航/功率曲线等专项数据若未接入,
+明确写“本期未接入”,不编造结论。
+"""
+from __future__ import annotations
+
+import os
+from typing import Any, Dict, List, Optional
+
+from docx import Document
+from docx.enum.text import WD_ALIGN_PARAGRAPH
+from docx.shared import Cm, Pt
+
+from app.report import docx_builder as L
+
+
+def _num(v, digits=2, suffix=""):
+    if v is None:
+        return "—"
+    try:
+        return f"{float(v):,.{digits}f}{suffix}"
+    except (TypeError, ValueError):
+        return f"{v}{suffix}"
+
+
+def _section_summary(doc, data: Dict[str, Any]):
+    L._heading(doc, "摘  要", 1)
+    w, ov = data["wind"], data.get("overview") or {}
+    L._para(
+        doc,
+        f"本报告以{w.get('name')}为分析对象,分析时段为"
+        f"{data['period']['start']} 至 {data['period']['end']}。"
+        "报告围绕风资源与发电性能、设备可靠性、机组潜在风险及功率曲线等维度开展分析,"
+        "识别影响机组可靠性和能效的主要问题,并提出针对性的检查与治理建议。",
+    )
+    if ov.get("available"):
+        L._para(
+            doc,
+            f"分析期内,风电场累计发电量约 {_num(ov.get('total_mwh'), 2, ' MWh')},"
+            f"等效满负荷小时约 {_num(ov.get('equivalent_hours'), 1, ' h')},"
+            f"平均风速约 {_num(ov.get('avg_wind'), 2, ' m/s')},"
+            f"容量系数约 {_num(ov.get('capacity_factor'), 2, '%')},"
+            f"分钟级数据完整率约 {_num(ov.get('completeness'), 2, '%')}。",
+        )
+    h = data.get("health") or {}
+    if h.get("available"):
+        L._para(
+            doc,
+            f"健康评估覆盖 {len(h.get('turbines') or [])} 台机组,平均健康得分 "
+            f"{_num(h.get('avg_score'), 2)}。报告对低分机组及其发电子系统、机舱系统、"
+            "电网环境和传动系统进行了重点识别。",
+        )
+    f = data.get("fault") or {}
+    if f.get("available"):
+        L._para(
+            doc,
+            f"故障统计共记录 {f.get('total', 0)} 次,影响 {f.get('affected_turbines', 0)} 台机组;"
+            "报告对高频故障码和故障集中机组进行了分析。",
+        )
+    L._para(
+        doc,
+        "本报告的数字、图表与统计结果由系统按既定口径计算;受数据接入范围、测点配置和现场记录完整性限制,"
+        "结论应作为运维分析参考,需经专业技术人员复核后使用。",
+    )
+
+
+def _section_preface(doc, data: Dict[str, Any]):
+    w = data["wind"]
+    L._heading(doc, "1 前言", 1)
+    L._heading(doc, "1.1 风场情况", 2)
+    L._table(
+        doc,
+        ["项目", "内容"],
+        [
+            ["风电场名称", w.get("name")],
+            ["所属单位", w.get("company") or "—"],
+            ["装机容量", _num((w.get("capacity_kw") or 0) / 1000, 2, " MW")],
+            ["机组数量", f"{w.get('turbine_count', 0)} 台"],
+            ["分析时段", f"{data['period']['start']} 至 {data['period']['end']}"],
+        ],
+        [4.0, 11.0],
+    )
+    L._para(
+        doc,
+        f"基于{w.get('name')}的 SCADA 运行数据、健康评估结果、故障日志和 CMS 振动波形,"
+        "对机位风资源、发电量、设备可靠性、机组潜在风险和功率曲线进行分析,"
+        "为场站可靠性和能效提升提供数据依据。",
+    )
+    L._heading(doc, "1.2 分析思路", 2)
+    L._para(doc, "风电场能效不及预期,可能存在的问题主要包括以下四个方面:")
+    for t in (
+        "一是风资源条件与可研设计存在偏差,通常需要较大投入的技改才能提升;",
+        "二是限电比例较高,由当地电网及政策决定,不计入场站考核;",
+        "三是设备可靠性不足,故障停机、亚健康限功率运行和隐性问题造成电量损失;",
+        "四是机组功率曲线偏离设计水平,机组间一致性差,需要通过维护和整机优化改善。",
+    ):
+        L._para(doc, f"· {t}", indent=False, size=10)
+    L._para(
+        doc,
+        "本报告结合风电场运行数据、故障记录和健康评估结果,依次开展数据质量检查、"
+        "能效分析、设备可靠性分析、潜在风险评估和功率曲线分析,并给出结论与建议。",
+    )
+    L._heading(doc, "1.3 相关说明", 2)
+    L._para(
+        doc,
+        "本报告为场站级运行数据分析报告。报告中的健康评估结果来自平台预训练模型,"
+        "故障统计来自故障日志,振动分析基于 CMS 波形记录;未接入的专项数据在对应章节中明确标注,"
+        "不以推测替代实测。",
+    )
+
+
+def _section_standards(doc):
+    L._heading(doc, "2 依据标准", 1)
+    L._para(doc, "下列文件对于本报告的应用是必不可少的,但不限于这些。引用文件以最新版本适用于本报告。")
+    standards = [
+        "IEC 61400-12-1:2017《风力发电机组功率曲线测试》",
+        "IEC 61400-12-2:2013《基于机舱风速计的风力发电机组功率曲线测试》",
+        "IEC 61400-26-2:2014《基于发电量的可利用率》",
+        "IEC 61400-1:2005《风力发电机组设计要求》",
+        "GB/T 18451.2-2012《风力发电机组功率特性测试》",
+        "GB/T 19960.2-2005《风力发电机组 第2部分:通用试验方法》",
+        "GB/T 20319-2006《风力发电机组验收规范》",
+        "GB/T 18710-2002《风电场风能资源评估方法》",
+        "DL/T 793-2012《发电设备可靠性评价规程》",
+        "NB/T 31045-2013《风电场运行指标与评价导则》",
+        "《中国华电集团有限公司风电与光伏发电设备退出质保期管理办法》",
+        "《中国华电集团有限公司防止风电机组重大设备事故技术要求》",
+    ]
+    for s in standards:
+        L._para(doc, f"· {s}", indent=False, size=9.5)
+
+
+def _section_data_collection(doc, data: Dict[str, Any], tmp: str):
+    w = data["wind"]
+    ov = data.get("overview") or {}
+    L._heading(doc, "3 数据收集", 1)
+    L._heading(doc, "3.1 数据收集情况", 2)
+    L._para(doc, f"{w.get('name')}提供的数据及接入情况汇总见表 3-1。")
+    L._table(
+        doc,
+        ["数据类别", "来源/表", "本期状态", "用途"],
+        [
+            ["台账数据", "wind_field / wind_engine_group", "已接入", "风场、机组、机型与容量"],
+            ["分钟级 SCADA", f"{w.get('code')}_minute", "已接入" if ov.get("available") else "不足", "发电量、风速、功率、完整率"],
+            ["健康评估", "健康评估模型", "已接入" if (data.get("health") or {}).get("available") else "不足", "机组与子系统健康得分"],
+            ["故障日志", f"{w.get('code')}_fault", "已接入" if (data.get("fault") or {}).get("available") else "不足", "故障次数、故障码与影响机组"],
+            ["CMS 振动", f"{w.get('code')}_wave", "已接入" if (data.get("vibration") or {}).get("available") else "不足", "测点覆盖、采样频率与频谱"],
+            ["秒级 SCADA", "标准秒级表", "按场站接入情况", "偏航/变桨/功率曲线专项分析"],
+            ["偏航误差专项", "偏航误差计算结果", "本期未接入", "静态/动态偏航误差分析"],
+        ],
+        [3.8, 7.0, 2.8, 3.4],
+    )
+    L._heading(doc, "3.2 数据质量分析", 2)
+    if ov.get("available"):
+        L._para(doc, f"分钟级数据完整率约 {_num(ov.get('completeness'), 2, '%')}。各月数据质量见表 3-2。")
+        rows = [
+            [m.get("month"), _num(m.get("gen_mwh"), 2), _num(m.get("avg_wind"), 2), _num(m.get("completeness"), 2, "%")]
+            for m in ov.get("monthly", [])
+        ]
+        if rows:
+            L._table(doc, ["月份", "发电量(MWh)", "平均风速(m/s)", "完整率"], rows, [3.2, 4.2, 4.2, 3.4])
+    else:
+        L._para(doc, f"分钟级数据不足:{ov.get('error', '未取得有效记录')}。")
+    for key, label in (("health", "健康评估"), ("fault", "故障日志"), ("vibration", "振动波形")):
+        sec = data.get(key) or {}
+        if not sec.get("available"):
+            L._para(doc, f"· {label}:{sec.get('error', '未取得有效记录')}。", indent=False, size=10)
+
+
+def _section_energy(doc, data: Dict[str, Any], tmp: str):
+    ov = data.get("overview") or {}
+    L._heading(doc, "4 能效分析", 1)
+    L._para(doc, "本节主要通过机组生产指标评价和偏航误差分析,对风电场的能效情况进行分析。")
+    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,
+            "偏航误差包括静态偏航误差和动态偏航误差。本期报告生成数据中未包含可用的偏航误差专项结果,"
+            "因此不对具体机组偏航误差数值作出判断。建议后续接入偏航误差计算结果或秒级风向/机舱位置数据后补充本节。",
+        )
+        return
+    L._para(
+        doc,
+        "根据机组综合统计,选取累计发电量、等效满负荷小时、平均风速、容量系数和数据完整率"
+        "五项指标,对机组运行状况进行评价。",
+    )
+    L._table(
+        doc,
+        ["指标", "数值", "说明"],
+        [
+            ["累计发电量", _num(ov.get("total_mwh"), 2, " MWh"), "分钟级有功功率积分"],
+            ["等效满负荷小时", _num(ov.get("equivalent_hours"), 1, " h"), "发电量 / 装机容量"],
+            ["平均风速", _num(ov.get("avg_wind"), 2, " m/s"), "按记录数加权"],
+            ["容量系数", _num(ov.get("capacity_factor"), 2, "%"), "发电量 /(容量×时段小时数)"],
+            ["数据完整率", _num(ov.get("completeness"), 2, "%"), "实际记录 / 应有分钟记录"],
+        ],
+        [4.2, 5.0, 7.0],
+    )
+    rows = [
+        [m.get("month"), _num(m.get("gen_mwh"), 2), _num(m.get("avg_wind"), 2), _num(m.get("completeness"), 2, "%")]
+        for m in ov.get("monthly", [])
+    ]
+    if rows:
+        L._table(doc, ["月份", "发电量(MWh)", "平均风速(m/s)", "完整率"], rows, [3.2, 4.2, 4.2, 3.4])
+    L._image(doc, L.charts.monthly_generation(ov.get("monthly", []), os.path.join(tmp, "monthly_gen.png")), "图 4-1 月度发电量与平均风速")
+    L._para(
+        doc,
+        "按机组统计发电量并排序,可快速识别低效机组。机组间差异需结合机位风速、限电、停机与故障记录综合判断,"
+        "不宜仅凭发电量排名直接认定机组性能异常。",
+    )
+    rows = [
+        [t.get("rank"), t.get("name"), _num(t.get("gen_mwh"), 2), _num(t.get("avg_wind"), 2), t.get("points")]
+        for t in ov.get("turbines", [])[:15]
+    ]
+    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,
+        "偏航误差包括静态偏航误差和动态偏航误差。本期报告生成数据中未包含可用的偏航误差专项结果,"
+        "因此不对具体机组偏航误差数值作出判断。建议后续接入偏航误差计算结果或秒级风向/机舱位置数据后补充本节。",
+    )
+
+
+def _section_reliability(doc, data: Dict[str, Any], tmp: str):
+    h = data.get("health") or {}
+    f = data.get("fault") or {}
+    L._heading(doc, "5 设备可靠性分析", 1)
+    L._para(doc, "本节通过故障统计和健康评估结果,对风电场设备可靠性情况进行分析。")
+    L._heading(doc, "5.1 故障分析", 2)
+    if not f.get("available"):
+        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 月度故障次数")
+        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', '未取得有效记录')}。")
+        return
+    sub = h.get("subsystems") or {}
+    L._table(
+        doc,
+        ["子系统", "平均得分", "关注点"],
+        [
+            ["发电机组", _num(sub.get("generator"), 2), "绕组、轴承温度与电气量"],
+            ["机舱系统", _num(sub.get("nacelle"), 2), "机舱振动、温度与位置"],
+            ["电网环境", _num(sub.get("grid"), 2), "电流、功率与并网质量"],
+            ["传动系统", _num(sub.get("drive_train"), 2), "主轴承、齿轮箱温度"],
+        ],
+        [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,
+        "大部件温度异常检测需要温度测点与工况数据的完整配对。本期健康评估已对发电机、机舱、"
+        "电网环境和传动系统给出综合得分;具体温度偏差、温升趋势和传感器可信度仍需结合专项温度分析复核。",
+    )
+
+
+def _section_risk(doc, data: Dict[str, Any], tmp: str):
+    h = data.get("health") or {}
+    v = data.get("vibration") or {}
+    L._heading(doc, "6 机组设备潜在风险评估", 1)
+    L._para(doc, "本节结合健康评估、故障记录和振动波形,对机组潜在风险进行分析。")
+    L._heading(doc, "6.1 主控系统分析", 2)
+    L._para(
+        doc,
+        "主控系统风险应结合变桨-转速协调、转速-功率协调和控制参数一致性判断。"
+        "本期报告已纳入健康评估中的电网环境与机舱系统得分,但未单独接入主控系统专项分析结果,"
+        "相关结论需结合现场控制参数核查。",
+    )
+    L._heading(doc, "6.2 变桨系统分析", 2)
+    L._para(
+        doc,
+        "变桨系统重点关注三叶桨距一致性、变桨速率、变桨电机温度及后备电源状态。"
+        "本期数据未形成独立的变桨系统评分,暂不给出具体机组结论;建议补充变桨专项数据后开展。",
+    )
+    L._heading(doc, "6.3 偏航系统分析", 2)
+    L._para(
+        doc,
+        "偏航系统重点关注静态/动态偏航误差、偏航频次、偏航刹车和扭缆状态。"
+        "本期偏航误差专项结果未接入,暂不给出具体机组偏航误差数值,建议后续补充。",
+    )
+    L._heading(doc, "6.4 传动链分析", 2)
+    if h.get("available"):
+        sub = h.get("subsystems") or {}
+        L._para(
+            doc,
+            f"传动系统平均健康得分 {_num(sub.get('drive_train'), 2)}。"
+            "传动链风险需结合主轴承、齿轮箱温度、振动频谱和润滑状态综合判断。",
+        )
+        lows = [t for t in (h.get("low_turbines") or []) if (t.get("drive_train") or -1) >= 0][:8]
+        if lows:
+            rows = [[t.get("name"), _num(t.get("score"), 2), _num(t.get("drive_train"), 2)] for t in lows]
+            L._table(doc, ["机组", "总分", "传动系统得分"], rows, [5.0, 4.0, 5.0])
+    else:
+        L._para(doc, "健康评估数据不足,暂不开展传动链风险排序。")
+    L._heading(doc, "6.5 振动分析", 2)
+    if not v.get("available"):
+        L._para(doc, f"振动波形数据不足:{v.get('error', '未取得有效记录')}。")
+    else:
+        L._table(
+            doc,
+            ["指标", "数值"],
+            [
+                ["波形记录数", v.get("total")],
+                ["覆盖机组数", v.get("turbine_count")],
+                ["测点数", v.get("point_count")],
+            ],
+            [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, "所选时间段内未找到可解析的波形记录,无法生成频谱示例。")
+
+
+def _section_power_curve(doc, data: Dict[str, Any]):
+    L._heading(doc, "7 机组功率曲线分析", 1)
+    L._para(
+        doc,
+        "功率曲线分析应基于机组风速-功率散点、合同功率曲线和机舱传递函数,对机组发电性能与一致性进行评价。"
+        "本期报告生成数据中未包含功率曲线专项数据集,暂不输出功率曲线拟合结果和机组性能结论。",
+    )
+    ov = data.get("overview") or {}
+    if ov.get("available"):
+        L._para(
+            doc,
+            f"作为总体参考,本期平均风速约 {_num(ov.get('avg_wind'), 2, ' m/s')},"
+            f"累计发电量约 {_num(ov.get('total_mwh'), 2, ' MWh')};上述数据仅用于运行概况说明,"
+            "不能替代按风速分仓的功率曲线分析。",
+        )
+
+
+def _section_conclusion(doc, data: Dict[str, Any]):
+    L._heading(doc, "8 结论及建议", 1)
+    ov, h, f, v = (data.get(k) or {} for k in ("overview", "health", "fault", "vibration"))
+    points = []
+    if ov.get("available"):
+        points.append(
+            f"分析期内累计发电量约 {_num(ov.get('total_mwh'), 2, ' MWh')},平均风速约 "
+            f"{_num(ov.get('avg_wind'), 2, ' m/s')},数据完整率约 {_num(ov.get('completeness'), 2, '%')}。"
+        )
+    if h.get("available"):
+        points.append(
+            f"健康评估覆盖 {len(h.get('turbines') or [])} 台机组,平均健康得分 {_num(h.get('avg_score'), 2)};"
+            "低分机组应优先纳入现场核查。"
+        )
+    if f.get("available"):
+        points.append(f"故障统计共 {f.get('total', 0)} 次,影响 {f.get('affected_turbines', 0)} 台机组,建议优先治理高频故障码。")
+    if v.get("available"):
+        points.append(f"CMS 波形记录 {v.get('total', 0)} 条,覆盖 {v.get('turbine_count', 0)} 台机组;建议对典型频谱异常测点开展复核。")
+    if not points:
+        points.append("本期数据不足,暂不形成具体结论。")
+    for p in points:
+        L._para(doc, f"· {p}", indent=False)
+    L._para(doc, "建议:", indent=False, bold=True)
+    for s in (
+        "对健康评估低分机组和故障集中机组开展专项检查,核实传感器、润滑、冷却和控制参数状态。",
+        "补齐偏航误差、变桨系统、主控参数和功率曲线专项数据,完善后续报告分析。",
+        "对高频故障码建立治理清单,结合备件、工单和现场检修记录闭环跟踪。",
+        "对 CMS 振动异常测点开展频谱复核,必要时开展离线振动检测。",
+    ):
+        L._para(doc, f"· {s}", indent=False, size=10)
+
+
+def build_template_report(data: Dict[str, Any], tmp_dir: str, output_path: str,
+                          title: Optional[str] = None, sections: Optional[List[str]] = None):
+    os.makedirs(tmp_dir, exist_ok=True)
+    os.makedirs(os.path.dirname(output_path), exist_ok=True)
+    doc = Document()
+    section = doc.sections[0]
+    section.top_margin = Cm(2.2)
+    section.bottom_margin = Cm(2.2)
+    section.left_margin = Cm(2.6)
+    section.right_margin = Cm(2.6)
+    L._setup_header_footer(doc)
+    normal = doc.styles["Normal"]
+    normal.font.name = "微软雅黑"
+    normal.font.size = Pt(10.5)
+    normal._element.rPr.rFonts.set(L.qn("w:eastAsia"), "微软雅黑")
+
+    report_title = title or f"{data['wind']['name']}风电机组可靠性和能效双提升数据分析报告"
+    L._cover(doc, report_title, data)
+    L._statement(doc)
+    L._toc(doc, [
+        "摘  要",
+        "1 前言",
+        "2 依据标准",
+        "3 数据收集",
+        "4 能效分析",
+        "5 设备可靠性分析",
+        "6 机组设备潜在风险评估",
+        "7 机组功率曲线分析",
+        "8 结论及建议",
+        "附录 数据与模型说明",
+    ])
+    _section_summary(doc, data)
+    _section_preface(doc, data)
+    _section_standards(doc)
+    _section_data_collection(doc, data, tmp_dir)
+    _section_energy(doc, data, tmp_dir)
+    _section_reliability(doc, data, tmp_dir)
+    _section_risk(doc, data, tmp_dir)
+    _section_power_curve(doc, data)
+    _section_conclusion(doc, data)
+    L._appendix(doc, data)
+    doc.core_properties.title = report_title
+    doc.core_properties.author = L.HEADER_TEXT
+    doc.core_properties.subject = f"{data['wind']['name']} {data['period']['start']} 至 {data['period']['end']}"
+    doc.save(output_path)
+    return output_path