SKILL.md
唯讀
名稱
report-generator
描述
生成專業資料報告,包含圖表、表格與視覺化呈現
版本
1.0
報告產生器技能
概述
此技能可自動產生專業的資料報告。從您的資料建立儀表板、KPI 摘要以及包含圖表、表格和分析洞察的報告。
使用方式
- 提供資料(CSV、Excel、JSON 或直接描述)
- 指定需要的報告類型
- 我會產生一份包含視覺化圖表的格式化報告
範例提示:
- 「根據這份資料產生銷售報告」
- 「建立每月 KPI 儀表板」
- 「製作一份附圖表的執行摘要」
- 「產出資料分析報告」
領域知識
報告元件
# 報告結構
report = {
'title': 'Monthly Sales Report',
'period': 'January 2024',
'sections': [
'executive_summary',
'kpi_dashboard',
'detailed_analysis',
'charts',
'recommendations'
]
}
使用 Python 製作報告
import pandas as pd
import matplotlib.pyplot as plt
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
def generate_report(data, output_path):
# 載入資料
df = pd.read_csv(data)
# 計算 KPI
total_revenue = df['revenue'].sum()
avg_order = df['revenue'].mean()
growth = df['revenue'].pct_change().mean()
# 建立圖表
fig, axes = plt.subplots(2, 2, figsize=(12, 10))
df.plot(kind='bar', ax=axes[0,0], title='Revenue by Month')
df.plot(kind='line', ax=axes[0,1], title='Trend')
plt.savefig('charts.png')
# 產生 PDF
# ... PDF 產生程式碼
return output_path
HTML 報告範本
def generate_html_report(data, title):
html = f'''
<!DOCTYPE html>
<html>
<head>
<title>{title}</title>
<style>
body {{ font-family: Arial; margin: 40px; }}
.kpi {{ display: flex; gap: 20px; }}
.kpi-card {{ background: #f5f5f5; padding: 20px; border-radius: 8px; }}
.metric {{ font-size: 2em; font-weight: bold; color: #2563eb; }}
table {{ border-collapse: collapse; width: 100%; }}
th, td {{ border: 1px solid #ddd; padding: 12px; text-align: left; }}
</style>
</head>
<body>
<h1>{title}</h1>
<div class="kpi">
<div class="kpi-card">
<div class="metric">${data['revenue']:,.0f}</div>
<div>Total Revenue</div>
</div>
<div class="kpi-card">
<div class="metric">{data['growth']:.1%}</div>
<div>Growth Rate</div>
</div>
</div>
<!-- 更多內容 -->
</body>
</html>
'''
return html
範例:銷售報告
import pandas as pd
import matplotlib.pyplot as plt
def create_sales_report(csv_path, output_path):
# 讀取資料
df = pd.read_csv(csv_path)
# 計算指標
metrics = {
'total_revenue': df['amount'].sum(),
'total_orders': len(df),
'avg_order': df['amount'].mean(),
'top_product': df.groupby('product')['amount'].sum().idxmax()
}
# 建立視覺化圖表
fig, axes = plt.subplots(2, 2, figsize=(14, 10))
# 各產品營收
df.groupby('product')['amount'].sum().plot(
kind='bar', ax=axes[0,0], title='Revenue by Product'
)
# 每月趨勢
df.groupby('month')['amount'].sum().plot(
kind='line', ax=axes[0,1], title='Monthly Revenue'
)
plt.tight_layout()
plt.savefig(output_path.replace('.html', '_charts.png'))
# 產生 HTML 報告
html = generate_html_report(metrics, 'Sales Report')
with open(output_path, 'w') as f:
f.write(html)
return output_path
create_sales_report('sales_data.csv', 'sales_report.html')






