显示数据分析报告
(final_state: Dict)
| 686 | return final_state, "quit" |
| 687 | |
| 688 | def display_data_report(final_state: Dict): |
| 689 | """显示数据分析报告""" |
| 690 | if not final_state: |
| 691 | console.print("[red]无结果可显示[/red]") |
| 692 | return |
| 693 | |
| 694 | try: |
| 695 | from .static.report_template import DataReportGenerator |
| 696 | |
| 697 | # 从final_state获取trigger_time,然后读取factors数据 |
| 698 | trigger_time = final_state.get('trigger_time', 'N/A') |
| 699 | |
| 700 | # 读取factors文件夹中的数据 |
| 701 | factors_data = load_factors_data(trigger_time) |
| 702 | |
| 703 | if not factors_data or not factors_data.get('agents'): |
| 704 | console.print("[yellow]未找到数据分析结果[/yellow]") |
| 705 | return |
| 706 | |
| 707 | generator = DataReportGenerator(factors_data) |
| 708 | |
| 709 | # 生成报告内容 |
| 710 | total_agents = len(factors_data.get('agents', {})) |
| 711 | |
| 712 | markdown_content = f"""# ContestTrade {get_text('数据分析报告', 'Data Analysis Report')} |
| 713 | |
| 714 | ## 📊 {get_text('数据摘要', 'Data Summary')} |
| 715 | |
| 716 | **{get_text('分析时间', 'Analysis Time')}**: {trigger_time} |
| 717 | **{get_text('分析状态', 'Analysis Status')}**: ✅ {get_text('完成', 'Completed')} |
| 718 | **{get_text('数据代理数量', 'Data Agent Count')}**: {total_agents} |
| 719 | |
| 720 | --- |
| 721 | |
| 722 | ## 🔍 {get_text('数据源分析详情', 'Data Source Analysis Details')} |
| 723 | |
| 724 | """ |
| 725 | |
| 726 | # 遍历每个代理的数据 |
| 727 | for agent_name, agent_data in factors_data.get('agents', {}).items(): |
| 728 | markdown_content += f"### 📈 {agent_name.replace('_', ' ').title()}\n\n" |
| 729 | |
| 730 | # 只获取context_string字段 |
| 731 | context_string = agent_data.get('context_string', '') |
| 732 | |
| 733 | if context_string: |
| 734 | # 清洗掉 [Batch X] 标记 |
| 735 | cleaned_context = re.sub(r'\[Batch \d+\]', '', context_string).strip() |
| 736 | markdown_content += f"{cleaned_context}\n\n" |
| 737 | else: |
| 738 | markdown_content += f"**{get_text('暂无分析内容', 'No analysis content available')}**\n\n" |
| 739 | |
| 740 | markdown_content += "---\n\n" |
| 741 | |
| 742 | generator.display_terminal_interactive_report(markdown_content) |
| 743 | |
| 744 | except Exception as e: |
| 745 | console.print(f"[red]数据报告显示失败: {e}[/red]") |
no test coverage detected