SKILL.md 8.6 KB


name: generate-data-report-ppt description: > 通用数据报告 PPT 生成器。输入任意 Excel 数据文件,自动探查数据结构、计算指标、通过六项用户确认后生成高质量 PPT 报告。 图表使用原生 python-pptx 可编辑 Chart 对象(非 matplotlib PNG 插入)。

内置质量自检引擎,自动检测布局/视觉/内容/数据问题并迭代修复至理想效果。

通用数据报告 PPT 生成器

输入任意 Excel 文件,自动生成高质量可编辑数据报告 PPT。

工作流程

  1. 接收 Excel 文件:用户提供任意格式的 Excel 数据文件。
  2. 数据探查scripts/data_profiler.py 自动检测 Schema、统计特征、数据质量及字段语义。
  3. 智能分析与推荐scripts/agent_analyzer.py 基于探查结果生成指标推荐、页面结构建议及可视化方案。
  4. 用户确认(六项):生成 PPT 前必须与用户确认以下内容:
    • 报告周期与页数范围
    • 核心指标集
    • 受众与决策场景
    • 视觉风格与配色方向
    • 页面结构与模板方案
    • (合计六项确认内容)
  5. 生成 PPTscripts/ppt_builder.py 按用户确认的配置,动态选择布局模板、应用主题配色、插入原生可编辑图表。
  6. 质量自检与修复scripts/quality_inspector.py 检查四类 25 项质量标准,发现问题自动修复,迭代至阈值达标。
  7. 输出:保存 .pptx 文件。所有图表和表格均可在 PowerPoint 中编辑。

目录结构

generate-data-report-ppt/
├── SKILL.md
├── scripts/
│   ├── data_loader.py              # Excel 加载与数据清洗(保留原有兼容)
│   ├── data_profiler.py            # 通用数据探查引擎(新增)
│   ├── report_config.py            # ReportConfig 数据模型定义(新增)
│   ├── theme_manager.py            # 多主题配色与模板管理(新增)
│   ├── agent_analyzer.py           # LLM 智能分析与推荐(新增)
│   ├── metrics_calculator.py       # KPI 计算引擎(新增通用计算函数)
│   ├── chart_factory.py            # 原生可编辑图表创建
│   ├── page_layouts.py             # 动态页面布局引擎(新增)
│   ├── quality_rules.py            # 质量检查规则定义(新增)
│   ├── quality_inspector.py        # 质量自检与自动修复引擎(新增)
│   ├── deep_insights.py            # 结构化深度洞察生成(周报/月报)
│   └── ppt_builder.py              # PPT 组装编排器(新增 build_report / quality_assured_build)
├── references/
│   ├── data-schema.md              # Excel 字段映射与校验规则
│   ├── report-structures.md        # 日报/周报/月报页面结构
│   ├── chart-specs.md              # 原生图表类型、配色、数据绑定
│   └── visual-style-guide.md       # 布局、字体、配色方案
└── assets/
    ├── report-master.pptx          # 日报模板(封面、内容页、目录、尾页)
    ├── weekly-master.pptx          # 周报模板
    └── monthly-master.pptx         # 月报模板

新增核心模块

ReportConfig(report_config.py)

通用数据模型,定义报告配置的所有要素:

  • ReportConfig:报告标题、周期、数据来源、主题、页数范围、质量阈值、最大修复迭代次数
  • MetricDef:指标名称、列映射、聚合方式、数值格式、单位、指标类型
  • PageDef:页面类型、标题、结论标题、布局模板、可选图表类型、选中状态
  • PeriodType 枚举:DAILY / WEEKLY / MONTHLY / CUSTOM
  • ChartType 枚举:BAR / LINE / PIE / DOUGHNUT / FUNNEL / TABLE / AUTO

数据探查(data_profiler.py)

自动分析任意 Excel 数据结构:

  • Schema 检测:列名、类型推断、缺失率、唯一值统计
  • 统计特征提取:数值列的 min/max/mean/std/分位数,分类列的分布/基数
  • 语义推断:自动识别时间列、分类列、数值列、ID 列
  • 数据质量评分:完整性、唯一性、合理性三维度评分

