feat: enhance Mermaid visualizations with multi-series trends, distribution pie, and impact analysis
This commit is contained in:
@@ -269,31 +269,59 @@ class OpenWebUIStats:
|
|||||||
print(f"⚠️ 无法从 Token 解析用户 ID: {e}")
|
print(f"⚠️ 无法从 Token 解析用户 ID: {e}")
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def generate_mermaid_chart(self) -> str:
|
def generate_mermaid_chart(self, stats: dict = None) -> str:
|
||||||
"""生成 Mermaid 增长趋势图"""
|
"""生成多维度的 Mermaid 可视化图表集"""
|
||||||
history = self.load_history()
|
history = self.load_history()
|
||||||
if len(history) < 3: # 数据太少不显示图表
|
charts = []
|
||||||
return ""
|
|
||||||
|
|
||||||
# 只取最近 14 天的数据用于展示
|
# 1. 增长趋势图 (XY Chart)
|
||||||
data = history[-14:]
|
if len(history) >= 3:
|
||||||
dates = [item["date"][-5:] for item in data] # 只取 MM-DD
|
# 只取最近 14 天
|
||||||
dates_str = ", ".join([f'"{d}"' for d in dates])
|
data = history[-14:]
|
||||||
downloads = [str(item["total_downloads"]) for item in data]
|
dates = [item["date"][-5:] for item in data]
|
||||||
downloads_str = ", ".join(downloads)
|
dates_str = ", ".join([f'"{d}"' for d in dates])
|
||||||
|
dls = [str(item["total_downloads"]) for item in data]
|
||||||
|
vws = [str(item["total_views"]) for item in data]
|
||||||
|
|
||||||
mm = []
|
charts.append("### 📈 增长与趋势 (Last 14 Days)")
|
||||||
mm.append("### 📈 增长趋势 (14天)")
|
charts.append("```mermaid")
|
||||||
mm.append("")
|
charts.append("xychart-beta")
|
||||||
mm.append("```mermaid")
|
charts.append(' title "Engagement & Downloads Trend"')
|
||||||
mm.append("xychart-beta")
|
charts.append(f" x-axis [{dates_str}]")
|
||||||
mm.append(f' title "Downloads Trend"')
|
charts.append(f' y-axis "Total Counts"')
|
||||||
mm.append(f" x-axis [{dates_str}]")
|
charts.append(f" line [{', '.join(dls)}]")
|
||||||
mm.append(f' y-axis "Downloads"')
|
charts.append(f" line [{', '.join(vws)}]")
|
||||||
mm.append(f" line [{downloads_str}]")
|
charts.append("```")
|
||||||
mm.append("```")
|
charts.append("\n> *蓝色: 总下载量 | 紫色: 总浏览量*")
|
||||||
mm.append("")
|
charts.append("")
|
||||||
return "\n".join(mm)
|
|
||||||
|
# 2. 插件类型分布 (Pie Chart)
|
||||||
|
if stats and stats.get("by_type"):
|
||||||
|
charts.append("### 📂 内容分类占比 (Distribution)")
|
||||||
|
charts.append("```mermaid")
|
||||||
|
charts.append("pie title Plugin Types")
|
||||||
|
for p_type, count in stats["by_type"].items():
|
||||||
|
charts.append(f' "{p_type}" : {count}')
|
||||||
|
charts.append("```")
|
||||||
|
charts.append("")
|
||||||
|
|
||||||
|
# 3. 影响力分析 (Bar Chart for Top 6)
|
||||||
|
if stats and stats.get("posts"):
|
||||||
|
top6 = stats["posts"][:6]
|
||||||
|
labels = [f'"{p["title"][:15]}..."' for p in top6]
|
||||||
|
values = [str(p["downloads"]) for p in top6]
|
||||||
|
|
||||||
|
charts.append("### 🏆 影响力排行 (Top 6 Downloads)")
|
||||||
|
charts.append("```mermaid")
|
||||||
|
charts.append("xychart-beta")
|
||||||
|
charts.append(' title "Top 6 Plugins Comparison"')
|
||||||
|
charts.append(f" x-axis [{', '.join(labels)}]")
|
||||||
|
charts.append(f' y-axis "Downloads"')
|
||||||
|
charts.append(f" bar [{', '.join(values)}]")
|
||||||
|
charts.append("```")
|
||||||
|
charts.append("")
|
||||||
|
|
||||||
|
return "\n".join(charts)
|
||||||
|
|
||||||
def get_user_posts(self, sort: str = "new", page: int = 1) -> list:
|
def get_user_posts(self, sort: str = "new", page: int = 1) -> list:
|
||||||
"""
|
"""
|
||||||
@@ -514,7 +542,7 @@ class OpenWebUIStats:
|
|||||||
md.append("")
|
md.append("")
|
||||||
|
|
||||||
# 插入趋势图
|
# 插入趋势图
|
||||||
chart = self.generate_mermaid_chart()
|
chart = self.generate_mermaid_chart(stats)
|
||||||
if chart:
|
if chart:
|
||||||
md.append(chart)
|
md.append(chart)
|
||||||
md.append("")
|
md.append("")
|
||||||
|
|||||||
Reference in New Issue
Block a user