#!/usr/bin/env python3
"""
Test script to verify AI comprehension evaluation is working
"""

import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

from app import create_app
from app.services.ai_assessment import get_ai_assessor
import json

def test_comprehension_evaluation():
    """Test the AI comprehension evaluation"""
    try:
        # Create Flask app context
        app = create_app()
        
        with app.app_context():
            ai = get_ai_assessor()
            
            # Test data
            question = "What is the main theme of this reading?"
            answer = "The main theme is about friendship and how people support each other during difficult times."
            reading_content = "This story talks about two friends who help each other through various challenges in their lives..."
            
            print("Testing AI comprehension evaluation...")
            print(f"Question: {question}")
            print(f"Answer: {answer}")
            print("-" * 50)
            
            # Get evaluation
            result = ai.evaluate_answer(question, answer, reading_content)
            
            print("AI Evaluation Result:")
            print(json.dumps(result, indent=2))
            
            # Check specific scores
            print("\nSpecific Scores:")
            print(f"Grammar Score: {result.get('grammar_score', 'NOT FOUND')}")
            print(f"Content Score: {result.get('content_score', 'NOT FOUND')}")
            print(f"Vocabulary Score: {result.get('vocabulary_score', 'NOT FOUND')}")
            print(f"Coherence Score: {result.get('coherence_score', 'NOT FOUND')}")
            print(f"Overall Score: {result.get('score', 'NOT FOUND')}")
            
            return result
        
    except Exception as e:
        print(f"Error testing comprehension evaluation: {e}")
        import traceback
        traceback.print_exc()
        return None

if __name__ == "__main__":
    test_comprehension_evaluation()