feat: step13 auto-detect mode + user confirmation combo (with fallback to manual override)

This commit is contained in:
duxin
2026-07-09 15:33:45 +08:00
parent 66a181cbe2
commit 208e067334
2 changed files with 36 additions and 9 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, QSpinBox,
QLabel, QCheckBox, QPushButton, QLineEdit, QComboBox, QSpinBox,
QMessageBox, QFileDialog, QProgressBar,
)
@ -34,12 +34,13 @@ class ReportWorkerThread(QThread):
error = pyqtSignal(str)
def __init__(self, work_dir: str, output_dir: Optional[str], report_title: str,
enable_ai: bool, ai_maps_limit: int = 999):
enable_ai: bool, report_mode: str = 'auto', ai_maps_limit: int = 999):
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
self.ai_maps_limit = ai_maps_limit
def run(self):
@ -78,7 +79,7 @@ class ReportWorkerThread(QThread):
out_path = gen.generate_report(
work_dir=self.work_dir,
report_title=self.report_title or "水质参数反演分析报告",
report_mode='auto',
report_mode=self.report_mode,
ai_maps_limit=self.ai_maps_limit,
on_progress=lambda pct, text: self.progress.emit(int(pct), str(text)),
)
@ -261,6 +262,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("机器学习水质参数反演", "ml")
self.report_mode_cb.addItem("水色指数与物理经验公式反演", "formula")
self.report_mode_cb.setStyleSheet(common_lineedit_css)
mode_row.addWidget(self.report_mode_cb, 1)
execute_layout.addLayout(mode_row)
# AI 专题图分析数量仅水色指数公式模式生效ML 模式忽略)
ai_maps_row = QHBoxLayout()
ai_maps_row.setContentsMargins(0, 0, 0, 0)
@ -401,6 +417,16 @@ class Step13ReportPanel(QWidget):
f"未找到可视化目录:\n{viz}\n请先完成流程或生成可视化。",
)
return
# 自动检测报告模式(参考 Step11 逻辑)
wd_path = Path(wd)
ml_dir = wd_path / "9_ML_Prediction"
formula_dir = wd_path / "10_WaterIndex_CSV"
if ml_dir.is_dir() and list(ml_dir.glob("*.csv")):
self.report_mode_cb.setCurrentIndex(0) # ML
elif formula_dir.is_dir() and list(formula_dir.glob("*.csv")):
self.report_mode_cb.setCurrentIndex(1) # 公式
if self._report_thread and self._report_thread.isRunning():
QMessageBox.information(self, "提示", "报告正在生成中,请稍候。")
return
@ -414,8 +440,9 @@ class Step13ReportPanel(QWidget):
self.progress_bar.setValue(0)
self.progress_label.setText("正在准备生成…")
report_mode = self.report_mode_cb.currentData()
ai_maps_limit = self.ai_maps_spin.value()
self._report_thread = ReportWorkerThread(wd, out, title, enable_ai, ai_maps_limit)
self._report_thread = ReportWorkerThread(wd, out, title, enable_ai, report_mode, ai_maps_limit)
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)