Преглед изворни кода

fix: ensure report data sourced from same pages and period

zhouyang.xie пре 1 недеља
родитељ
комит
3bc6431ec6
2 измењених фајлова са 49 додато и 3 уклоњено
  1. 28 3
      app/report/collector.py
  2. 21 0
      app/report/template_builder.py

+ 28 - 3
app/report/collector.py

@@ -280,9 +280,8 @@ def _call_health(wind_code: str, month: str) -> List[Dict[str, Any]]:
 
 
 
 
 def collect_health(wind: Dict[str, Any], months: List[str]) -> Dict[str, Any]:
 def collect_health(wind: Dict[str, Any], months: List[str]) -> Dict[str, Any]:
-    # 健康评估为逐机组模型推理,耗时较长;报告取时间段内最近 1 个月,
-    # 其余维度(概览/故障/振动)仍覆盖完整时间段。
-    assess_months = months[-1:]
+    # 报告与健康评估页同源:按所选时间段逐月调用健康评估页接口。
+    assess_months = list(months)
     monthly = []
     monthly = []
     latest_turbines: List[Dict[str, Any]] = []
     latest_turbines: List[Dict[str, Any]] = []
     errors = []
     errors = []
@@ -561,5 +560,31 @@ def collect_all(wind_code: str, start_month: str, end_month: str, sections=None)
             "generated_at": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
             "generated_at": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
             "data_source": "energy_data_prod(SCADA/故障/振动) + energy_prod(台账/健康)",
             "data_source": "energy_data_prod(SCADA/故障/振动) + energy_prod(台账/健康)",
         },
         },
+        "provenance": {
+            "overview": {
+                "page": "分析概览",
+                "source": f"energy_data_prod.{wind_code}_minute",
+                "period": [start_month, end_month],
+                "filter": "year_month + 分钟级有功/风速聚合",
+            },
+            "health": {
+                "page": "健康评估",
+                "source": HEALTH_API,
+                "period": months,
+                "filter": "windcode + month,逐月调用页面接口",
+            },
+            "fault": {
+                "page": "故障诊断",
+                "source": f"energy_data_prod.{wind_code}_fault",
+                "period": [start_month, end_month],
+                "filter": "time_stamp 月区间",
+            },
+            "vibration": {
+                "page": "振动分析",
+                "source": f"energy_data_prod.{wind_code}_wave",
+                "period": [start_month, end_month],
+                "filter": "time_stamp 月区间 + 波形解析",
+            },
+        },
     }
     }
     return data
     return data

+ 21 - 0
app/report/template_builder.py

@@ -25,6 +25,15 @@ def _num(v, digits=2, suffix=""):
         return f"{v}{suffix}"
         return f"{v}{suffix}"
 
 
 
 
+def _period_text(v):
+    if isinstance(v, (list, tuple)):
+        if len(v) == 1:
+            return str(v[0])
+        if len(v) >= 2:
+            return f"{v[0]} 至 {v[-1]}"
+    return str(v) if v not in (None, "") else "—"
+
+
 def _section_summary(doc, data: Dict[str, Any]):
 def _section_summary(doc, data: Dict[str, Any]):
     L._heading(doc, "摘  要", 1)
     L._heading(doc, "摘  要", 1)
     w, ov = data["wind"], data.get("overview") or {}
     w, ov = data["wind"], data.get("overview") or {}
@@ -152,6 +161,18 @@ def _section_data_collection(doc, data: Dict[str, Any], tmp: str):
         ],
         ],
         [3.8, 7.0, 2.8, 3.4],
         [3.8, 7.0, 2.8, 3.4],
     )
     )
+    prov = data.get("provenance") or {}
+    if prov:
+        L._para(
+            doc,
+            f"本报告只使用 {data['period']['start']} 至 {data['period']['end']} 的数据,"
+            "四个数据页面与报告采用同一时间段口径,来源如下:",
+        )
+        rows = [
+            [v.get("page"), v.get("source"), _period_text(v.get("period")), v.get("filter")]
+            for v in prov.values()
+        ]
+        L._table(doc, ["数据页面", "来源", "时间段", "口径"], rows, [3.2, 7.2, 3.0, 5.0])
     L._heading(doc, "3.2 数据质量分析", 2)
     L._heading(doc, "3.2 数据质量分析", 2)
     if ov.get("available"):
     if ov.get("available"):
         L._para(doc, f"分钟级数据完整率约 {_num(ov.get('completeness'), 2, '%')}。各月数据质量见表 3-2。")
         L._para(doc, f"分钟级数据完整率约 {_num(ov.get('completeness'), 2, '%')}。各月数据质量见表 3-2。")