Spaces:
Sleeping
Sleeping
| """ | |
| Debug script to verify grant data is loading correctly. | |
| Run with: python debug_data.py | |
| """ | |
| from pathlib import Path | |
| from src.analyzer.data_loader import load_current_grants | |
| from src.analyzer.search.service import get_grant_by_id | |
| print("=" * 60) | |
| print("GRANT DATA DEBUG") | |
| print("=" * 60) | |
| # Load all grants | |
| print("\n1. Loading grants from snapshots...") | |
| grants = load_current_grants(Path('data/snapshots')) | |
| print(f" β Loaded {len(grants)} grants") | |
| # Check grant 2313 specifically | |
| print("\n2. Checking competition-2313 (Battery Feasibility)...") | |
| grant_2313 = next((g for g in grants if '2313' in g.id), None) | |
| if grant_2313: | |
| print(f" β Found grant: {grant_2313.title}") | |
| print(f" Status: {grant_2313.status}") | |
| print(f" Has funding: {grant_2313.funding is not None}") | |
| if grant_2313.funding: | |
| print(f" Funding min: Β£{grant_2313.funding.min:,.0f}" if grant_2313.funding.min else " Funding min: None") | |
| print(f" Funding max: Β£{grant_2313.funding.max:,.0f}" if grant_2313.funding.max else " Funding max: None") | |
| print(f" Total pot: Β£{grant_2313.funding.total_pot:,.0f}" if grant_2313.funding.total_pot else " Total pot: None") | |
| else: | |
| print(" β NO FUNDING DATA") | |
| print(f" Has summary: {grant_2313.summary is not None and len(grant_2313.summary) > 0}") | |
| print(f" Close date: {grant_2313.close_date}") | |
| print(f" URL: {grant_2313.url}") | |
| else: | |
| print(" β Grant 2313 not found in loaded grants!") | |
| # Check grant 2314 | |
| print("\n3. Checking competition-2314 (Battery Concept)...") | |
| grant_2314 = next((g for g in grants if '2314' in g.id), None) | |
| if grant_2314: | |
| print(f" β Found grant: {grant_2314.title}") | |
| print(f" Status: {grant_2314.status}") | |
| if grant_2314.funding: | |
| print(f" Funding min: Β£{grant_2314.funding.min:,.0f}" if grant_2314.funding.min else " Funding min: None") | |
| print(f" Funding max: Β£{grant_2314.funding.max:,.0f}" if grant_2314.funding.max else " Funding max: None") | |
| else: | |
| print(" β NO FUNDING DATA") | |
| else: | |
| print(" β Grant 2314 not found!") | |
| # Check search index | |
| print("\n4. Checking search index (get_grant_by_id)...") | |
| try: | |
| indexed_grant = get_grant_by_id("competition-2313") | |
| if indexed_grant: | |
| print(f" β Found via search index: {indexed_grant.title}") | |
| print(f" Status via index: {indexed_grant.status}") | |
| print(f" Has funding via index: {indexed_grant.funding is not None}") | |
| if indexed_grant.funding: | |
| print(f" Funding via index: Β£{indexed_grant.funding.min:,.0f} - Β£{indexed_grant.funding.max:,.0f}") | |
| else: | |
| print(" β NO FUNDING DATA VIA INDEX") | |
| else: | |
| print(" β Not found via search index") | |
| except Exception as e: | |
| print(f" β Error accessing index: {e}") | |
| # Summary | |
| print("\n" + "=" * 60) | |
| print("DIAGNOSIS:") | |
| print("=" * 60) | |
| has_data = grant_2313 and grant_2313.funding and grant_2313.funding.min | |
| has_indexed_data = False | |
| try: | |
| indexed_grant = get_grant_by_id("competition-2313") | |
| has_indexed_data = indexed_grant and indexed_grant.funding and indexed_grant.funding.min | |
| except: | |
| pass | |
| if has_data and has_indexed_data: | |
| print("β Data is present and index is working") | |
| print(" Issue is likely in context building or LLM prompt") | |
| elif has_data and not has_indexed_data: | |
| print("β Data exists in snapshots") | |
| print("β Search index is not preserving the data") | |
| print(" ACTION: Rebuild search index") | |
| elif not has_data: | |
| print("β Data missing from snapshot files") | |
| print(" ACTION: Re-run scraper to get funding data") | |
| else: | |
| print("? Unclear - check logs above") | |
| print("=" * 60) | |