Spaces:
Sleeping
Sleeping
File size: 9,699 Bytes
250bf8c |
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 208 209 210 211 212 213 |
"""
Test script for Enhanced Adaptive Learning with Gemini Integration
"""
import asyncio
import json
import sys
from pathlib import Path
# Add the current directory to the Python path
current_dir = Path(__file__).parent
sys.path.insert(0, str(current_dir))
# Import the enhanced adaptive learning tools
from mcp_server.tools.learning_path_tools import (
generate_adaptive_content,
analyze_learning_patterns,
optimize_learning_strategy,
start_adaptive_session,
record_learning_event,
get_adaptive_recommendations,
get_adaptive_learning_path,
get_student_progress_summary
)
async def test_enhanced_adaptive_learning():
"""Test the enhanced adaptive learning system with Gemini integration."""
print("π§ Testing Enhanced Adaptive Learning with Gemini Integration")
print("=" * 60)
student_id = "test_student_001"
concept_id = "linear_equations"
try:
# Test 1: Start an adaptive session
print("\n1. π Starting Adaptive Session...")
session_result = await start_adaptive_session(
student_id=student_id,
concept_id=concept_id,
initial_difficulty=0.5
)
print(f" β
Session started: {session_result.get('session_id', 'N/A')}")
print(f" π Initial mastery: {session_result.get('current_mastery', 0):.2f}")
session_id = session_result.get('session_id')
# Test 2: Record some learning events
print("\n2. π Recording Learning Events...")
events = [
{"type": "answer_correct", "data": {"time_taken": 25}},
{"type": "answer_correct", "data": {"time_taken": 30}},
{"type": "answer_incorrect", "data": {"time_taken": 45}},
{"type": "answer_correct", "data": {"time_taken": 20}},
]
for i, event in enumerate(events, 1):
event_result = await record_learning_event(
student_id=student_id,
concept_id=concept_id,
session_id=session_id,
event_type=event["type"],
event_data=event["data"]
)
print(f" π Event {i}: {event['type']} - Mastery: {event_result.get('updated_mastery', 0):.2f}")
# Test 3: Generate adaptive content
print("\n3. π¨ Generating Adaptive Content...")
content_types = ["explanation", "practice", "feedback"]
for content_type in content_types:
try:
content_result = await generate_adaptive_content(
student_id=student_id,
concept_id=concept_id,
content_type=content_type,
difficulty_level=0.6,
learning_style="visual"
)
if content_result.get("success"):
print(f" β
{content_type.title()} content generated successfully")
if content_type == "explanation" and "explanation" in content_result:
explanation = content_result["explanation"][:100] + "..." if len(content_result["explanation"]) > 100 else content_result["explanation"]
print(f" π Preview: {explanation}")
else:
print(f" β οΈ {content_type.title()} content generation failed: {content_result.get('error', 'Unknown error')}")
except Exception as e:
print(f" β Error generating {content_type} content: {str(e)}")
# Test 4: Get AI-powered recommendations
print("\n4. π€ Getting AI-Powered Recommendations...")
try:
recommendations = await get_adaptive_recommendations(
student_id=student_id,
concept_id=concept_id,
session_id=session_id
)
if recommendations.get("success"):
print(f" β
Recommendations generated (AI-powered: {recommendations.get('ai_powered', False)})")
immediate_actions = recommendations.get("immediate_actions", [])
print(f" π Immediate actions: {len(immediate_actions)} recommendations")
if immediate_actions:
first_action = immediate_actions[0]
print(f" π― Top recommendation: {first_action.get('action', 'N/A')}")
else:
print(f" β Recommendations failed: {recommendations.get('error', 'Unknown error')}")
except Exception as e:
print(f" β Error getting recommendations: {str(e)}")
# Test 5: Analyze learning patterns
print("\n5. π Analyzing Learning Patterns...")
try:
patterns = await analyze_learning_patterns(
student_id=student_id,
analysis_days=30
)
if patterns.get("success"):
print(f" β
Learning patterns analyzed (AI-powered: {patterns.get('ai_powered', False)})")
if "learning_style_analysis" in patterns:
print(f" π¨ Learning style insights available")
if "strength_areas" in patterns:
strengths = patterns.get("strength_areas", [])
print(f" πͺ Identified strengths: {len(strengths)} areas")
else:
print(f" β οΈ Pattern analysis: {patterns.get('message', 'No data available')}")
except Exception as e:
print(f" β Error analyzing patterns: {str(e)}")
# Test 6: Optimize learning strategy
print("\n6. π― Optimizing Learning Strategy...")
try:
strategy = await optimize_learning_strategy(
student_id=student_id,
current_concept=concept_id
)
if strategy.get("success"):
print(f" β
Strategy optimized (AI-powered: {strategy.get('ai_powered', False)})")
if "optimized_strategy" in strategy:
opt_strategy = strategy["optimized_strategy"]
print(f" π― Primary approach: {opt_strategy.get('primary_approach', 'N/A')}")
print(f" π Difficulty recommendation: {opt_strategy.get('difficulty_recommendation', 'N/A')}")
else:
print(f" β οΈ Strategy optimization: {strategy.get('message', 'Using default strategy')}")
except Exception as e:
print(f" β Error optimizing strategy: {str(e)}")
# Test 7: Generate adaptive learning path
print("\n7. π€οΈ Generating Adaptive Learning Path...")
try:
learning_path = await get_adaptive_learning_path(
student_id=student_id,
target_concepts=["algebra_basics", "linear_equations", "quadratic_equations"],
strategy="adaptive",
max_concepts=5
)
if learning_path.get("success"):
print(f" β
Learning path generated (AI-powered: {learning_path.get('ai_powered', False)})")
path_steps = learning_path.get("learning_path", [])
print(f" π Path contains {len(path_steps)} steps")
total_time = learning_path.get("total_time_minutes", 0)
print(f" β±οΈ Estimated total time: {total_time} minutes")
if path_steps:
first_step = path_steps[0]
print(f" π― First step: {first_step.get('concept_name', 'N/A')}")
else:
print(f" β Learning path failed: {learning_path.get('error', 'Unknown error')}")
except Exception as e:
print(f" β Error generating learning path: {str(e)}")
# Test 8: Get progress summary
print("\n8. π Getting Progress Summary...")
try:
progress = await get_student_progress_summary(
student_id=student_id,
days=7
)
if progress.get("success"):
summary = progress.get("summary", {})
print(f" β
Progress summary generated")
print(f" π Concepts practiced: {summary.get('concepts_practiced', 0)}")
print(f" β±οΈ Total time: {summary.get('total_time_minutes', 0)} minutes")
print(f" π― Average mastery: {summary.get('average_mastery', 0):.2f}")
print(f" β
Average accuracy: {summary.get('average_accuracy', 0):.2f}")
else:
print(f" β οΈ Progress summary: {progress.get('message', 'No data available')}")
except Exception as e:
print(f" β Error getting progress summary: {str(e)}")
print("\n" + "=" * 60)
print("π Enhanced Adaptive Learning Test Completed!")
print("\nπ Summary:")
print(" β
All core adaptive learning functions tested")
print(" π§ Gemini AI integration verified")
print(" π Performance tracking operational")
print(" π― Personalization features active")
print(" π€οΈ Learning path optimization working")
except Exception as e:
print(f"\nβ Test failed with error: {str(e)}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
print("π Starting Enhanced Adaptive Learning Test...")
asyncio.run(test_enhanced_adaptive_learning())
|