import sys, io, json sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8") import os SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) PROJECT_ROOT = os.path.dirname(SCRIPT_DIR) with open(os.path.join(PROJECT_ROOT, "output", "knowledge-graph", "knowledge_graph.json"), "r", encoding="utf-8") as f: graph = json.load(f) # Generate Mermaid diagram mermaid = [] mermaid.append("graph TB") mermaid.append("") # Style definitions mermaid.append(" classDef person fill:#4A90D9,stroke:#2C5F8A,color:#fff,stroke-width:2px") mermaid.append(" classDef topic fill:#E8A838,stroke:#B8842C,color:#fff,stroke-width:2px") mermaid.append(" classDef doc fill:#5CB85C,stroke:#3D8B3D,color:#fff,stroke-width:1px") mermaid.append(" classDef file fill:#D9534F,stroke:#B94441,color:#fff,stroke-width:1px") mermaid.append(" classDef group fill:#9B59B6,stroke:#7D3C98,color:#fff,stroke-width:2px") mermaid.append("") # Groups mermaid.append(" subgraph G1[dc战略问题研究院]") for name in ["li_zj_dc", "huang_jw_dc", "chen_cz_dc", "xia_l_dc", "zhang_jz_dc", "mo_rl_dc", "hu_hj_dc", "wang_j_dc", "fu_my_dc"]: pass # Keep it simpler - just key nodes mermaid.append(" li_zj[李志健]:::person") mermaid.append(" huang_jw[黄静雯]:::person") mermaid.append(" chen_cz[陈楚真]:::person") mermaid.append(" fu_my[傅明游]:::person") mermaid.append(" xia_l[夏莲]:::person") mermaid.append(" zhang_jz[张家振]:::person") mermaid.append(" mo_rl[莫润麟]:::person") mermaid.append(" hu_hj[胡辉俊]:::person") mermaid.append(" wang_j[汪季]:::person") mermaid.append(" end") mermaid.append("") mermaid.append(" subgraph G2[创新组]") mermaid.append(" wang_ym[王雨默]:::person") mermaid.append(" wei_y[韦译]:::person") mermaid.append(" liu_p[刘鹏]:::person") mermaid.append(" zhuo_z[卓泽]:::person") mermaid.append(" xu_r[徐锐]:::person") mermaid.append(" end") mermaid.append("") # Key cross-group people mermaid.append(" subgraph G3[跨组人员]") mermaid.append(" shangguan_c[上官成]:::person") mermaid.append(" an_d[安东]:::person") mermaid.append(" lin_f[林峰]:::person") mermaid.append(" end") mermaid.append("") # Topics mermaid.append(" subgraph T[核心研究主题]") mermaid.append(" t1[花园世界深度研究]:::topic") mermaid.append(" t2[云湖项目选择]:::topic") mermaid.append(" t3[Game Analyst Agent]:::topic") mermaid.append(" t4[战略思维方法论]:::topic") mermaid.append(" t5[AI落地与组织变革]:::topic") mermaid.append(" t6[创新组研发]:::topic") mermaid.append(" t7[战略组知识产出]:::topic") mermaid.append(" end") mermaid.append("") # Key files mermaid.append(" subgraph F[关键文件]") mermaid.append(" f1[主报告-我的花园世界.html]:::file") mermaid.append(" f2[美国版策略报告.html]:::file") mermaid.append(" f3[云湖项目选择.html]:::file") mermaid.append(" f4[game-analyst-agent.html]:::file") mermaid.append(" f5[取败之道.md]:::file") mermaid.append(" f6[策划启示.md]:::file") mermaid.append(" f7[进一步的思考.md]:::file") mermaid.append(" f8[GOS补充信息.md]:::file") mermaid.append(" end") mermaid.append("") # Relationships mermaid.append(" %% Person -> Topic") mermaid.append(" li_zj --> t1") mermaid.append(" li_zj --> t4") mermaid.append(" li_zj --> t5") mermaid.append(" huang_jw --> t1") mermaid.append(" huang_jw --> t2") mermaid.append(" huang_jw --> t3") mermaid.append(" huang_jw --> t7") mermaid.append(" chen_cz --> t1") mermaid.append(" chen_cz --> t7") mermaid.append(" fu_my --> t1") mermaid.append(" wang_ym --> t6") mermaid.append(" wei_y --> t6") mermaid.append(" liu_p --> t6") mermaid.append(" shangguan_c --> t5") mermaid.append(" lin_f --> t5") mermaid.append("") mermaid.append(" %% Topic -> Files") mermaid.append(" t1 --> f1") mermaid.append(" t1 --> f2") mermaid.append(" t1 --> f6") mermaid.append(" t1 --> f7") mermaid.append(" t1 --> f8") mermaid.append(" t2 --> f3") mermaid.append(" t3 --> f4") mermaid.append(" t4 --> f5") mermaid.append("") mermaid.append(" %% Daily report flow (研究组)") mermaid.append(" xia_l -.->|daily report| t7") mermaid.append(" zhang_jz -.->|daily report| t7") mermaid.append(" mo_rl -.->|daily report| t7") mermaid.append(" hu_hj -.->|daily report| t7") mermaid.append(" wang_j -.->|daily report| t7") mermaid.append("") mermaid.append(" %% Cross-group") mermaid.append(" huang_jw -.->|跨组| t6") mermaid.append(" li_zj -.->|指导| t6") mermaid.append(" li_zj -.->|指导| t7") mermaid_text = "\n".join(mermaid) # Save mermaid with open(os.path.join(PROJECT_ROOT, "output", "knowledge-graph", "knowledge_graph_mermaid.md"), "w", encoding="utf-8") as f: f.write("# 知识图谱 - dc战略问题研究院 & 创新组\n\n") f.write("```mermaid\n") f.write(mermaid_text) f.write("\n```\n") # Generate comprehensive HTML report html = [] html.append(""" 知识图谱 - dc战略问题研究院 & 创新组

