visualize_inspiration_points_backup.py 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358
  1. """
  2. 灵感点分析结果可视化脚本
  3. 读取 how/灵感点 目录下的分析结果,结合作者历史帖子详情,生成可视化HTML页面
  4. """
  5. import json
  6. from pathlib import Path
  7. from typing import Dict, Any, List, Optional
  8. from datetime import datetime
  9. import html as html_module
  10. def load_inspiration_points_data(inspiration_dir: str) -> List[Dict[str, Any]]:
  11. """
  12. 加载所有灵感点的分析结果
  13. Args:
  14. inspiration_dir: 灵感点目录路径
  15. Returns:
  16. 灵感点分析结果列表
  17. """
  18. inspiration_path = Path(inspiration_dir)
  19. results = []
  20. # 遍历所有子目录
  21. for subdir in inspiration_path.iterdir():
  22. if subdir.is_dir():
  23. # 查找 all_summary 文件
  24. summary_files = list(subdir.glob("all_summary_*.json"))
  25. if summary_files:
  26. summary_file = summary_files[0]
  27. try:
  28. with open(summary_file, 'r', encoding='utf-8') as f:
  29. data = json.load(f)
  30. # 加载完整的 step1 和 step2 数据
  31. step1_data = None
  32. step2_data = None
  33. if "文件路径" in data:
  34. step1_path = data["文件路径"].get("step1")
  35. step2_path = data["文件路径"].get("step2")
  36. if step1_path:
  37. step1_full_path = Path(step1_path)
  38. if not step1_full_path.is_absolute():
  39. step1_full_path = inspiration_path.parent.parent.parent.parent / step1_path
  40. if step1_full_path.exists():
  41. with open(step1_full_path, 'r', encoding='utf-8') as f:
  42. step1_data = json.load(f)
  43. if step2_path:
  44. step2_full_path = Path(step2_path)
  45. if not step2_full_path.is_absolute():
  46. step2_full_path = inspiration_path.parent.parent.parent.parent / step2_path
  47. if step2_full_path.exists():
  48. with open(step2_full_path, 'r', encoding='utf-8') as f:
  49. step2_data = json.load(f)
  50. results.append({
  51. "summary": data,
  52. "step1": step1_data,
  53. "step2": step2_data,
  54. "inspiration_name": subdir.name
  55. })
  56. except Exception as e:
  57. print(f"警告: 读取 {summary_file} 失败: {e}")
  58. return results
  59. def load_posts_data(posts_dir: str) -> Dict[str, Dict[str, Any]]:
  60. """
  61. 加载所有帖子详情数据
  62. Args:
  63. posts_dir: 帖子目录路径
  64. Returns:
  65. 帖子ID到帖子详情的映射
  66. """
  67. posts_path = Path(posts_dir)
  68. posts_map = {}
  69. for post_file in posts_path.glob("*.json"):
  70. try:
  71. with open(post_file, 'r', encoding='utf-8') as f:
  72. post_data = json.load(f)
  73. post_id = post_data.get("channel_content_id")
  74. if post_id:
  75. posts_map[post_id] = post_data
  76. except Exception as e:
  77. print(f"警告: 读取 {post_file} 失败: {e}")
  78. return posts_map
  79. def generate_inspiration_card_html(inspiration_data: Dict[str, Any]) -> str:
  80. """
  81. 生成单个灵感点的卡片HTML
  82. Args:
  83. inspiration_data: 灵感点数据
  84. Returns:
  85. HTML字符串
  86. """
  87. summary = inspiration_data.get("summary", {})
  88. step1 = inspiration_data.get("step1", {})
  89. step2 = inspiration_data.get("step2", {})
  90. inspiration_name = inspiration_data.get("inspiration_name", "未知灵感")
  91. # 提取关键指标
  92. metrics = summary.get("关键指标", {})
  93. step1_score = metrics.get("step1_top1_score", 0)
  94. step2_score = metrics.get("step2_score", 0)
  95. step1_match_element = metrics.get("step1_top1_匹配要素", "")
  96. step2_increment_count = metrics.get("step2_增量词数量", 0)
  97. # 确定卡片颜色(基于Step1分数)
  98. if step1_score >= 0.7:
  99. border_color = "#10b981"
  100. step1_color = "#10b981"
  101. elif step1_score >= 0.5:
  102. border_color = "#f59e0b"
  103. step1_color = "#f59e0b"
  104. elif step1_score >= 0.3:
  105. border_color = "#3b82f6"
  106. step1_color = "#3b82f6"
  107. else:
  108. border_color = "#ef4444"
  109. step1_color = "#ef4444"
  110. # Step2颜色
  111. if step2_score >= 0.7:
  112. step2_color = "#10b981"
  113. elif step2_score >= 0.5:
  114. step2_color = "#f59e0b"
  115. elif step2_score >= 0.3:
  116. step2_color = "#3b82f6"
  117. else:
  118. step2_color = "#ef4444"
  119. # 转义HTML
  120. inspiration_name_escaped = html_module.escape(inspiration_name)
  121. step1_match_element_escaped = html_module.escape(step1_match_element)
  122. # 获取Step1匹配结果(简要展示)
  123. step1_matches = step1.get("匹配结果", []) if step1 else []
  124. step1_match_preview = ""
  125. if step1_matches:
  126. top_match = step1_matches[0]
  127. element_name = top_match.get("要素", {}).get("名称", "")
  128. match_score = top_match.get("分数", 0)
  129. step1_match_preview = f'''
  130. <div class="match-preview">
  131. <div class="match-preview-header">🎯 Step1 Top1匹配</div>
  132. <div class="match-preview-content">
  133. <span class="match-preview-name">{html_module.escape(element_name)}</span>
  134. <span class="match-preview-score" style="color: {step1_color};">{match_score:.2f}</span>
  135. </div>
  136. </div>
  137. '''
  138. # 获取Step2匹配结果(简要展示)
  139. step2_matches = step2.get("匹配结果", []) if step2 else []
  140. step2_match_preview = ""
  141. if step2_matches:
  142. top_match = step2_matches[0]
  143. words = top_match.get("增量词", [])
  144. match_score = top_match.get("分数", 0)
  145. step2_match_preview = f'''
  146. <div class="match-preview">
  147. <div class="match-preview-header">➕ Step2 Top1增量词</div>
  148. <div class="match-preview-content">
  149. <span class="match-preview-name">{html_module.escape(", ".join(words))}</span>
  150. <span class="match-preview-score" style="color: {step2_color};">{match_score:.2f}</span>
  151. </div>
  152. </div>
  153. '''
  154. # 准备详细数据用于弹窗
  155. detail_data_json = json.dumps(inspiration_data, ensure_ascii=False)
  156. detail_data_json_escaped = html_module.escape(detail_data_json)
  157. html = f'''
  158. <div class="inspiration-card" style="border-left-color: {border_color};"
  159. data-inspiration-name="{inspiration_name_escaped}"
  160. data-detail="{detail_data_json_escaped}"
  161. data-step1-score="{step1_score}"
  162. data-step2-score="{step2_score}"
  163. onclick="showInspirationDetail(this)">
  164. <div class="card-header">
  165. <h3 class="inspiration-name">{inspiration_name_escaped}</h3>
  166. </div>
  167. <div class="score-section">
  168. <div class="score-item">
  169. <div class="score-label">Step1分数</div>
  170. <div class="score-value" style="color: {step1_color};">{step1_score:.3f}</div>
  171. </div>
  172. <div class="score-divider"></div>
  173. <div class="score-item">
  174. <div class="score-label">Step2分数</div>
  175. <div class="score-value" style="color: {step2_color};">{step2_score:.3f}</div>
  176. </div>
  177. </div>
  178. {step1_match_preview}
  179. {step2_match_preview}
  180. <div class="metrics-section">
  181. <div class="metric-item">
  182. <span class="metric-icon">📊</span>
  183. <span class="metric-label">增量词数:</span>
  184. <span class="metric-value">{step2_increment_count}</span>
  185. </div>
  186. </div>
  187. <div class="click-hint">点击查看详情 →</div>
  188. </div>
  189. '''
  190. return html
  191. def generate_detail_modal_content_js() -> str:
  192. """
  193. 生成详情弹窗内容的JavaScript函数
  194. Returns:
  195. JavaScript代码字符串
  196. """
  197. return '''
  198. function showInspirationDetail(element) {
  199. const inspirationName = element.dataset.inspirationName;
  200. const detailStr = element.dataset.detail;
  201. let detail;
  202. try {
  203. detail = JSON.parse(detailStr);
  204. } catch(e) {
  205. console.error('解析数据失败:', e);
  206. return;
  207. }
  208. const modal = document.getElementById('detailModal');
  209. const modalBody = document.getElementById('modalBody');
  210. const summary = detail.summary || {};
  211. const step1 = detail.step1 || {};
  212. const step2 = detail.step2 || {};
  213. const metrics = summary.关键指标 || {};
  214. // 构建Modal内容
  215. let content = `
  216. <div class="modal-header">
  217. <h2 class="modal-title">${inspirationName}</h2>
  218. </div>
  219. `;
  220. // 元数据信息
  221. const metadata = summary.元数据 || {};
  222. if (metadata.current_time || metadata.流程) {
  223. content += `
  224. <div class="modal-section">
  225. <h3>📋 分析信息</h3>
  226. <div class="info-grid">
  227. ${metadata.current_time ? `<div class="info-item"><span class="info-label">分析时间:</span> <span class="info-value">${metadata.current_time}</span></div>` : ''}
  228. ${metadata.流程 ? `<div class="info-item"><span class="info-label">分析流程:</span> <span class="info-value">${metadata.流程}</span></div>` : ''}
  229. ${metadata.step1_model ? `<div class="info-item"><span class="info-label">Step1模型:</span> <span class="info-value">${metadata.step1_model}</span></div>` : ''}
  230. ${metadata.step2_model ? `<div class="info-item"><span class="info-label">Step2模型:</span> <span class="info-value">${metadata.step2_model}</span></div>` : ''}
  231. </div>
  232. </div>
  233. `;
  234. }
  235. // 关键指标
  236. content += `
  237. <div class="modal-section">
  238. <h3>📊 关键指标</h3>
  239. <div class="metrics-grid">
  240. <div class="metric-box">
  241. <div class="metric-box-label">Step1得分</div>
  242. <div class="metric-box-value">${metrics.step1_top1_score || 0}</div>
  243. </div>
  244. <div class="metric-box">
  245. <div class="metric-box-label">Step2得分</div>
  246. <div class="metric-box-value">${metrics.step2_score || 0}</div>
  247. </div>
  248. <div class="metric-box">
  249. <div class="metric-box-label">增量词数量</div>
  250. <div class="metric-box-value">${metrics.step2_增量词数量 || 0}</div>
  251. </div>
  252. <div class="metric-box wide">
  253. <div class="metric-box-label">匹配要素</div>
  254. <div class="metric-box-value small">${metrics.step1_top1_匹配要素 || '无'}</div>
  255. </div>
  256. </div>
  257. </div>
  258. `;
  259. // Step1 详细信息
  260. if (step1 && step1.灵感) {
  261. const inspiration = step1.灵感 || '';
  262. const persona = step1.人设 || {};
  263. const matches = step1.匹配结果 || [];
  264. content += `
  265. <div class="modal-section">
  266. <h3>🎯 Step1: 灵感人设匹配</h3>
  267. <div class="step-content">
  268. <div class="step-field">
  269. <span class="step-field-label">灵感内容:</span>
  270. <span class="step-field-value">${inspiration}</span>
  271. </div>
  272. `;
  273. // 显示匹配结果(Top3)
  274. if (matches.length > 0) {
  275. content += `
  276. <div class="step-field">
  277. <span class="step-field-label">匹配结果 (Top ${Math.min(3, matches.length)}):</span>
  278. <div class="matches-list">
  279. `;
  280. matches.slice(0, 3).forEach((match, index) => {
  281. const element = match.要素 || {};
  282. const score = match.分数 || 0;
  283. const reason = match.原因 || '';
  284. const colorClass = index === 0 ? 'top1' : (index === 1 ? 'top2' : 'top3');
  285. content += `
  286. <div class="match-item ${colorClass}">
  287. <div class="match-header">
  288. <span class="match-rank">#${index + 1}</span>
  289. <span class="match-element-name">${element.名称 || '未知要素'}</span>
  290. <span class="match-score">${score.toFixed(2)}</span>
  291. </div>
  292. ${element.定义 ? `<div class="match-detail"><strong>定义:</strong> ${element.定义}</div>` : ''}
  293. <div class="match-reason">${reason}</div>
  294. </div>
  295. `;
  296. });
  297. content += `
  298. </div>
  299. </div>
  300. `;
  301. }
  302. content += `
  303. </div>
  304. </div>
  305. `;
  306. }
  307. // Step2 详细信息
  308. if (step2 && step2.灵感) {
  309. const step2Matches = step2.匹配结果 || [];
  310. content += `
  311. <div class="modal-section">
  312. <h3>➕ Step2: 增量词匹配</h3>
  313. <div class="step-content">
  314. `;
  315. if (step2Matches.length > 0) {
  316. content += `
  317. <div class="step-field">
  318. <span class="step-field-label">增量词匹配结果:</span>
  319. <div class="increment-matches">
  320. `;
  321. step2Matches.forEach((match, index) => {
  322. const words = match.增量词 || [];
  323. const score = match.分数 || 0;
  324. const reason = match.原因 || '';
  325. content += `
  326. <div class="increment-item">
  327. <div class="increment-header">
  328. <span class="increment-words">${words.join(', ')}</span>
  329. <span class="increment-score">${score.toFixed(2)}</span>
  330. </div>
  331. <div class="increment-reason">${reason}</div>
  332. </div>
  333. `;
  334. });
  335. content += `
  336. </div>
  337. </div>
  338. `;
  339. } else {
  340. content += `
  341. <div class="empty-state">暂无增量词匹配结果</div>
  342. `;
  343. }
  344. content += `
  345. </div>
  346. </div>
  347. `;
  348. }
  349. // 日志链接
  350. if (metadata.log_url) {
  351. content += `
  352. <div class="modal-link">
  353. <a href="${metadata.log_url}" target="_blank" class="modal-link-btn">
  354. 🔗 查看详细日志
  355. </a>
  356. </div>
  357. `;
  358. }
  359. modalBody.innerHTML = content;
  360. modal.classList.add('active');
  361. document.body.style.overflow = 'hidden';
  362. }
  363. function closeModal() {
  364. const modal = document.getElementById('detailModal');
  365. modal.classList.remove('active');
  366. document.body.style.overflow = '';
  367. }
  368. function closeModalOnOverlay(event) {
  369. if (event.target.id === 'detailModal') {
  370. closeModal();
  371. }
  372. }
  373. // ESC键关闭Modal
  374. document.addEventListener('keydown', function(event) {
  375. if (event.key === 'Escape') {
  376. closeModal();
  377. }
  378. });
  379. // 搜索和过滤功能
  380. function filterInspirations() {
  381. const searchInput = document.getElementById('searchInput').value.toLowerCase();
  382. const sortSelect = document.getElementById('sortSelect').value;
  383. const cards = document.querySelectorAll('.inspiration-card');
  384. let visibleCards = Array.from(cards);
  385. // 搜索过滤
  386. visibleCards.forEach(card => {
  387. const name = card.dataset.inspirationName.toLowerCase();
  388. if (name.includes(searchInput)) {
  389. card.style.display = '';
  390. } else {
  391. card.style.display = 'none';
  392. }
  393. });
  394. // 获取可见的卡片
  395. visibleCards = Array.from(cards).filter(card => card.style.display !== 'none');
  396. // 排序
  397. if (sortSelect === 'score-desc' || sortSelect === 'score-asc') {
  398. visibleCards.sort((a, b) => {
  399. const detailA = JSON.parse(a.dataset.detail);
  400. const detailB = JSON.parse(b.dataset.detail);
  401. const scoreA = ((detailA.summary.关键指标.step1_top1_score || 0) + (detailA.summary.关键指标.step2_score || 0)) / 2;
  402. const scoreB = ((detailB.summary.关键指标.step1_top1_score || 0) + (detailB.summary.关键指标.step2_score || 0)) / 2;
  403. return sortSelect === 'score-desc' ? scoreB - scoreA : scoreA - scoreB;
  404. });
  405. } else if (sortSelect === 'name-asc' || sortSelect === 'name-desc') {
  406. visibleCards.sort((a, b) => {
  407. const nameA = a.dataset.inspirationName;
  408. const nameB = b.dataset.inspirationName;
  409. return sortSelect === 'name-asc' ? nameA.localeCompare(nameB) : nameB.localeCompare(nameA);
  410. });
  411. }
  412. // 重新排列卡片
  413. const container = document.querySelector('.inspirations-grid');
  414. visibleCards.forEach(card => {
  415. container.appendChild(card);
  416. });
  417. // 更新统计
  418. updateStats();
  419. }
  420. function updateStats() {
  421. const cards = document.querySelectorAll('.inspiration-card');
  422. const visibleCards = Array.from(cards).filter(card => card.style.display !== 'none');
  423. document.getElementById('totalCount').textContent = visibleCards.length;
  424. let excellentCount = 0;
  425. let goodCount = 0;
  426. let normalCount = 0;
  427. let needOptCount = 0;
  428. let totalScore = 0;
  429. visibleCards.forEach(card => {
  430. const detail = JSON.parse(card.dataset.detail);
  431. const metrics = detail.summary.关键指标;
  432. const score = ((metrics.step1_top1_score || 0) + (metrics.step2_score || 0)) / 2 * 100;
  433. totalScore += score;
  434. if (score >= 70) excellentCount++;
  435. else if (score >= 50) goodCount++;
  436. else if (score >= 30) normalCount++;
  437. else needOptCount++;
  438. });
  439. document.getElementById('excellentCount').textContent = excellentCount;
  440. document.getElementById('goodCount').textContent = goodCount;
  441. document.getElementById('normalCount').textContent = normalCount;
  442. document.getElementById('needOptCount').textContent = needOptCount;
  443. const avgScore = visibleCards.length > 0 ? (totalScore / visibleCards.length).toFixed(1) : 0;
  444. document.getElementById('avgScore').textContent = avgScore;
  445. }
  446. '''
  447. def generate_html(
  448. inspirations_data: List[Dict[str, Any]],
  449. posts_map: Dict[str, Dict[str, Any]],
  450. output_path: str
  451. ) -> str:
  452. """
  453. 生成完整的可视化HTML
  454. Args:
  455. inspirations_data: 灵感点数据列表
  456. posts_map: 帖子数据映射
  457. output_path: 输出文件路径
  458. Returns:
  459. 输出文件路径
  460. """
  461. timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
  462. # 统计信息
  463. total_count = len(inspirations_data)
  464. excellent_count = sum(1 for d in inspirations_data
  465. if ((d["summary"].get("关键指标", {}).get("step1_top1_score", 0) +
  466. d["summary"].get("关键指标", {}).get("step2_score", 0)) / 2 * 100) >= 70)
  467. good_count = sum(1 for d in inspirations_data
  468. if 50 <= ((d["summary"].get("关键指标", {}).get("step1_top1_score", 0) +
  469. d["summary"].get("关键指标", {}).get("step2_score", 0)) / 2 * 100) < 70)
  470. normal_count = sum(1 for d in inspirations_data
  471. if 30 <= ((d["summary"].get("关键指标", {}).get("step1_top1_score", 0) +
  472. d["summary"].get("关键指标", {}).get("step2_score", 0)) / 2 * 100) < 50)
  473. need_opt_count = sum(1 for d in inspirations_data
  474. if ((d["summary"].get("关键指标", {}).get("step1_top1_score", 0) +
  475. d["summary"].get("关键指标", {}).get("step2_score", 0)) / 2 * 100) < 30)
  476. total_score = sum((d["summary"].get("关键指标", {}).get("step1_top1_score", 0) +
  477. d["summary"].get("关键指标", {}).get("step2_score", 0)) / 2 * 100
  478. for d in inspirations_data)
  479. avg_score = total_score / total_count if total_count > 0 else 0
  480. # 按综合分数排序
  481. inspirations_data_sorted = sorted(
  482. inspirations_data,
  483. key=lambda x: (x["summary"].get("关键指标", {}).get("step1_top1_score", 0) +
  484. x["summary"].get("关键指标", {}).get("step2_score", 0)) / 2,
  485. reverse=True
  486. )
  487. # 生成卡片HTML
  488. cards_html = [generate_inspiration_card_html(data) for data in inspirations_data_sorted]
  489. cards_html_str = '\n'.join(cards_html)
  490. # 生成JavaScript
  491. detail_modal_js = generate_detail_modal_content_js()
  492. # 完整HTML
  493. html_content = f'''<!DOCTYPE html>
  494. <html lang="zh-CN">
  495. <head>
  496. <meta charset="UTF-8">
  497. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  498. <title>灵感点分析可视化</title>
  499. <style>
  500. * {{
  501. margin: 0;
  502. padding: 0;
  503. box-sizing: border-box;
  504. }}
  505. body {{
  506. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  507. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  508. color: #333;
  509. line-height: 1.6;
  510. min-height: 100vh;
  511. padding: 20px;
  512. }}
  513. .container {{
  514. max-width: 1600px;
  515. margin: 0 auto;
  516. }}
  517. .header {{
  518. background: white;
  519. padding: 40px;
  520. border-radius: 16px;
  521. margin-bottom: 30px;
  522. box-shadow: 0 10px 40px rgba(0,0,0,0.2);
  523. }}
  524. .header h1 {{
  525. font-size: 42px;
  526. margin-bottom: 10px;
  527. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  528. -webkit-background-clip: text;
  529. -webkit-text-fill-color: transparent;
  530. font-weight: 800;
  531. }}
  532. .header-subtitle {{
  533. font-size: 16px;
  534. color: #6b7280;
  535. margin-bottom: 30px;
  536. }}
  537. .stats-overview {{
  538. display: grid;
  539. grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  540. gap: 20px;
  541. margin-top: 25px;
  542. }}
  543. .stat-box {{
  544. background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  545. padding: 20px;
  546. border-radius: 12px;
  547. text-align: center;
  548. transition: transform 0.3s ease;
  549. }}
  550. .stat-box:hover {{
  551. transform: translateY(-5px);
  552. }}
  553. .stat-label {{
  554. font-size: 13px;
  555. color: #6b7280;
  556. margin-bottom: 8px;
  557. font-weight: 600;
  558. }}
  559. .stat-value {{
  560. font-size: 32px;
  561. font-weight: 700;
  562. color: #1a1a1a;
  563. }}
  564. .stat-box.excellent .stat-value {{
  565. color: #10b981;
  566. }}
  567. .stat-box.good .stat-value {{
  568. color: #f59e0b;
  569. }}
  570. .stat-box.normal .stat-value {{
  571. color: #3b82f6;
  572. }}
  573. .stat-box.need-opt .stat-value {{
  574. color: #ef4444;
  575. }}
  576. .controls-section {{
  577. background: white;
  578. padding: 25px;
  579. border-radius: 16px;
  580. margin-bottom: 30px;
  581. box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  582. display: flex;
  583. gap: 20px;
  584. flex-wrap: wrap;
  585. align-items: center;
  586. }}
  587. .search-box {{
  588. flex: 1;
  589. min-width: 250px;
  590. }}
  591. .search-input {{
  592. width: 100%;
  593. padding: 12px 20px;
  594. border: 2px solid #e5e7eb;
  595. border-radius: 10px;
  596. font-size: 15px;
  597. transition: all 0.3s;
  598. }}
  599. .search-input:focus {{
  600. outline: none;
  601. border-color: #667eea;
  602. box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
  603. }}
  604. .sort-box {{
  605. display: flex;
  606. align-items: center;
  607. gap: 12px;
  608. }}
  609. .sort-label {{
  610. font-size: 14px;
  611. font-weight: 600;
  612. color: #374151;
  613. }}
  614. .sort-select {{
  615. padding: 10px 16px;
  616. border: 2px solid #e5e7eb;
  617. border-radius: 10px;
  618. font-size: 14px;
  619. background: white;
  620. cursor: pointer;
  621. transition: all 0.3s;
  622. }}
  623. .sort-select:focus {{
  624. outline: none;
  625. border-color: #667eea;
  626. }}
  627. .inspirations-section {{
  628. background: white;
  629. padding: 30px;
  630. border-radius: 16px;
  631. box-shadow: 0 10px 40px rgba(0,0,0,0.15);
  632. }}
  633. .inspirations-grid {{
  634. display: grid;
  635. grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  636. gap: 25px;
  637. }}
  638. .inspiration-card {{
  639. background: white;
  640. border-radius: 14px;
  641. padding: 25px;
  642. border-left: 6px solid #10b981;
  643. cursor: pointer;
  644. transition: all 0.3s ease;
  645. box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  646. position: relative;
  647. }}
  648. .inspiration-card:hover {{
  649. transform: translateY(-8px);
  650. box-shadow: 0 12px 30px rgba(102, 126, 234, 0.2);
  651. }}
  652. .card-header {{
  653. display: flex;
  654. justify-content: space-between;
  655. align-items: flex-start;
  656. margin-bottom: 20px;
  657. gap: 12px;
  658. }}
  659. .inspiration-name {{
  660. font-size: 19px;
  661. font-weight: 700;
  662. color: #1a1a1a;
  663. line-height: 1.4;
  664. flex: 1;
  665. }}
  666. .grade-badge {{
  667. background: #10b981;
  668. color: white;
  669. padding: 6px 14px;
  670. border-radius: 20px;
  671. font-size: 12px;
  672. font-weight: 700;
  673. white-space: nowrap;
  674. }}
  675. .score-section {{
  676. display: flex;
  677. align-items: center;
  678. gap: 25px;
  679. margin-bottom: 20px;
  680. padding: 20px;
  681. background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  682. border-radius: 12px;
  683. }}
  684. .main-score {{
  685. display: flex;
  686. flex-direction: column;
  687. align-items: center;
  688. gap: 8px;
  689. }}
  690. .score-circle {{
  691. width: 90px;
  692. height: 90px;
  693. border-radius: 50%;
  694. border: 6px solid #10b981;
  695. display: flex;
  696. align-items: center;
  697. justify-content: center;
  698. background: white;
  699. }}
  700. .score-value {{
  701. font-size: 26px;
  702. font-weight: 800;
  703. color: #10b981;
  704. }}
  705. .score-label {{
  706. font-size: 12px;
  707. color: #6b7280;
  708. font-weight: 600;
  709. }}
  710. .sub-scores {{
  711. flex: 1;
  712. display: flex;
  713. flex-direction: column;
  714. gap: 12px;
  715. }}
  716. .sub-score-item {{
  717. display: flex;
  718. justify-content: space-between;
  719. align-items: center;
  720. padding: 10px 15px;
  721. background: white;
  722. border-radius: 8px;
  723. }}
  724. .sub-score-label {{
  725. font-size: 13px;
  726. color: #6b7280;
  727. font-weight: 600;
  728. }}
  729. .sub-score-value {{
  730. font-size: 18px;
  731. font-weight: 700;
  732. color: #2563eb;
  733. }}
  734. .metrics-section {{
  735. display: flex;
  736. flex-direction: column;
  737. gap: 10px;
  738. margin-bottom: 15px;
  739. }}
  740. .metric-item {{
  741. display: flex;
  742. align-items: center;
  743. gap: 8px;
  744. font-size: 13px;
  745. color: #4b5563;
  746. }}
  747. .metric-icon {{
  748. font-size: 16px;
  749. }}
  750. .metric-label {{
  751. font-weight: 600;
  752. }}
  753. .metric-value {{
  754. color: #1f2937;
  755. }}
  756. .click-hint {{
  757. position: absolute;
  758. bottom: 15px;
  759. right: 15px;
  760. font-size: 12px;
  761. color: #8b5cf6;
  762. font-weight: 700;
  763. opacity: 0;
  764. transition: opacity 0.3s ease;
  765. background: rgba(139, 92, 246, 0.1);
  766. padding: 6px 12px;
  767. border-radius: 8px;
  768. }}
  769. .inspiration-card:hover .click-hint {{
  770. opacity: 1;
  771. }}
  772. /* Modal样式 */
  773. .modal-overlay {{
  774. display: none;
  775. position: fixed;
  776. top: 0;
  777. left: 0;
  778. right: 0;
  779. bottom: 0;
  780. background: rgba(0, 0, 0, 0.8);
  781. z-index: 1000;
  782. align-items: center;
  783. justify-content: center;
  784. padding: 20px;
  785. overflow-y: auto;
  786. }}
  787. .modal-overlay.active {{
  788. display: flex;
  789. }}
  790. .modal-content {{
  791. background: white;
  792. border-radius: 16px;
  793. max-width: 1200px;
  794. width: 100%;
  795. max-height: 90vh;
  796. overflow-y: auto;
  797. position: relative;
  798. }}
  799. .modal-close {{
  800. position: sticky;
  801. top: 0;
  802. right: 0;
  803. background: white;
  804. border: none;
  805. font-size: 32px;
  806. color: #6b7280;
  807. cursor: pointer;
  808. padding: 15px 20px;
  809. z-index: 10;
  810. text-align: right;
  811. border-bottom: 1px solid #e5e7eb;
  812. }}
  813. .modal-close:hover {{
  814. color: #1f2937;
  815. }}
  816. .modal-body {{
  817. padding: 30px;
  818. }}
  819. .modal-header {{
  820. margin-bottom: 25px;
  821. padding-bottom: 20px;
  822. border-bottom: 2px solid #e5e7eb;
  823. }}
  824. .modal-title {{
  825. font-size: 28px;
  826. font-weight: 800;
  827. color: #1a1a1a;
  828. }}
  829. .modal-section {{
  830. margin-bottom: 30px;
  831. }}
  832. .modal-section h3 {{
  833. font-size: 20px;
  834. font-weight: 700;
  835. color: #374151;
  836. margin-bottom: 15px;
  837. padding-bottom: 10px;
  838. border-bottom: 2px solid #f3f4f6;
  839. }}
  840. .info-grid {{
  841. display: grid;
  842. grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  843. gap: 15px;
  844. }}
  845. .info-item {{
  846. background: #f9fafb;
  847. padding: 12px 16px;
  848. border-radius: 8px;
  849. border-left: 3px solid #8b5cf6;
  850. }}
  851. .info-label {{
  852. font-weight: 600;
  853. color: #6b7280;
  854. font-size: 13px;
  855. margin-right: 8px;
  856. }}
  857. .info-value {{
  858. color: #1f2937;
  859. font-size: 14px;
  860. }}
  861. .metrics-grid {{
  862. display: grid;
  863. grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  864. gap: 15px;
  865. }}
  866. .metric-box {{
  867. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  868. padding: 20px;
  869. border-radius: 12px;
  870. text-align: center;
  871. color: white;
  872. }}
  873. .metric-box.wide {{
  874. grid-column: span 2;
  875. }}
  876. .metric-box-label {{
  877. font-size: 13px;
  878. opacity: 0.9;
  879. margin-bottom: 8px;
  880. font-weight: 600;
  881. }}
  882. .metric-box-value {{
  883. font-size: 28px;
  884. font-weight: 700;
  885. }}
  886. .metric-box-value.small {{
  887. font-size: 16px;
  888. }}
  889. .step-content {{
  890. background: #f9fafb;
  891. padding: 20px;
  892. border-radius: 12px;
  893. }}
  894. .step-field {{
  895. margin-bottom: 20px;
  896. }}
  897. .step-field-label {{
  898. font-weight: 700;
  899. color: #374151;
  900. font-size: 14px;
  901. margin-bottom: 8px;
  902. display: block;
  903. }}
  904. .step-field-value {{
  905. color: #1f2937;
  906. font-size: 15px;
  907. line-height: 1.7;
  908. }}
  909. .matches-list {{
  910. display: flex;
  911. flex-direction: column;
  912. gap: 15px;
  913. margin-top: 10px;
  914. }}
  915. .match-item {{
  916. background: white;
  917. padding: 18px;
  918. border-radius: 10px;
  919. border-left: 5px solid #3b82f6;
  920. }}
  921. .match-item.top1 {{
  922. border-left-color: #fbbf24;
  923. background: linear-gradient(135deg, #fef3c7 0%, #fde68a 50%, white 100%);
  924. }}
  925. .match-item.top2 {{
  926. border-left-color: #c0c0c0;
  927. background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 50%, white 100%);
  928. }}
  929. .match-item.top3 {{
  930. border-left-color: #cd7f32;
  931. background: linear-gradient(135deg, #fef3c7 0%, #fed7aa 50%, white 100%);
  932. }}
  933. .match-header {{
  934. display: flex;
  935. justify-content: space-between;
  936. align-items: center;
  937. margin-bottom: 12px;
  938. gap: 10px;
  939. }}
  940. .match-rank {{
  941. font-size: 18px;
  942. font-weight: 800;
  943. color: #6b7280;
  944. }}
  945. .match-element-name {{
  946. flex: 1;
  947. font-size: 16px;
  948. font-weight: 700;
  949. color: #1f2937;
  950. }}
  951. .match-score {{
  952. font-size: 22px;
  953. font-weight: 800;
  954. color: #2563eb;
  955. background: white;
  956. padding: 6px 14px;
  957. border-radius: 8px;
  958. }}
  959. .match-detail {{
  960. background: rgba(255, 255, 255, 0.7);
  961. padding: 10px;
  962. border-radius: 6px;
  963. margin-bottom: 10px;
  964. font-size: 13px;
  965. color: #4b5563;
  966. }}
  967. .match-reason {{
  968. color: #1f2937;
  969. font-size: 14px;
  970. line-height: 1.7;
  971. }}
  972. .increment-matches {{
  973. display: flex;
  974. flex-direction: column;
  975. gap: 12px;
  976. margin-top: 10px;
  977. }}
  978. .increment-item {{
  979. background: white;
  980. padding: 15px;
  981. border-radius: 8px;
  982. border-left: 4px solid #10b981;
  983. }}
  984. .increment-header {{
  985. display: flex;
  986. justify-content: space-between;
  987. align-items: center;
  988. margin-bottom: 10px;
  989. }}
  990. .increment-words {{
  991. font-weight: 700;
  992. color: #1f2937;
  993. font-size: 15px;
  994. }}
  995. .increment-score {{
  996. font-size: 20px;
  997. font-weight: 800;
  998. color: #10b981;
  999. }}
  1000. .increment-reason {{
  1001. color: #4b5563;
  1002. font-size: 13px;
  1003. line-height: 1.6;
  1004. }}
  1005. .empty-state {{
  1006. text-align: center;
  1007. padding: 40px;
  1008. color: #9ca3af;
  1009. font-size: 14px;
  1010. }}
  1011. .modal-link {{
  1012. margin-top: 25px;
  1013. padding-top: 20px;
  1014. border-top: 2px solid #e5e7eb;
  1015. text-align: center;
  1016. }}
  1017. .modal-link-btn {{
  1018. display: inline-flex;
  1019. align-items: center;
  1020. gap: 10px;
  1021. padding: 12px 24px;
  1022. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  1023. color: white;
  1024. text-decoration: none;
  1025. border-radius: 10px;
  1026. font-size: 15px;
  1027. font-weight: 600;
  1028. transition: all 0.3s;
  1029. }}
  1030. .modal-link-btn:hover {{
  1031. transform: translateY(-2px);
  1032. box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4);
  1033. }}
  1034. .timestamp {{
  1035. text-align: center;
  1036. color: white;
  1037. font-size: 13px;
  1038. margin-top: 30px;
  1039. opacity: 0.8;
  1040. }}
  1041. @media (max-width: 768px) {{
  1042. .inspirations-grid {{
  1043. grid-template-columns: 1fr;
  1044. }}
  1045. .header h1 {{
  1046. font-size: 32px;
  1047. }}
  1048. .stats-overview {{
  1049. grid-template-columns: repeat(2, 1fr);
  1050. }}
  1051. }}
  1052. </style>
  1053. </head>
  1054. <body>
  1055. <div class="container">
  1056. <div class="header">
  1057. <h1>💡 灵感点分析可视化</h1>
  1058. <div class="header-subtitle">基于HOW人设的灵感点匹配分析结果</div>
  1059. <div class="stats-overview">
  1060. <div class="stat-box">
  1061. <div class="stat-label">分析总数</div>
  1062. <div class="stat-value" id="totalCount">{total_count}</div>
  1063. </div>
  1064. <div class="stat-box excellent">
  1065. <div class="stat-label">优秀 (≥70)</div>
  1066. <div class="stat-value" id="excellentCount">{excellent_count}</div>
  1067. </div>
  1068. <div class="stat-box good">
  1069. <div class="stat-label">良好 (50-70)</div>
  1070. <div class="stat-value" id="goodCount">{good_count}</div>
  1071. </div>
  1072. <div class="stat-box normal">
  1073. <div class="stat-label">一般 (30-50)</div>
  1074. <div class="stat-value" id="normalCount">{normal_count}</div>
  1075. </div>
  1076. <div class="stat-box need-opt">
  1077. <div class="stat-label">待优化 (<30)</div>
  1078. <div class="stat-value" id="needOptCount">{need_opt_count}</div>
  1079. </div>
  1080. <div class="stat-box">
  1081. <div class="stat-label">平均分数</div>
  1082. <div class="stat-value" id="avgScore">{avg_score:.1f}</div>
  1083. </div>
  1084. </div>
  1085. </div>
  1086. <div class="controls-section">
  1087. <div class="search-box">
  1088. <input type="text"
  1089. id="searchInput"
  1090. class="search-input"
  1091. placeholder="🔍 搜索灵感点名称..."
  1092. oninput="filterInspirations()">
  1093. </div>
  1094. <div class="sort-box">
  1095. <span class="sort-label">排序方式:</span>
  1096. <select id="sortSelect" class="sort-select" onchange="filterInspirations()">
  1097. <option value="score-desc">分数从高到低</option>
  1098. <option value="score-asc">分数从低到高</option>
  1099. <option value="name-asc">名称A-Z</option>
  1100. <option value="name-desc">名称Z-A</option>
  1101. </select>
  1102. </div>
  1103. </div>
  1104. <div class="inspirations-section">
  1105. <div class="inspirations-grid">
  1106. {cards_html_str}
  1107. </div>
  1108. </div>
  1109. <div class="timestamp">生成时间: {timestamp}</div>
  1110. <!-- Modal -->
  1111. <div id="detailModal" class="modal-overlay" onclick="closeModalOnOverlay(event)">
  1112. <div class="modal-content">
  1113. <button class="modal-close" onclick="closeModal()">&times;</button>
  1114. <div class="modal-body" id="modalBody">
  1115. <!-- Content will be inserted here -->
  1116. </div>
  1117. </div>
  1118. </div>
  1119. </div>
  1120. <script>
  1121. {detail_modal_js}
  1122. </script>
  1123. </body>
  1124. </html>'''
  1125. # 写入文件
  1126. output_file = Path(output_path)
  1127. output_file.parent.mkdir(parents=True, exist_ok=True)
  1128. with open(output_file, 'w', encoding='utf-8') as f:
  1129. f.write(html_content)
  1130. return str(output_file.absolute())
  1131. def main():
  1132. """主函数"""
  1133. import sys
  1134. # 配置路径
  1135. inspiration_dir = "/Users/semsevens/Desktop/workspace/aaa/dev_3/data/阿里多多酱/out/人设_1110/how/灵感点"
  1136. posts_dir = "/Users/semsevens/Desktop/workspace/aaa/dev_3/data/阿里多多酱/作者历史帖子"
  1137. output_path = "/Users/semsevens/Desktop/workspace/aaa/dev_3/data/阿里多多酱/out/人设_1110/how/灵感点可视化.html"
  1138. print("=" * 60)
  1139. print("灵感点分析可视化脚本")
  1140. print("=" * 60)
  1141. # 加载数据
  1142. print("\n📂 正在加载灵感点数据...")
  1143. inspirations_data = load_inspiration_points_data(inspiration_dir)
  1144. print(f"✅ 成功加载 {len(inspirations_data)} 个灵感点")
  1145. print("\n📂 正在加载帖子数据...")
  1146. posts_map = load_posts_data(posts_dir)
  1147. print(f"✅ 成功加载 {len(posts_map)} 个帖子")
  1148. # 生成HTML
  1149. print("\n🎨 正在生成可视化HTML...")
  1150. result_path = generate_html(inspirations_data, posts_map, output_path)
  1151. print(f"\n✅ 可视化文件已生成!")
  1152. print(f"📄 文件路径: {result_path}")
  1153. print(f"\n💡 在浏览器中打开该文件即可查看可视化结果")
  1154. print("=" * 60)
  1155. if __name__ == "__main__":
  1156. main()