Spaces:
Runtime error
Runtime error
danielraynaud
commited on
Update performance_analyzer.py
Browse files- performance_analyzer.py +9 -31
performance_analyzer.py
CHANGED
@@ -1,56 +1,34 @@
|
|
1 |
import logging
|
2 |
from typing import Dict, List
|
3 |
|
4 |
-
logging.basicConfig(level=logging.INFO)
|
5 |
-
logger = logging.getLogger(__name__)
|
6 |
-
|
7 |
class PerformanceAnalyzer:
|
8 |
-
def __init__(self, db_connection):
|
9 |
self.conn = db_connection
|
10 |
-
|
11 |
def analyze_user_performance(self, user_id: str) -> Dict:
|
12 |
try:
|
13 |
cursor = self.conn.cursor()
|
14 |
cursor.execute('''
|
15 |
-
SELECT
|
16 |
-
topic,
|
17 |
-
AVG(performance_score) as avg_score,
|
18 |
-
COUNT(*) as total_sessions
|
19 |
FROM study_progress
|
20 |
WHERE user_id = ?
|
21 |
GROUP BY topic
|
22 |
''', (user_id,))
|
23 |
-
|
24 |
-
results = cursor.fetchall()
|
25 |
-
return {
|
26 |
-
'performance_by_topic': [dict(r) for r in results],
|
27 |
-
'overall_score': self._calculate_overall_score(results)
|
28 |
-
}
|
29 |
except Exception as e:
|
30 |
-
|
31 |
return {}
|
32 |
|
33 |
def get_weak_areas(self, user_id: str) -> List[str]:
|
34 |
try:
|
35 |
cursor = self.conn.cursor()
|
36 |
cursor.execute('''
|
37 |
-
SELECT
|
38 |
-
topic,
|
39 |
-
AVG(performance_score) as avg_score
|
40 |
FROM study_progress
|
41 |
-
WHERE user_id = ?
|
42 |
GROUP BY topic
|
43 |
-
HAVING avg_score < 70
|
44 |
-
ORDER BY avg_score ASC
|
45 |
''', (user_id,))
|
46 |
-
|
47 |
return [row['topic'] for row in cursor.fetchall()]
|
48 |
except Exception as e:
|
49 |
-
|
50 |
-
return []
|
51 |
-
|
52 |
-
def _calculate_overall_score(self, results) -> float:
|
53 |
-
if not results:
|
54 |
-
return 0.0
|
55 |
-
total_score = sum(r['avg_score'] for r in results)
|
56 |
-
return round(total_score / len(results), 2)
|
|
|
1 |
import logging
|
2 |
from typing import Dict, List
|
3 |
|
|
|
|
|
|
|
4 |
class PerformanceAnalyzer:
|
5 |
+
def __init__(self, db_connection):
|
6 |
self.conn = db_connection
|
7 |
+
|
8 |
def analyze_user_performance(self, user_id: str) -> Dict:
|
9 |
try:
|
10 |
cursor = self.conn.cursor()
|
11 |
cursor.execute('''
|
12 |
+
SELECT topic, AVG(performance_score) as avg_score
|
|
|
|
|
|
|
13 |
FROM study_progress
|
14 |
WHERE user_id = ?
|
15 |
GROUP BY topic
|
16 |
''', (user_id,))
|
17 |
+
return dict(cursor.fetchall())
|
|
|
|
|
|
|
|
|
|
|
18 |
except Exception as e:
|
19 |
+
logging.error(f"Erro ao analisar performance: {e}")
|
20 |
return {}
|
21 |
|
22 |
def get_weak_areas(self, user_id: str) -> List[str]:
|
23 |
try:
|
24 |
cursor = self.conn.cursor()
|
25 |
cursor.execute('''
|
26 |
+
SELECT topic
|
|
|
|
|
27 |
FROM study_progress
|
28 |
+
WHERE user_id = ? AND performance_score < 70
|
29 |
GROUP BY topic
|
|
|
|
|
30 |
''', (user_id,))
|
|
|
31 |
return [row['topic'] for row in cursor.fetchall()]
|
32 |
except Exception as e:
|
33 |
+
logging.error(f"Erro ao buscar áreas fracas: {e}")
|
34 |
+
return []
|
|
|
|
|
|
|
|
|
|
|
|