Spaces:
Sleeping
Sleeping
Parthnuwal7 commited on
Commit ·
e3ab915
1
Parent(s): c1adf10
Fix1
Browse files- routes/scoring.py +13 -2
routes/scoring.py
CHANGED
|
@@ -23,8 +23,19 @@ def get_student_score(student_id):
|
|
| 23 |
Compute and return full scoring packet for a student
|
| 24 |
"""
|
| 25 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
# 1. Fetch student data
|
| 27 |
student_result = db.table('analytics_students').select('*').eq('student_id', student_id).maybe_single().execute()
|
|
|
|
|
|
|
| 28 |
if not student_result.data:
|
| 29 |
return jsonify({'error': 'Student not found', 'student_id': student_id}), 404
|
| 30 |
|
|
@@ -33,13 +44,13 @@ def get_student_score(student_id):
|
|
| 33 |
# 2. Fetch personality responses
|
| 34 |
personality_result = db.table('analytics_personality_responses').select('*').eq('student_id', student_id).maybe_single().execute()
|
| 35 |
personality_responses = {}
|
| 36 |
-
if personality_result.data:
|
| 37 |
personality_responses = {k: v for k, v in personality_result.data.items() if k.startswith('p_q')}
|
| 38 |
|
| 39 |
# 3. Fetch text responses
|
| 40 |
text_result = db.table('analytics_text_responses').select('*').eq('student_id', student_id).maybe_single().execute()
|
| 41 |
text_responses = {}
|
| 42 |
-
if text_result.data:
|
| 43 |
text_responses = {
|
| 44 |
'text_q1': text_result.data.get('text_q1', ''),
|
| 45 |
'text_q2': text_result.data.get('text_q2', ''),
|
|
|
|
| 23 |
Compute and return full scoring packet for a student
|
| 24 |
"""
|
| 25 |
try:
|
| 26 |
+
# Check database connection first
|
| 27 |
+
if db is None:
|
| 28 |
+
from database.db import get_db_error
|
| 29 |
+
return jsonify({
|
| 30 |
+
'error': 'Database not available',
|
| 31 |
+
'details': get_db_error(),
|
| 32 |
+
'hint': 'Check SUPABASE_URL and SUPABASE_KEY environment variables on HuggingFace'
|
| 33 |
+
}), 503
|
| 34 |
+
|
| 35 |
# 1. Fetch student data
|
| 36 |
student_result = db.table('analytics_students').select('*').eq('student_id', student_id).maybe_single().execute()
|
| 37 |
+
if student_result is None:
|
| 38 |
+
return jsonify({'error': 'Database query failed - connection may be lost'}), 503
|
| 39 |
if not student_result.data:
|
| 40 |
return jsonify({'error': 'Student not found', 'student_id': student_id}), 404
|
| 41 |
|
|
|
|
| 44 |
# 2. Fetch personality responses
|
| 45 |
personality_result = db.table('analytics_personality_responses').select('*').eq('student_id', student_id).maybe_single().execute()
|
| 46 |
personality_responses = {}
|
| 47 |
+
if personality_result and personality_result.data:
|
| 48 |
personality_responses = {k: v for k, v in personality_result.data.items() if k.startswith('p_q')}
|
| 49 |
|
| 50 |
# 3. Fetch text responses
|
| 51 |
text_result = db.table('analytics_text_responses').select('*').eq('student_id', student_id).maybe_single().execute()
|
| 52 |
text_responses = {}
|
| 53 |
+
if text_result and text_result.data:
|
| 54 |
text_responses = {
|
| 55 |
'text_q1': text_result.data.get('text_q1', ''),
|
| 56 |
'text_q2': text_result.data.get('text_q2', ''),
|