feat: align prediction report with guidance

This commit is contained in:
2026-07-20 20:50:37 +08:00
parent 1223227ea9
commit fac2a2a2d2
4 changed files with 39 additions and 19 deletions
+10 -8
View File
@@ -56,7 +56,10 @@ FEATURES = [
ID_COLUMN = "管道编号"
PIPE_AGE_COLUMN = "管龄(年)"
REMAINING_LIFE_COLUMN = "预计剩余寿命(年)(管道健康状态 ≥0.5 的剩余年数)"
REMAINING_LIFE_COLUMN = (
"预计剩余寿命(年)(管道健康状态 ≥0.5 的剩余年数;"
"如管道健康状态在73年内均高于0.5,则为73减去当前管龄)"
)
LEGACY_PIPE_AGE_COLUMN = "管龄"
COLUMN_ALIASES = {
"ID": ID_COLUMN,
@@ -402,7 +405,7 @@ def make_analysis_text(summary_rows: list[dict[str, Any]]) -> str:
return (
"曲线表示模型对不同管道随管龄变化的健康状态动态预测。"
f"当前样本中风险最高管道为 {worst['pipe_id']}{worst['grade_label']}),"
f"当前健康状态最高管道为 {best['pipe_id']}{best['health_state']:.1%})。"
f"当前健康状态最高管道为 {best['pipe_id']}{best['health_state']:.2f})。"
)
@@ -460,9 +463,9 @@ def float_list(values: Any) -> list[float]:
return [float(value) for value in list(values)]
def format_years(value: float | None, current_age: float, max_age: float) -> str | float:
def format_years(value: float | None, current_age: float, max_age: float) -> float:
if value is None:
return f">{max(max_age - current_age, 0.0):g}"
return round(max(max_age - current_age, 0.0), 3)
return round(float(value), 3)
@@ -497,7 +500,7 @@ def render_survival_chart(predictions: list[dict[str, Any]], image_path: Path) -
summary_sheet_rows.append(
{
ID_COLUMN: pipe_id,
PIPE_AGE_COLUMN: pipe_age,
PIPE_AGE_COLUMN: current_age,
"当前健康状态": current_health_state,
"健康等级": grade_label,
REMAINING_LIFE_COLUMN: format_years(remaining_life, current_age, max_age),
@@ -509,7 +512,6 @@ def render_survival_chart(predictions: list[dict[str, Any]], image_path: Path) -
font_kwargs = chinese_font_kwargs()
plt.xlabel("管龄(年)", **font_kwargs)
plt.ylabel("管道健康状态", **font_kwargs)
plt.title("供水管道健康状态曲线", **font_kwargs)
plt.figtext(0.5, 0.02, display_note, ha="center", fontsize=9, color="#475569", **font_kwargs)
plt.grid(alpha=0.18)
if min(len(summary_rows), CHART_DISPLAY_LIMIT) <= 12:
@@ -561,7 +563,7 @@ def write_prediction_workbook(
sample_worksheet = writer.book["样本数据"]
summary_worksheet = writer.book["结果摘要"]
for cell in summary_worksheet["C"][1:]:
cell.number_format = "0.0%"
cell.number_format = "0.00"
sample_worksheet.freeze_panes = "A2"
sample_worksheet.auto_filter.ref = sample_worksheet.dimensions
sample_worksheet.column_dimensions["A"].width = 12
@@ -569,7 +571,7 @@ def write_prediction_workbook(
header_cell = column_cells[0]
sample_worksheet.column_dimensions[header_cell.column_letter].width = max(12, len(str(header_cell.value)) + 2)
for cell in column_cells[1:]:
cell.number_format = "0.0%"
cell.number_format = "0.00"
for sheet_name in ("结果摘要", "样本数据"):
worksheet = writer.book[sheet_name]