Spaces:
Runtime error
Runtime error
File size: 1,869 Bytes
9e33225 |
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 |
import logging
from typing import Dict, List
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
class PerformanceAnalyzer:
def __init__(self, db_connection):
self.conn = db_connection
def analyze_user_performance(self, user_id: str) -> Dict:
try:
cursor = self.conn.cursor()
cursor.execute('''
SELECT
topic,
AVG(performance_score) as avg_score,
COUNT(*) as total_sessions
FROM study_progress
WHERE user_id = ?
GROUP BY topic
''', (user_id,))
results = cursor.fetchall()
return {
'performance_by_topic': [dict(r) for r in results],
'overall_score': self._calculate_overall_score(results)
}
except Exception as e:
logger.error(f"Erro ao analisar performance: {e}")
return {}
def get_weak_areas(self, user_id: str) -> List[str]:
try:
cursor = self.conn.cursor()
cursor.execute('''
SELECT
topic,
AVG(performance_score) as avg_score
FROM study_progress
WHERE user_id = ?
GROUP BY topic
HAVING avg_score < 70
ORDER BY avg_score ASC
''', (user_id,))
return [row['topic'] for row in cursor.fetchall()]
except Exception as e:
logger.error(f"Erro ao identificar áreas fracas: {e}")
return []
def _calculate_overall_score(self, results) -> float:
if not results:
return 0.0
total_score = sum(r['avg_score'] for r in results)
return round(total_score / len(results), 2) |