-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_data_flow.py
More file actions
207 lines (169 loc) · 7.63 KB
/
debug_data_flow.py
File metadata and controls
207 lines (169 loc) · 7.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/usr/bin/env python3
"""
Debug Data Flow Script for NEAR Partnership Analysis
This script helps diagnose data flow issues between agents and database storage.
It analyzes the database for common problems and provides detailed debugging information.
Usage:
python debug_data_flow.py # List all issues
python debug_data_flow.py --project NAME # Debug specific project
python debug_data_flow.py --fix-empty # Attempt to fix empty analyses
"""
import argparse
import json
from database import DatabaseManager
from agents import DIAGNOSTIC_QUESTIONS
def main():
"""Main debugging interface."""
parser = argparse.ArgumentParser(description='Debug NEAR Partnership Analysis data flow issues')
parser.add_argument('--project', type=str, help='Debug specific project by name')
parser.add_argument('--list-issues', action='store_true', help='List all problematic projects')
parser.add_argument('--summary', action='store_true', help='Show summary of database issues')
args = parser.parse_args()
db_manager = DatabaseManager()
if args.project:
debug_specific_project(db_manager, args.project)
elif args.list_issues:
list_all_issues(db_manager)
elif args.summary:
show_summary(db_manager)
else:
show_overview(db_manager)
def debug_specific_project(db_manager, project_name):
"""Debug a specific project in detail."""
print(f"🔍 Debugging project: {project_name}")
print("=" * 60)
debug_info = db_manager.debug_project_data(project_name)
# General research status
print("📊 GENERAL RESEARCH:")
if debug_info["general_research"]:
gr = debug_info["general_research"]
print(f" ✅ Success: {gr['success']}")
print(f" 📄 Data length: {gr['data_length']:,} chars")
print(f" 🔗 Sources: {gr['sources_count']}")
if gr['error']:
print(f" ❌ Error: {gr['error']}")
else:
print(" ❌ No general research found")
# Deep research status
print("\n🔬 DEEP RESEARCH:")
if debug_info["deep_research"]:
dr = debug_info["deep_research"]
print(f" ✅ Success: {dr['success']}")
print(f" 🚀 Enabled: {dr['enabled']}")
print(f" 📄 Data length: {dr['data_length']:,} chars")
print(f" 🔗 Sources: {dr['sources_count']}")
print(f" ⚙️ Tool calls: {dr['tool_calls']}")
print(f" ⏱️ Elapsed time: {dr['elapsed_time']:.1f}s")
print(f" 📝 Enhanced prompt length: {dr['enhanced_prompt_length']:,} chars")
if dr['error']:
print(f" ❌ Error: {dr['error']}")
else:
print(" ⚠️ No deep research data")
# Question analyses status
print("\n❓ QUESTION ANALYSES:")
if debug_info["question_analyses"]:
total_score = 0
for q in debug_info["question_analyses"]:
question_text = get_question_text(q["question_id"])
status = "✅" if q["has_analysis"] else "❌"
score_display = f"{q['score']:+d}" if q['score'] is not None else "NULL"
print(f" {status} Q{q['question_id']}: {question_text}")
print(f" Research: {q['research_data_length']:,} chars")
print(f" Analysis: {q['analysis_length']:,} chars")
print(f" Score: {score_display} | Confidence: {q['confidence']}")
if q["analysis_preview"]:
print(f" Preview: {q['analysis_preview'][:80]}...")
if q['score'] is not None:
total_score += q['score']
print(f"\n 📊 Total Score: {total_score}/6")
else:
print(" ❌ No question analyses found")
# Final summary status
print("\n📋 FINAL SUMMARY:")
if debug_info["final_summary"]:
fs = debug_info["final_summary"]
print(f" ✅ Success: {fs['success']}")
print(f" 📊 Total Score: {fs['total_score']}/6")
print(f" 🎯 Recommendation: {fs['recommendation']}")
print(f" 📄 Summary length: {fs['summary_length']:,} chars")
if fs['error']:
print(f" ❌ Error: {fs['error']}")
else:
print(" ❌ No final summary found")
# Issues summary
if debug_info["issues"]:
print("\n🚨 IDENTIFIED ISSUES:")
for issue in debug_info["issues"]:
print(f" • {issue}")
else:
print("\n✅ No issues detected")
def list_all_issues(db_manager):
"""List all problematic projects."""
print("🚨 PROBLEMATIC PROJECTS ANALYSIS")
print("=" * 60)
issues = db_manager.list_problematic_projects()
# Empty analyses
if issues["empty_analyses"]:
print(f"\n❌ PROJECTS WITH EMPTY ANALYSES ({len(issues['empty_analyses'])}):")
for project in issues["empty_analyses"]:
print(f" • {project}")
# Failed summaries
if issues["failed_summaries"]:
print(f"\n💥 PROJECTS WITH FAILED SUMMARIES ({len(issues['failed_summaries'])}):")
for project, error in issues["failed_summaries"]:
print(f" • {project}: {error}")
# Missing deep research
if issues["missing_deep_research"]:
print(f"\n🔬 PROJECTS WITHOUT DEEP RESEARCH ({len(issues['missing_deep_research'])}):")
for project in issues["missing_deep_research"][:10]: # Show first 10
print(f" • {project}")
if len(issues["missing_deep_research"]) > 10:
print(f" ... and {len(issues['missing_deep_research']) - 10} more")
# Zero scores (potential parsing issues)
if issues["zero_scores"]:
print(f"\n0️⃣ PROJECTS WITH ALL ZERO SCORES ({len(issues['zero_scores'])}):")
for project, question_count in issues["zero_scores"]:
print(f" • {project} ({question_count} questions)")
def show_summary(db_manager):
"""Show high-level summary of database status."""
print("📊 DATABASE SUMMARY")
print("=" * 60)
projects = db_manager.list_projects()
issues = db_manager.list_problematic_projects()
print(f"Total projects: {len(projects)}")
print(f"Projects with deep research: {sum(1 for p in projects if p['deep_research_performed'])}")
print(f"Projects with empty analyses: {len(issues['empty_analyses'])}")
print(f"Projects with failed summaries: {len(issues['failed_summaries'])}")
print(f"Projects with zero scores: {len(issues['zero_scores'])}")
# Score distribution
scores = [p['score'] for p in projects if p['score'] is not None]
if scores:
print(f"\nScore distribution:")
print(f" Min: {min(scores)}")
print(f" Max: {max(scores)}")
print(f" Avg: {sum(scores) / len(scores):.1f}")
def show_overview(db_manager):
"""Show overview of debugging options."""
print("🔍 NEAR Partnership Analysis - Data Flow Debugger")
print("=" * 60)
print("Available debugging options:")
print()
print(" --project NAME Debug specific project in detail")
print(" --list-issues List all projects with data issues")
print(" --summary Show high-level database summary")
print()
print("Examples:")
print(" python debug_data_flow.py --project 'MyProject'")
print(" python debug_data_flow.py --list-issues")
print(" python debug_data_flow.py --summary")
print()
# Quick summary
show_summary(db_manager)
def get_question_text(question_id):
"""Get question text by ID."""
for q in DIAGNOSTIC_QUESTIONS:
if q['id'] == question_id:
return q['question']
return f"Question {question_id}"
if __name__ == "__main__":
main()