fix(report/template): 迁移到应该使用的 jinja2 (#47)

* fix(report/template): 迁移到应该使用的 jinja2

* fix(topic): 纠正 topic jinja2 模板

* log(generate): debug

* fix(generator): 之前的代码直接将原始模板字符串和渲染数据分开传递给 html_render_func,但 html_render_func 期望接收的是已经渲染好的完整HTML内容

* fix(template): debug

* debug

* fix(debug): 删除冗余的日志调试

* fix(code quality): cr
This commit is contained in:
Helian Nuits
2025-11-22 01:43:27 +08:00
committed by GitHub
parent 8287452688
commit e12b8d56e0
7 changed files with 1210 additions and 1119 deletions
+86 -83
View File
@@ -19,6 +19,7 @@ class ReportGenerator:
def __init__(self, config_manager):
self.config_manager = config_manager
self.activity_visualizer = ActivityVisualizer()
self.html_templates = HTMLTemplates() # 实例化HTML模板管理器
async def generate_image_report(
self, analysis_result: dict, group_id: str, html_render_func
@@ -27,7 +28,20 @@ class ReportGenerator:
try:
# 准备渲染数据
render_payload = await self._prepare_render_data(analysis_result)
# 使用AstrBot内置的HTML渲染服务(直接传递模板和数据)
# 先渲染HTML模板
html_content = self._render_html_template(
self.html_templates.get_image_template(), render_payload
)
# 检查HTML内容是否有效
if not html_content:
logger.error("图片报告HTML渲染失败:返回空内容")
return None
logger.info(f"图片报告HTML渲染完成,长度: {len(html_content)} 字符")
# 使用AstrBot内置的HTML渲染服务(传递渲染后的HTML)
# 使用兼容的图片生成选项(基于NetworkRenderStrategy的默认设置)
image_options = {
"full_page": True,
@@ -35,8 +49,8 @@ class ReportGenerator:
"quality": 95, # 设置合理的质量
}
image_url = await html_render_func(
HTMLTemplates.get_image_template(),
render_payload,
html_content, # 渲染后的HTML内容
{}, # 空数据字典,因为数据已包含在HTML中
True, # return_url=True,返回URL而不是下载文件
image_options,
)
@@ -55,8 +69,8 @@ class ReportGenerator:
"quality": 70, # 降低质量以提高兼容性
}
image_url = await html_render_func(
HTMLTemplates.get_image_template(),
render_payload,
html_content, # 使用已渲染的HTML
{}, # 空数据字典
True,
simple_options,
)
@@ -86,10 +100,16 @@ class ReportGenerator:
render_data = await self._prepare_render_data(analysis_result)
logger.info(f"PDF 渲染数据准备完成,包含 {len(render_data)} 个字段")
# 生成 HTML 内容(PDF模板使用{}占位符)
# 生成 HTML 内容(PDF模板使用{{}}占位符)
html_content = self._render_html_template(
HTMLTemplates.get_pdf_template(), render_data, use_jinja_style=False
self.html_templates.get_pdf_template(), render_data
)
# 检查HTML内容是否有效
if not html_content:
logger.error("PDF报告HTML渲染失败:返回空内容")
return None
logger.info(f"HTML 内容生成完成,长度: {len(html_content)} 字符")
# 转换为 PDF
@@ -152,69 +172,68 @@ class ReportGenerator:
user_titles = analysis_result["user_titles"]
activity_viz = stats.activity_visualization
# 构建话题HTML
topics_html = ""
# 使用Jinja2模板构建话题HTML(批量渲染)
max_topics = self.config_manager.get_max_topics()
topics_list = []
for i, topic in enumerate(topics[:max_topics], 1):
contributors_str = "".join(topic.contributors)
topics_html += f"""
<div class="topic-item">
<div class="topic-header">
<span class="topic-number">{i}</span>
<span class="topic-title">{topic.topic}</span>
</div>
<div class="topic-contributors">参与者: {contributors_str}</div>
<div class="topic-detail">{topic.detail}</div>
</div>
"""
topics_list.append(
{
"index": i,
"topic": topic,
"contributors": "".join(topic.contributors),
}
)
# 构建用户称号HTML(包含头像)
titles_html = ""
topics_html = self.html_templates.render_template(
"topic_item.html", topics=topics_list
)
logger.info(f"话题HTML生成完成,长度: {len(topics_html)}")
# 使用Jinja2模板构建用户称号HTML(批量渲染,包含头像)
max_user_titles = self.config_manager.get_max_user_titles()
titles_list = []
for title in user_titles[:max_user_titles]:
# 获取用户头像
avatar_data = await self._get_user_avatar(str(title.qq))
avatar_html = (
f'<img src="{avatar_data}" class="user-avatar" alt="头像">'
if avatar_data
else '<div class="user-avatar-placeholder">👤</div>'
title_data = {
"name": title.name,
"title": title.title,
"mbti": title.mbti,
"reason": title.reason,
"avatar_data": avatar_data,
}
titles_list.append(title_data)
titles_html = self.html_templates.render_template(
"user_title_item.html", titles=titles_list
)
logger.info(f"用户称号HTML生成完成,长度: {len(titles_html)}")
# 使用Jinja2模板构建金句HTML(批量渲染)
max_golden_quotes = self.config_manager.get_max_golden_quotes()
quotes_list = []
for quote in stats.golden_quotes[:max_golden_quotes]:
quotes_list.append(
{
"content": quote.content,
"sender": quote.sender,
"reason": quote.reason,
}
)
titles_html += f"""
<div class="user-title">
<div class="user-info">
{avatar_html}
<div class="user-details">
<div class="user-name">{title.name}</div>
<div class="user-badges">
<div class="user-title-badge">{title.title}</div>
<div class="user-mbti">{title.mbti}</div>
</div>
</div>
</div>
<div class="user-reason">{title.reason}</div>
</div>
"""
# 构建金句HTML
quotes_html = ""
max_golden_quotes = self.config_manager.get_max_golden_quotes()
for quote in stats.golden_quotes[:max_golden_quotes]:
quotes_html += f"""
<div class="quote-item">
<div class="quote-content">"{quote.content}"</div>
<div class="quote-author">—— {quote.sender}</div>
<div class="quote-reason">{quote.reason}</div>
</div>
"""
quotes_html = self.html_templates.render_template(
"quote_item.html", quotes=quotes_list
)
logger.info(f"金句HTML生成完成,长度: {len(quotes_html)}")
# 生成活跃度可视化HTML
hourly_chart_html = self.activity_visualizer.generate_hourly_chart_html(
activity_viz.hourly_activity
)
logger.info(f"活跃度图表HTML生成完成,长度: {len(hourly_chart_html)}")
# 返回扁平化的渲染数据
return {
# 准备最终渲染数据
render_data = {
"current_date": datetime.now().strftime("%Y年%m月%d"),
"current_datetime": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
"message_count": stats.message_count,
@@ -237,46 +256,30 @@ class ReportGenerator:
else 0,
}
def _render_html_template(
self, template: str, data: dict, use_jinja_style: bool = False
) -> str:
"""HTML模板渲染,支持两种占位符格式
logger.info(f"渲染数据准备完成,包含 {len(render_data)} 个字段")
return render_data
def _render_html_template(self, template: str, data: dict) -> str:
"""HTML模板渲染,使用 {{key}} 占位符格式
Args:
template: HTML模板字符串
data: 渲染数据
use_jinja_style: 是否使用Jinja2风格的{{ }}占位符,否则使用{}占位符
data: 渲染数据字典
"""
result = template
# 调试:记录渲染数据
logger.info(
f"渲染数据键: {list(data.keys())}, 使用Jinja风格: {use_jinja_style}"
)
for key, value in data.items():
if use_jinja_style:
# 图片模板使用{{ }}占位符
placeholder = f"{{{{ {key} }}}}"
else:
# PDF模板使用{}占位符
placeholder = f"{{{key}}}"
# 调试:记录替换过程
if placeholder in result:
logger.debug(f"替换 {placeholder} -> {str(value)[:100]}...")
# 统一使用双大括号格式 {{key}}
placeholder = "{{" + key + "}}"
result = result.replace(placeholder, str(value))
# 检查是否还有未替换的占位符
import re
if use_jinja_style:
remaining_placeholders = re.findall(r"\{\{[^}]+\}\}", result)
else:
remaining_placeholders = re.findall(r"\{[^}]+\}", result)
if remaining_placeholders:
logger.warning(f"未替换的占位符: {remaining_placeholders[:10]}")
if remaining_placeholders := re.findall(r"\{\{[^}]+\}\}", result):
logger.warning(
f"未替换的占位符 ({len(remaining_placeholders)}个): {remaining_placeholders[:10]}"
)
return result
+60 -1036
View File
File diff suppressed because it is too large Load Diff
+584
View File
@@ -0,0 +1,584 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>群聊日常分析报告</title>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;700&display=swap" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Noto Sans SC', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
min-height: 100vh;
padding: 30px;
line-height: 1.6;
color: #1a1a1a;
}
.container {
max-width: 1400px;
margin: 0 auto;
background: #ffffff;
border-radius: 20px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
overflow: hidden;
}
.header {
background: linear-gradient(135deg, #4299e1 0%, #667eea 100%);
color: #ffffff;
padding: 60px 50px;
text-align: center;
border-radius: 30px 30px 0 0;
}
.header h1 {
font-size: 3.2em;
font-weight: 300;
margin-bottom: 16px;
letter-spacing: -1px;
}
.header .date {
font-size: 1.2em;
opacity: 0.8;
font-weight: 300;
letter-spacing: 0.5px;
}
.content {
padding: 40px;
}
.topics-grid,
.users-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 25px;
align-items: stretch;
}
.section {
margin-bottom: 0;
}
.full-width-section {
grid-column: 1 / -1;
margin-bottom: 40px;
}
.section-title {
font-size: 1.6em;
font-weight: 600;
margin-bottom: 25px;
color: #4a5568;
letter-spacing: -0.3px;
display: flex;
align-items: center;
gap: 10px;
border-bottom: 2px solid #e2e8f0;
padding-bottom: 10px;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 25px;
margin-bottom: 40px;
}
.stat-card {
background: linear-gradient(135deg, #f7fafc 0%, #edf2f7 100%);
padding: 40px 30px;
text-align: center;
border-radius: 25px;
border: 1px solid #e2e8f0;
transition: all 0.3s ease;
}
.stat-number {
font-size: 3.2em;
font-weight: 300;
color: #4299e1;
margin-bottom: 10px;
display: block;
letter-spacing: -1px;
}
.stat-label {
font-size: 1em;
color: #666666;
font-weight: 400;
text-transform: uppercase;
letter-spacing: 1px;
}
.active-period {
background: linear-gradient(135deg, #4299e1 0%, #667eea 100%);
color: #ffffff;
padding: 40px;
text-align: center;
margin: 60px 0;
border-radius: 25px;
box-shadow: 0 8px 24px rgba(66, 153, 225, 0.3);
}
.active-period .time {
font-size: 3.2em;
font-weight: 200;
margin-bottom: 10px;
letter-spacing: -1px;
}
.active-period .label {
font-size: 1em;
opacity: 0.8;
font-weight: 300;
text-transform: uppercase;
letter-spacing: 1px;
}
.topic-item {
background: #ffffff;
padding: 25px;
margin-bottom: 0;
border-radius: 15px;
border: 1px solid #e5e5e5;
transition: all 0.3s ease;
display: flex;
flex-direction: column;
height: 100%;
box-sizing: border-box;
}
.topic-header {
display: flex;
align-items: center;
margin-bottom: 20px;
}
.topic-number {
background: linear-gradient(135deg, #3182ce 0%, #2c5282 100%);
color: #ffffff;
width: 40px;
height: 40px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-weight: 500;
margin-right: 16px;
font-size: 1em;
box-shadow: 0 4px 12px rgba(49, 130, 206, 0.3);
}
.topic-title {
font-weight: 600;
color: #2d3748;
font-size: 1.3em;
letter-spacing: -0.3px;
}
.topic-contributors {
color: #666666;
font-size: 1em;
margin-bottom: 16px;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.topic-detail {
color: #333333;
line-height: 1.6;
font-size: 1em;
font-weight: 300;
}
.user-title {
background: #ffffff;
padding: 20px;
margin-bottom: 0;
border-radius: 15px;
border: 1px solid #e5e5e5;
display: flex;
align-items: flex-start;
justify-content: space-between;
transition: all 0.3s ease;
min-height: 100px;
height: 100%;
box-sizing: border-box;
}
.user-info {
display: flex;
align-items: center;
flex: 1;
}
.user-avatar {
width: 50px;
height: 50px;
border-radius: 50%;
margin-right: 20px;
border: 2px solid #f0f0f0;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.user-avatar-placeholder {
width: 50px;
height: 50px;
border-radius: 50%;
background: linear-gradient(135deg, #f0f0f0 0%, #e2e8f0 100%);
display: flex;
align-items: center;
justify-content: center;
margin-right: 20px;
font-size: 1.2em;
color: #999999;
border: 2px solid #e5e5e5;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.user-details {
flex: 1;
}
.user-name {
font-weight: 600;
color: #2d3748;
margin-bottom: 15px;
font-size: 1.2em;
letter-spacing: -0.2px;
}
.user-badges {
display: flex;
align-items: center;
gap: 15px;
flex-wrap: nowrap;
overflow-x: auto;
}
.user-title-badge,
.user-mbti {
white-space: nowrap;
display: inline-flex;
align-items: center;
}
.user-title-badge {
background: linear-gradient(135deg, #4299e1 0%, #3182ce 100%);
color: #ffffff;
padding: 8px 20px;
border-radius: 25px;
font-size: 0.9em;
font-weight: 500;
text-transform: uppercase;
letter-spacing: 0.5px;
box-shadow: 0 2px 8px rgba(66, 153, 225, 0.3);
}
.user-mbti {
background: linear-gradient(135deg, #667eea 0%, #5a67d8 100%);
color: #ffffff;
padding: 8px 15px;
border-radius: 20px;
font-weight: 500;
font-size: 0.9em;
text-transform: uppercase;
letter-spacing: 1px;
box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}
.user-reason {
color: #666666;
font-size: 1em;
text-align: right;
line-height: 1.4;
font-weight: 300;
margin-left: 20px;
flex: 1;
word-wrap: break-word;
overflow-wrap: break-word;
}
.quote-item {
background: #ffffff;
padding: 16px;
margin-bottom: 16px;
border-radius: 12px;
border: 1px solid #e2e8f0;
position: relative;
transition: all 0.3s ease;
}
.quote-content {
font-size: 1.1em;
color: #2d3748;
font-weight: 500;
line-height: 1.6;
margin-bottom: 12px;
font-style: italic;
letter-spacing: 0.2px;
}
.quote-author {
font-size: 0.9em;
color: #4299e1;
font-weight: 600;
margin-bottom: 8px;
text-align: right;
}
.quote-reason {
font-size: 0.8em;
color: #666666;
font-style: normal;
background: rgba(66, 153, 225, 0.1);
padding: 8px 12px;
border-radius: 12px;
border-left: 3px solid #4299e1;
}
.footer {
background: linear-gradient(135deg, #3182ce 0%, #2c5282 100%);
color: #ffffff;
text-align: center;
padding: 40px;
font-size: 1em;
font-weight: 300;
letter-spacing: 0.5px;
opacity: 0.9;
}
/* 活跃度可视化样式 - 重新设计 */
.activity-section {
background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
padding: 50px;
border-radius: 25px;
margin: 50px 0;
border: 1px solid #e2e8f0;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}
.activity-chart-container {
background: #ffffff;
padding: 40px;
border-radius: 20px;
border: 1px solid #e2e8f0;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
}
.chart-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 40px;
padding-bottom: 20px;
border-bottom: 2px solid #f0f2f5;
}
.chart-title {
font-size: 1.6em;
font-weight: 600;
color: #2d3748;
display: flex;
align-items: center;
gap: 15px;
}
.chart-subtitle {
color: #7f8c8d;
font-size: 1.1em;
font-weight: 400;
}
.hour-bar-container {
display: flex;
align-items: center;
margin: 12px 0;
height: 25px;
transition: all 0.2s ease;
}
.hour-label {
width: 65px;
text-align: left;
color: #4a5568;
font-size: 15px;
font-weight: 500;
flex-shrink: 0;
}
.bar-wrapper {
display: flex;
align-items: center;
flex-grow: 1;
gap: 15px;
min-width: 0;
}
.bar {
height: 12px;
background: linear-gradient(90deg, #4299e1 0%, #667eea 100%);
border-radius: 8px;
transition: all 0.3s ease-out;
display: flex;
justify-content: flex-end;
align-items: center;
overflow: hidden;
box-shadow: 0 2px 8px rgba(66, 153, 225, 0.2);
}
.hourly-value-outside {
color: #4a5568;
font-size: 14px;
font-weight: 600;
flex-shrink: 0;
min-width: 35px;
text-align: right;
}
.hourly-value-inside {
color: white;
font-size: 13px;
padding: 0 10px;
font-weight: 600;
white-space: nowrap;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
@media (min-width: 1400px) {
.container {
max-width: 1600px;
}
.topics-grid {
grid-template-columns: repeat(3, 1fr);
}
.users-grid {
grid-template-columns: repeat(3, 1fr);
}
}
@media (max-width: 768px) {
body {
padding: 15px;
}
.container {
margin: 0;
max-width: 100%;
}
.header {
padding: 30px 25px;
}
.header h1 {
font-size: 2.2em;
}
.content {
padding: 25px;
}
.topics-grid {
grid-template-columns: 1fr;
}
.users-grid {
grid-template-columns: 1fr;
}
.stats-grid {
grid-template-columns: 1fr 1fr;
gap: 15px;
}
.stat-card {
padding: 25px 20px;
}
.topic-item {
padding: 25px;
}
.user-title {
flex-direction: column;
align-items: flex-start;
gap: 15px;
padding: 20px;
min-height: auto;
}
.user-info {
width: 100%;
}
.user-reason {
text-align: left;
max-width: none;
margin-left: 0;
margin-top: 10px;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>📊 群聊日常分析报告</h1>
<div class="date">{{current_date}}</div>
</div>
<div class="content">
<div class="section full-width-section">
<h2 class="section-title">📈 基础统计</h2>
<div class="stats-grid">
<div class="stat-card"><div class="stat-number">{{message_count}}</div><div class="stat-label">消息总数</div></div>
<div class="stat-card"><div class="stat-number">{{participant_count}}</div><div class="stat-label">参与人数</div></div>
<div class="stat-card"><div class="stat-number">{{total_characters}}</div><div class="stat-label">总字符数</div></div>
<div class="stat-card"><div class="stat-number">{{emoji_count}}</div><div class="stat-label">表情数量</div></div>
</div>
<div class="active-period">
<div class="time">{{most_active_period}}</div>
<div class="label">最活跃时段</div>
</div>
</div>
<!-- 活跃度可视化部分 - 重新设计 -->
<div class="activity-chart-container">
<div class="chart-header">
<div>
<div class="chart-title">⏱️ 24小时活跃度分布</div>
</div>
</div>
{{hourly_chart_html}}
</div>
<div class="section">
<h2 class="section-title">💬 热门话题</h2>
<div class="topics-grid">{{topics_html}}</div>
</div>
<div class="section">
<h2 class="section-title">🏆 群友称号</h2>
<div class="users-grid">{{titles_html}}</div>
</div>
<div class="section">
<h2 class="section-title">💬 群圣经</h2>
{{quotes_html}}
</div>
</div>
<div class="footer">
由 AstrBot QQ群日常分析插件 生成 | {{current_datetime}} | SXP-Simon/astrbot-qq-group-daily-analysis<br>
<small style="opacity: 0.8; font-size: 0.9em;">🤖 AI分析消耗:{{total_tokens}} tokens (输入: {{prompt_tokens}}, 输出: {{completion_tokens}})</small>
</div>
</div>
</body>
</html>
+444
View File
@@ -0,0 +1,444 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>群聊日常分析报告</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Microsoft YaHei', 'SimHei', sans-serif;
background: #ffffff;
color: #1a1a1a;
line-height: 1.6;
font-size: 14px;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.header {
background: linear-gradient(135deg, #4299e1 0%, #667eea 100%);
color: #ffffff;
padding: 30px;
text-align: center;
border-radius: 12px;
margin-bottom: 30px;
}
.header h1 {
font-size: 28px;
font-weight: 600;
margin-bottom: 8px;
}
.header .date {
font-size: 16px;
opacity: 0.9;
}
.section {
margin-bottom: 40px;
page-break-inside: avoid;
}
.section-title {
font-size: 20px;
font-weight: 600;
margin-bottom: 20px;
color: #4a5568;
border-bottom: 2px solid #4299e1;
padding-bottom: 8px;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 15px;
margin-bottom: 30px;
}
.stat-card {
background: #f8f9ff;
padding: 20px;
text-align: center;
border-radius: 8px;
border: 1px solid #e2e8f0;
}
.stat-number {
font-size: 24px;
font-weight: 600;
color: #4299e1;
margin-bottom: 5px;
}
.stat-label {
font-size: 12px;
color: #666666;
text-transform: uppercase;
}
.active-period {
background: linear-gradient(135deg, #4299e1 0%, #667eea 100%);
color: #ffffff;
padding: 25px;
text-align: center;
margin: 30px 0;
border-radius: 8px;
}
.active-period .time {
font-size: 28px;
font-weight: 300;
margin-bottom: 5px;
}
.active-period .label {
font-size: 14px;
opacity: 0.9;
}
.topic-item {
background: #ffffff;
padding: 20px;
margin-bottom: 15px;
border-radius: 8px;
border: 1px solid #e2e8f0;
page-break-inside: avoid;
}
.topic-header {
display: flex;
align-items: center;
margin-bottom: 12px;
}
.topic-number {
background: #4299e1;
color: #ffffff;
width: 24px;
height: 24px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-weight: 600;
margin-right: 12px;
font-size: 12px;
}
.topic-title {
font-weight: 600;
color: #2d3748;
font-size: 16px;
}
.topic-contributors {
color: #666666;
font-size: 12px;
margin-bottom: 10px;
}
.topic-detail {
color: #333333;
line-height: 1.6;
font-size: 14px;
}
.user-title {
background: #ffffff;
padding: 20px;
margin-bottom: 15px;
border-radius: 8px;
border: 1px solid #e2e8f0;
display: flex;
align-items: flex-start;
justify-content: space-between;
page-break-inside: avoid;
}
.user-info {
display: flex;
align-items: center;
flex: 1;
}
.user-details {
flex: 1;
}
.user-name {
font-weight: 600;
color: #2d3748;
margin-bottom: 8px;
font-size: 16px;
}
.user-badges {
display: flex;
align-items: center;
gap: 8px;
flex-wrap: wrap;
}
.user-title-badge {
background: #4299e1;
color: #ffffff;
padding: 4px 12px;
border-radius: 12px;
font-size: 12px;
font-weight: 500;
}
.user-mbti {
background: #667eea;
color: #ffffff;
padding: 4px 8px;
border-radius: 8px;
font-weight: 500;
font-size: 12px;
}
.user-reason {
color: #666666;
font-size: 12px;
max-width: 200px;
text-align: right;
line-height: 1.4;
}
.user-avatar {
width: 40px;
height: 40px;
border-radius: 50%;
margin-right: 15px;
border: 2px solid #e2e8f0;
object-fit: cover;
flex-shrink: 0;
}
.user-avatar-placeholder {
width: 40px;
height: 40px;
border-radius: 50%;
background: #f0f0f0;
display: flex;
align-items: center;
justify-content: center;
margin-right: 15px;
font-size: 18px;
color: #666666;
flex-shrink: 0;
}
.quote-item {
background: #faf5ff;
padding: 20px;
margin-bottom: 15px;
border-radius: 8px;
border: 1px solid #e2e8f0;
page-break-inside: avoid;
}
.quote-content {
font-size: 16px;
color: #2d3748;
font-weight: 500;
line-height: 1.6;
margin-bottom: 10px;
font-style: italic;
}
.quote-author {
font-size: 14px;
color: #4299e1;
font-weight: 600;
margin-bottom: 8px;
text-align: right;
}
.quote-reason {
font-size: 12px;
color: #666666;
background: rgba(66, 153, 225, 0.1);
padding: 8px 12px;
border-radius: 6px;
border-left: 3px solid #4299e1;
}
.footer {
background: #f8f9ff;
color: #666666;
text-align: center;
padding: 20px;
font-size: 12px;
border-radius: 8px;
margin-top: 40px;
}
/* PDF活跃度可视化样式 - 集成版本 */
.activity-chart-container {
background: #f8f9ff;
padding: 20px;
border-radius: 8px;
border: 1px solid #e2e8f0;
margin-top: 20px;
page-break-inside: avoid;
}
.chart-header {
margin-bottom: 15px;
padding-bottom: 8px;
border-bottom: 1px solid #e2e8f0;
}
.chart-title {
font-size: 16px;
font-weight: 600;
color: #2d3748;
}
.hour-bar-container {
display: flex;
align-items: center;
margin: 6px 0;
height: 16px;
}
.hour-label {
width: 45px;
text-align: left;
color: #4a5568;
font-size: 11px;
font-weight: 500;
flex-shrink: 0;
}
.bar-wrapper {
display: flex;
align-items: center;
flex-grow: 1;
gap: 8px;
min-width: 0;
}
.bar {
height: 6px;
background-color: #4299e1;
border-radius: 3px;
display: flex;
justify-content: flex-end;
align-items: center;
overflow: hidden;
}
.hourly-value-outside {
color: #4a5568;
font-size: 10px;
font-weight: 600;
flex-shrink: 0;
min-width: 25px;
text-align: right;
}
.hourly-value-inside {
color: white;
font-size: 9px;
padding: 0 4px;
font-weight: 600;
white-space: nowrap;
}
@media print {
body {
font-size: 12px;
}
.container {
padding: 10px;
}
.header {
padding: 20px;
}
.section {
margin-bottom: 30px;
}
.stats-grid {
grid-template-columns: repeat(2, 1fr);
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>📊 群聊日常分析报告</h1>
<div class="date">{{current_date}}</div>
</div>
<div class="section">
<h2 class="section-title">📈 基础统计</h2>
<div class="stats-grid">
<div class="stat-card">
<div class="stat-number">{{message_count}}</div>
<div class="stat-label">消息总数</div>
</div>
<div class="stat-card">
<div class="stat-number">{{participant_count}}</div>
<div class="stat-label">参与人数</div>
</div>
<div class="stat-card">
<div class="stat-number">{{total_characters}}</div>
<div class="stat-label">总字符数</div>
</div>
<div class="stat-card">
<div class="stat-number">{{emoji_count}}</div>
<div class="stat-label">表情数量</div>
</div>
</div>
<div class="active-period">
<div class="time">{{most_active_period}}</div>
<div class="label">最活跃时段</div>
</div>
<!-- 活跃度可视化部分 - 集成到基础统计 -->
<div class="activity-chart-container">
<div class="chart-header">
<div class="chart-title">⏱️ 活跃度分布</div>
</div>
{{hourly_chart_html}}
</div>
</div>
<div class="section">
<h2 class="section-title">💬 热门话题</h2>
{{topics_html}}
</div>
<div class="section">
<h2 class="section-title">🏆 群友称号</h2>
{{titles_html}}
</div>
<div class="section">
<h2 class="section-title">💬 群圣经</h2>
{{quotes_html}}
</div>
<div class="footer">
由 AstrBot QQ群日常分析插件 生成 | {{current_datetime}} | SXP-Simon/astrbot-qq-group-daily-analysis<br>
<small style="opacity: 0.8; font-size: 0.9em;">🤖 AI分析消耗:{{total_tokens}} tokens (输入: {{prompt_tokens}}, 输出:
{{completion_tokens}})</small>
</div>
</div>
</body>
</html>
+7
View File
@@ -0,0 +1,7 @@
{% for quote in quotes %}
<div class="quote-item">
<div class="quote-content">"{{ quote.content }}"</div>
<div class="quote-author">—— {{ quote.sender }}</div>
<div class="quote-reason">{{ quote.reason }}</div>
</div>
{% endfor %}
+10
View File
@@ -0,0 +1,10 @@
{% for topic in topics %}
<div class="topic-item">
<div class="topic-header">
<span class="topic-number">{{ topic.index }}</span>
<span class="topic-title">{{ topic.topic.topic }}</span>
</div>
<div class="topic-contributors">参与者: {{ topic.contributors }}</div>
<div class="topic-detail">{{ topic.topic.detail }}</div>
</div>
{% endfor %}
@@ -0,0 +1,19 @@
{% for title in titles %}
<div class="user-title">
<div class="user-info">
{% if title.avatar_data %}
<img src="{{ title.avatar_data }}" class="user-avatar" alt="头像">
{% else %}
<div class="user-avatar-placeholder">👤</div>
{% endif %}
<div class="user-details">
<div class="user-name">{{ title.name }}</div>
<div class="user-badges">
<div class="user-title-badge">{{ title.title }}</div>
<div class="user-mbti">{{ title.mbti }}</div>
</div>
</div>
</div>
<div class="user-reason">{{ title.reason }}</div>
</div>
{% endfor %}