From 6d49e80c7e9176b5aabc79e67278dd4223ecaf0c Mon Sep 17 00:00:00 2001 From: dxc Date: Tue, 9 Jun 2026 13:38:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(gui):=20step8=5Fpanel=E6=94=B9=E7=94=A8Data?= =?UTF-8?q?PreparationStep=E8=AE=A1=E7=AE=97=E6=B0=B4=E8=B4=A8=E6=8C=87?= =?UTF-8?q?=E6=95=B0=EF=BC=8C=E7=BB=9F=E4=B8=80pipeline=E4=B8=8E=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E7=8B=AC=E7=AB=8B=E8=BF=90=E8=A1=8C=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/panels/step8_panel.py | 37 +++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/gui/panels/step8_panel.py b/src/gui/panels/step8_panel.py index 74a084a..092f59b 100644 --- a/src/gui/panels/step8_panel.py +++ b/src/gui/panels/step8_panel.py @@ -346,17 +346,38 @@ class Step8Panel(QWidget): output_mode = config['output_mode'] try: - from src.utils.water_index import WaterQualityIndexCalculator - - calculator = WaterQualityIndexCalculator(self.builtin_formula_path) + from src.core.steps.data_preparation_step import DataPreparationStep spec_df = pd.read_csv(training_path) x_col, y_col = self._get_coord_cols(spec_df) - results_df = calculator.calculate_many(formula_names, spec_df) - output_df = pd.concat([spec_df, results_df], axis=1) + # 构建 formula_csv_path(使用内置 waterindex.csv) + import os + formula_csv_path = self.builtin_formula_path + if not formula_csv_path or not os.path.exists(formula_csv_path): + # 尝试从 src/gui/model/ 目录找 + possible_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'gui', 'model', 'waterindex.csv') + if os.path.exists(possible_path): + formula_csv_path = possible_path work_dir = self._get_work_dir() + + # 调用 DataPreparationStep 的静态方法计算水质指数(宽表输出) + indices_csv_path = DataPreparationStep.calculate_water_quality_indices( + training_csv_path=training_path, + formula_csv_file=formula_csv_path, + formula_names=formula_names, + output_file=None, # 不在此处指定输出,由下面的双轨输出逻辑接管 + enabled=True, + output_dir=work_dir if work_dir else os.getcwd(), + ) + + # 读取计算结果(宽表) + if indices_csv_path and os.path.exists(indices_csv_path): + output_df = pd.read_csv(indices_csv_path) + else: + output_df = spec_df # fallback + track_a_path = None track_b_dir = None @@ -379,12 +400,12 @@ class Step8Panel(QWidget): coord_y = spec_df[y_col].values if y_col in spec_df.columns else np.zeros(len(spec_df)) for formula_name in formula_names: - if formula_name not in results_df.columns: + if formula_name not in output_df.columns: continue single_df = pd.DataFrame({ 'x_coord': coord_x, 'y_coord': coord_y, - 'value': results_df[formula_name].values, + 'value': output_df[formula_name].values, }) safe_name = formula_name.replace('/', '_').replace(' ', '_') out_path = os.path.join(track_b_dir, f"{safe_name}_prediction.csv") @@ -397,7 +418,7 @@ class Step8Panel(QWidget): ) except ImportError as e: - QMessageBox.critical(self, "依赖错误", f"无法导入 WaterQualityIndexCalculator:\n{e}") + QMessageBox.critical(self, "依赖错误", f"无法导入模块:\n{e}") except Exception as e: import traceback QMessageBox.critical(self, "计算失败", f"原因: {str(e)}\n{traceback.format_exc()}") \ No newline at end of file