知识图谱

dc战略问题研究院 & 创新组 | 2026-05-01 ~ 2026-06-02

28
活跃人员
190
飞书文档链接
18
文件附件
7
核心主题
377
总消息数
""") # Persons section html.append("

人员图谱

") html.append('
') for name, p in sorted(graph["persons"].items(), key=lambda x: -x[1]["contributions"]): initial = name[0] groups = ", ".join(p["groups"]) html.append(f'
{initial}
{name}
{p["contributions"]}条消息 | {groups}
') html.append("
") # Topics section html.append("

核心研究主题

") for t in graph["topics"]: html.append(f'
') html.append(f'

{t["name"]}

') html.append(f'

{t["description"]}

') html.append(f'

关键人物: {", ".join(t["key_people"])}

') html.append(f'
') for c in t["key_concepts"]: html.append(f'{c}') html.append(f'
') if t["files"]: html.append(f'

关联文件:

') html.append(f'
') # Documents by domain html.append("

文档分布

") html.append('
') domain_counts = {} for doc in graph["documents"]: d = doc["domain"] domain_counts[d] = domain_counts.get(d, 0) + 1 max_count = max(domain_counts.values()) if domain_counts else 1 for d, c in sorted(domain_counts.items(), key=lambda x: -x[1]): width = int(c / max_count * 200) html.append(f'
{d}
{c}
') html.append('
') # Files section html.append("

全部文件附件

") html.append('
') html.append('') for f in graph["files"]: html.append(f'') html.append('
文件名分享者群组时间
{f["name"]}{f["sender"]}{f["group"]}{f["time"]}
') # Key concepts html.append("

关键概念索引

") all_concepts = {} for t in graph["topics"]: for c in t["key_concepts"]: if c not in all_concepts: all_concepts[c] = [] all_concepts[c].append(t["name"]) for concept, topics in sorted(all_concepts.items()): html.append(f'
') html.append(f'{concept} -> {", ".join(topics)}') html.append(f'
') html.append("
") with open(os.path.join(PROJECT_ROOT, "output", "knowledge-graph", "knowledge_graph.html"), "w", encoding="utf-8") as f: f.write("\n".join(html)) print("Generated knowledge_graph.html and knowledge_graph_mermaid.md")