#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Stage5搜索结果可视化工具 生成带图片轮播的交互式HTML页面 """ import json import os from datetime import datetime from typing import List, Dict, Any def load_data(json_path: str) -> List[Dict[str, Any]]: """加载JSON数据""" with open(json_path, 'r', encoding='utf-8') as f: return json.load(f) def calculate_statistics(data: List[Dict[str, Any]]) -> Dict[str, Any]: """计算统计数据""" total_features = len(data) total_search_words = 0 total_notes = 0 video_count = 0 normal_count = 0 for feature in data: search_results = feature.get('组合评估结果', []) total_search_words += len(search_results) for search_item in search_results: search_result = search_item.get('search_result', {}) notes = search_result.get('data', {}).get('data', []) total_notes += len(notes) for note in notes: note_type = note.get('note_card', {}).get('type', '') if note_type == 'video': video_count += 1 else: normal_count += 1 return { 'total_features': total_features, 'total_search_words': total_search_words, 'total_notes': total_notes, 'video_count': video_count, 'normal_count': normal_count, 'video_percentage': round(video_count / total_notes * 100, 1) if total_notes > 0 else 0, 'normal_percentage': round(normal_count / total_notes * 100, 1) if total_notes > 0 else 0 } def generate_html(data: List[Dict[str, Any]], stats: Dict[str, Any], output_path: str): """生成HTML可视化页面""" # 准备数据JSON(用于JavaScript) data_json = json.dumps(data, ensure_ascii=False, indent=2) html_content = f'''