feat(visualization+report): 接入 Step9 浓度反演数据至可视化面板与报告生成器
This commit is contained in:
@ -834,7 +834,12 @@ class WaterQualityReportGenerator:
|
||||
figure_counter = self._add_result_analysis_section(
|
||||
doc, vis_dir, figure_counter, all_image_analyses, progress=progress
|
||||
)
|
||||
|
||||
|
||||
# 物理模型反演浓度统计与分析(第4.1节)
|
||||
figure_counter = self._add_physical_inversion_section(
|
||||
doc, self.work_dir, figure_counter, all_image_analyses, progress=progress
|
||||
)
|
||||
|
||||
# 设置页眉和页码(从正文开始)
|
||||
self._setup_header_and_footer(section)
|
||||
|
||||
@ -1747,6 +1752,90 @@ class WaterQualityReportGenerator:
|
||||
doc.add_page_break()
|
||||
return start_figure_num + (1 if heatmap_path.exists() else 0)
|
||||
|
||||
def _add_physical_inversion_section(
|
||||
self,
|
||||
doc: Document,
|
||||
work_dir: Path,
|
||||
start_figure_num: int = 1,
|
||||
all_image_analyses: Optional[List[Dict[str, Any]]] = None,
|
||||
progress=None,
|
||||
) -> int:
|
||||
"""新增章节:物理模型反演浓度统计与分析(第4节之后)"""
|
||||
conc_dir = work_dir / "9_Concentration"
|
||||
if not conc_dir.is_dir():
|
||||
doc.add_paragraph("[物理反演浓度章节:9_Concentration 目录不存在,已跳过]")
|
||||
return start_figure_num
|
||||
|
||||
stats_csv = conc_dir / "statistics_summary.csv"
|
||||
charts_dir = conc_dir / "charts"
|
||||
|
||||
h = doc.add_heading("4.1 物理模型反演浓度统计与分析", level=2)
|
||||
self._style_heading(h, level=2)
|
||||
|
||||
fig_num = start_figure_num
|
||||
|
||||
if stats_csv.is_file():
|
||||
try:
|
||||
stats_df = pd.read_csv(stats_csv)
|
||||
table = doc.add_table(rows=1, cols=len(stats_df.columns))
|
||||
table.style = "Table Grid"
|
||||
hdr_cells = table.rows[0].cells
|
||||
for i, col_name in enumerate(stats_df.columns):
|
||||
hdr_cells[i].text = str(col_name)
|
||||
for run in hdr_cells[i].paragraphs[0].runs:
|
||||
run.font.name = self.chinese_font
|
||||
run.font.size = Pt(10)
|
||||
run.font.bold = True
|
||||
run._element.rPr.rFonts.set(qn('w:eastAsia'), self.chinese_font)
|
||||
for _, row_data in stats_df.iterrows():
|
||||
row_cells = table.add_row().cells
|
||||
for i, val in enumerate(row_data):
|
||||
row_cells[i].text = str(val)
|
||||
for run in row_cells[i].paragraphs[0].runs:
|
||||
run.font.name = self.chinese_font
|
||||
run.font.size = Pt(10)
|
||||
run._element.rPr.rFonts.set(qn('w:eastAsia'), self.chinese_font)
|
||||
doc.add_paragraph()
|
||||
except Exception as e:
|
||||
doc.add_paragraph(f"[浓度统计表插入失败: {e}]")
|
||||
else:
|
||||
doc.add_paragraph("[浓度统计表不存在: statistics_summary.csv]")
|
||||
|
||||
if charts_dir.is_dir():
|
||||
image_extensions = ['*.png', '*.jpg', '*.jpeg', '*.tif', '*.tiff']
|
||||
chart_files: List[Path] = []
|
||||
for ext in image_extensions:
|
||||
chart_files.extend(sorted(charts_dir.glob(ext)))
|
||||
for chart_file in chart_files:
|
||||
caption_text = f"图{fig_num} {chart_file.stem} 分布图"
|
||||
if self._add_image_with_caption(doc, str(chart_file), caption_text, width=Inches(5.5)):
|
||||
if all_image_analyses is not None:
|
||||
image_type = "boxplot" if "boxplot" in chart_file.stem.lower() else "distribution"
|
||||
analysis_text = self._analyze_and_cache_image(
|
||||
image_path=chart_file,
|
||||
image_type=image_type,
|
||||
param=chart_file.stem,
|
||||
figure_num=fig_num,
|
||||
)
|
||||
self._add_ai_analysis_paragraph(doc, analysis_text)
|
||||
all_image_analyses.append({
|
||||
"figure_num": fig_num,
|
||||
"param": chart_file.stem,
|
||||
"image_type": image_type,
|
||||
"image_name": chart_file.name,
|
||||
"analysis": analysis_text,
|
||||
})
|
||||
fig_num += 1
|
||||
try:
|
||||
if progress is not None:
|
||||
progress.update(1)
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
doc.add_paragraph("[浓度图表目录不存在: 9_Concentration/charts/]")
|
||||
|
||||
return fig_num
|
||||
|
||||
# ==================== 使用示例 ====================
|
||||
|
||||
def generate_full_water_quality_report(
|
||||
|
||||
Reference in New Issue
Block a user