feat: 报告生成模块双轨制重构 — 公式模式 + ML 模式独立分流

**UI (step13_report_panel.py):**
  - 新增 QComboBox 报告模式选择:
    机器学习(ml) / 水色指数公式(formula)
  - WorkerThread 传递 report_mode 到 generate_report

**后端 (report_word.py):**
  - generate_report(report_mode='ml'/'formula') 参数路由
  - _generate_formula_report(): 水色指数专属结构
    1.项目背景 → 2.影像预处理 → 3.公式列表 →
    4.指数统计(10_WaterIndex_CSV) → 5.分布专题图(11_Thematic_Map)
    绝不包含模型训练/R²/RMSE 等 ML 内容
  - _generate_ml_report(): 原有 ML 逻辑完整保留
  - _analyze_statistics(): 全部改用 .get() 防御式读取
    兼容 参数/Parameter/name, 点位数/数量/count,
    最小值/min, 最大值/max, 平均值/mean, 标准差/std
This commit is contained in:
duxin
2026-07-09 11:33:50 +08:00
parent 692a88c7bb
commit 650e505ac4
2 changed files with 213 additions and 33 deletions

View File

@ -14,7 +14,7 @@ from src.gui.panels._step_path_resolver import resolve_subdir
from PyQt5.QtCore import Qt, QThread, pyqtSignal, QSettings
from PyQt5.QtWidgets import (
QWidget, QVBoxLayout, QHBoxLayout, QGroupBox, QFormLayout,
QLabel, QCheckBox, QPushButton, QLineEdit,
QLabel, QCheckBox, QPushButton, QLineEdit, QComboBox,
QMessageBox, QFileDialog, QProgressBar,
)
@ -33,12 +33,14 @@ class ReportWorkerThread(QThread):
finished = pyqtSignal(str)
error = pyqtSignal(str)
def __init__(self, work_dir: str, output_dir: Optional[str], report_title: str, enable_ai: bool):
def __init__(self, work_dir: str, output_dir: Optional[str], report_title: str,
enable_ai: bool, report_mode: str = 'ml'):
super().__init__()
self.work_dir = work_dir
self.output_dir = output_dir
self.report_title = report_title
self.enable_ai = enable_ai
self.report_mode = report_mode
def run(self):
try:
@ -76,6 +78,7 @@ class ReportWorkerThread(QThread):
out_path = gen.generate_report(
work_dir=self.work_dir,
report_title=self.report_title or "水质参数反演分析报告",
report_mode=self.report_mode,
on_progress=lambda pct, text: self.progress.emit(int(pct), str(text)),
)
self.finished.emit(str(out_path))
@ -257,6 +260,21 @@ class Step13ReportPanel(QWidget):
""")
execute_layout.addWidget(self.progress_bar)
# 报告模式选择
mode_row = QHBoxLayout()
mode_row.setContentsMargins(0, 4, 0, 0)
mode_row.setSpacing(10)
mode_label = QLabel("报告模式:")
mode_label.setMinimumWidth(120)
mode_label.setMaximumWidth(120)
mode_row.addWidget(mode_label)
self.report_mode_cb = QComboBox()
self.report_mode_cb.addItem("机器学习水质参数反演 (Step 9/12/13)", "ml")
self.report_mode_cb.addItem("水色指数与物理经验公式反演 (Step 10/11)", "formula")
self.report_mode_cb.setStyleSheet(common_lineedit_css)
mode_row.addWidget(self.report_mode_cb, 1)
execute_layout.addLayout(mode_row)
action_layout = QHBoxLayout()
action_layout.addStretch()
@ -394,7 +412,8 @@ class Step13ReportPanel(QWidget):
self.progress_bar.setValue(0)
self.progress_label.setText("正在准备生成…")
self._report_thread = ReportWorkerThread(wd, out, title, enable_ai)
report_mode = self.report_mode_cb.currentData()
self._report_thread = ReportWorkerThread(wd, out, title, enable_ai, report_mode)
self._report_thread.progress.connect(self._on_progress, Qt.QueuedConnection)
self._report_thread.finished.connect(self._on_finished, Qt.QueuedConnection)
self._report_thread.error.connect(self._on_error, Qt.QueuedConnection)