import os
import time
import json
from pathlib import Path
from services.simulator import SimulationEngine
from services.data_loader import load_personas, load_questions
import config

def reproduce_grit():
    print("REPRODUCE: Grit Chunk 1 Failure...")
    engine = SimulationEngine(config.ANTHROPIC_API_KEY)
    
    adolescents, _ = load_personas()
    student = adolescents[0] # Test with first student
    
    questions_map = load_questions()
    grit_qs = [q for q in questions_map.get('Grit', []) if '14-17' in q.get('age_group', '')]
    chunk1 = grit_qs[:20]
    
    print(f"STUDENT: {student.get('StudentCPID')}")
    print(f"CHUNKS: {len(chunk1)}")
    
    # Simulate single batch
    answers = engine.simulate_batch(student, chunk1, verbose=True)
    
    print("\nANALYSIS: Result Analysis:")
    if answers:
        print(f"✅ Received {len(answers)} keys.")
        missing = [q['q_code'] for q in chunk1 if q['q_code'] not in answers]
        if missing:
            print(f"❌ Missing {len(missing)} keys: {missing}")
    else:
        print("❌ Received ZERO answers.")

if __name__ == "__main__":
    reproduce_grit()