多主题管理(theme_manager.py)

  • 5 套预设主题:商务经典(默认)、清新简约、科技蓝调、暖橙活力、暗夜深邃
  • 每套主题包含:主色、辅色、强调色、背景色、文字色、系列色盘
  • 支持自定义配色覆盖
  • theme_to_rgb_colors() 一键转换为 pptx RGBColor 对象

智能分析(agent_analyzer.py)

  • 自动识别可量化的数值指标
  • 推荐可视化方案(图表类型、配色、数据准备方式)
  • 生成页面结构建议(含结论标题和洞察文案模板)
  • 所有推荐需经用户确认后注入 ReportConfig

页面布局引擎(page_layouts.py)

  • 预定义布局模板:KPI 网格、图表左+洞察右、两栏、两行、卡片网格、全宽
  • calculate_content_area() 计算可用内容区域
  • calculate_fill_ratio() 计算页面内容填充率
  • ensure_safe_position() 确保元素在页面安全区域内

质量自检(quality_rules.py + quality_inspector.py)

四类 25 项检查规则

类别 检查项 自动修复
layout(布局) 元素飞出边界(4方向)、图文重叠、占位符未替换、元素紧贴边缘
visual(视觉) 字体不一致、字号过小/过大、颜色对比度不足、图片拉伸变形
content(内容) 页面留白过多、KPI数值为空、图表无数据、文本截断、分析文本过短、缺少标题
data(数据) 图表与文本矛盾、页码错乱、数据来源缺失、表格列宽不合理、图表刻度异常 部分

迭代修复机制

  1. 生成 PPT → 执行全量检查 → 报告问题
  2. 对可自动修复的问题执行修复 → 重新检查
  3. 重复至无严重/主要问题或达最大迭代次数
  4. 计算质量评分(0-100),评分 ≥ 阈值(默认 85)输出

质量评分计算

  • 严重问题:-20 分/页
  • 主要问题:-10 分/页
  • 次要问题:-3 分/页
  • 加权归一化到 100 分制

报告类型(原有,保持兼容)

日报

  • 结构:封面 → 核心指标概览 → 近10天趋势 → 订单状态分布 → 负责人分布 → 目的国家 TOP8 → 异常告警 → 今日要点
  • 页数:8

    周报

  • 结构:封面 → 周汇总 → 7日趋势 → 环比分析 → 区域分布 → 国家排行 → 团队追踪 → 问题与建议 → 下周计划

  • 页数:9

    月报

  • 结构:封面 → 目录 → 月度总览 → 订单状态漏斗 → 区域分布 → TOP10 目的国 → 30日追踪趋势 → 团队绩效 → 支持需求分析 → 下月规划 → 尾页

  • 页数:11

执行示例

from scripts.ppt_builder import build_daily_report, build_report, quality_assured_build
from scripts.report_config import ReportConfig, PageDef, MetricDef

# === 原有方式(保持兼容)===
build_daily_report('data.xlsx', datetime(2026, 4, 10), 'daily.pptx')

# === 新通用方式 ===
config = ReportConfig(
    title='销售数据报告',
    period_type='monthly',
    source_label='销售部',
    theme='business_classic',
    quality_threshold=85,
    max_fix_iterations=3,
)
# config 需经用户确认后填充 metrics 和 pages

build_report('any_data.xlsx', config, 'output.pptx')

# === 带质量保证的方式(推荐)===
prs, issues = quality_assured_build('any_data.xlsx', config, 'output_qa.pptx')

V2 generation contract

Before calling build_report or quality_assured_build, fill and validate the six user confirmations:

  1. 报告周期与页数范围
  2. 核心指标集
  3. 受众与决策场景
  4. 视觉风格与配色方向
  5. 页面结构与模板方案
  6. 数据范围与字段映射

Use ConfirmationSpec on ReportConfig.user_confirmation to record completion. Generic builds default to require_six_confirmations=True; missing confirmations or invalid metric-to-column mappings must stop generation before any PPT is written.

Data profiling serves the confirmed business intent. It should map the confirmed metrics and dimensions to actual Excel columns, then select feasible pages and layouts. It must not invent a different business focus when the user has already confirmed the core metrics.

For visual quality, treat master PPTX files as style assets, not rigid page contracts. If a template placeholder cannot be populated, remove the whole placeholder component. If a KPI grid consumes the available vertical space, do not add bottom insight text; use a later analysis page or a different layout instead.