Spaces:
Running
Running
github-actions[bot] commited on
Commit ·
462a5fb
1
Parent(s): 1861128
🚀 Auto-deploy backend from GitHub (30daf4f)
Browse files- routes/diagnostic.py +7 -9
routes/diagnostic.py
CHANGED
|
@@ -20,6 +20,8 @@ from pydantic import BaseModel, Field
|
|
| 20 |
|
| 21 |
from services.ai_client import CHAT_MODEL, get_deepseek_client
|
| 22 |
from rag.curriculum_rag import retrieve_curriculum_context
|
|
|
|
|
|
|
| 23 |
|
| 24 |
logger = logging.getLogger("mathpulse.diagnostic")
|
| 25 |
|
|
@@ -386,7 +388,7 @@ async def _store_diagnostic_session(
|
|
| 386 |
doc_ref.set({
|
| 387 |
"testId": test_id,
|
| 388 |
"userId": user_id,
|
| 389 |
-
"generatedAt":
|
| 390 |
"strand": strand,
|
| 391 |
"gradeLevel": grade_level,
|
| 392 |
"questions": questions,
|
|
@@ -435,8 +437,6 @@ async def generate_diagnostic(request: DiagnosticGenerateRequest, req: Request):
|
|
| 435 |
raise HTTPException(status_code=500, detail="Assessment generation failed. Please try again.")
|
| 436 |
|
| 437 |
try:
|
| 438 |
-
import firebase_admin
|
| 439 |
-
from firebase_admin import firestore as fs
|
| 440 |
firestore_client = fs.client()
|
| 441 |
stored = await _store_diagnostic_session(
|
| 442 |
firestore_client,
|
|
@@ -620,7 +620,7 @@ async def _save_results(
|
|
| 620 |
firestore_client.collection("diagnosticResults").document(user_id).set({
|
| 621 |
"userId": user_id,
|
| 622 |
"testId": test_id,
|
| 623 |
-
"takenAt":
|
| 624 |
"strand": strand,
|
| 625 |
"gradeLevel": grade_level,
|
| 626 |
"status": "completed",
|
|
@@ -637,9 +637,9 @@ async def _save_results(
|
|
| 637 |
firestore_client.collection("studentProgress").document(user_id).collection("stats").document("main").set({
|
| 638 |
"learning_path": risk_profile.get("suggested_learning_path", []),
|
| 639 |
"current_topic_index": 0,
|
| 640 |
-
"total_xp":
|
| 641 |
"current_streak_days": 1,
|
| 642 |
-
"badges":
|
| 643 |
"topics_mastered": mastered_count,
|
| 644 |
"diagnostic_completed": True,
|
| 645 |
"overall_risk": risk_profile.get("overall_risk", "moderate"),
|
|
@@ -647,7 +647,7 @@ async def _save_results(
|
|
| 647 |
|
| 648 |
firestore_client.collection("diagnosticSessions").document(test_id).update({
|
| 649 |
"status": "completed",
|
| 650 |
-
"completedAt":
|
| 651 |
})
|
| 652 |
|
| 653 |
except Exception as e:
|
|
@@ -662,8 +662,6 @@ async def submit_diagnostic(request: DiagnosticSubmitRequest, req: Request):
|
|
| 662 |
raise HTTPException(status_code=401, detail="Authentication required")
|
| 663 |
|
| 664 |
try:
|
| 665 |
-
import firebase_admin
|
| 666 |
-
from firebase_admin import firestore as fs
|
| 667 |
firestore_client = fs.client()
|
| 668 |
except Exception as e:
|
| 669 |
raise HTTPException(status_code=503, detail="Database unavailable")
|
|
|
|
| 20 |
|
| 21 |
from services.ai_client import CHAT_MODEL, get_deepseek_client
|
| 22 |
from rag.curriculum_rag import retrieve_curriculum_context
|
| 23 |
+
import firebase_admin
|
| 24 |
+
from firebase_admin import firestore as fs
|
| 25 |
|
| 26 |
logger = logging.getLogger("mathpulse.diagnostic")
|
| 27 |
|
|
|
|
| 388 |
doc_ref.set({
|
| 389 |
"testId": test_id,
|
| 390 |
"userId": user_id,
|
| 391 |
+
"generatedAt": fs.SERVER_TIMESTAMP,
|
| 392 |
"strand": strand,
|
| 393 |
"gradeLevel": grade_level,
|
| 394 |
"questions": questions,
|
|
|
|
| 437 |
raise HTTPException(status_code=500, detail="Assessment generation failed. Please try again.")
|
| 438 |
|
| 439 |
try:
|
|
|
|
|
|
|
| 440 |
firestore_client = fs.client()
|
| 441 |
stored = await _store_diagnostic_session(
|
| 442 |
firestore_client,
|
|
|
|
| 620 |
firestore_client.collection("diagnosticResults").document(user_id).set({
|
| 621 |
"userId": user_id,
|
| 622 |
"testId": test_id,
|
| 623 |
+
"takenAt": fs.SERVER_TIMESTAMP,
|
| 624 |
"strand": strand,
|
| 625 |
"gradeLevel": grade_level,
|
| 626 |
"status": "completed",
|
|
|
|
| 637 |
firestore_client.collection("studentProgress").document(user_id).collection("stats").document("main").set({
|
| 638 |
"learning_path": risk_profile.get("suggested_learning_path", []),
|
| 639 |
"current_topic_index": 0,
|
| 640 |
+
"total_xp": fs.Increment(50 + mastered_count * 10),
|
| 641 |
"current_streak_days": 1,
|
| 642 |
+
"badges": fs.ArrayUnion(["first_assessment"]),
|
| 643 |
"topics_mastered": mastered_count,
|
| 644 |
"diagnostic_completed": True,
|
| 645 |
"overall_risk": risk_profile.get("overall_risk", "moderate"),
|
|
|
|
| 647 |
|
| 648 |
firestore_client.collection("diagnosticSessions").document(test_id).update({
|
| 649 |
"status": "completed",
|
| 650 |
+
"completedAt": fs.SERVER_TIMESTAMP,
|
| 651 |
})
|
| 652 |
|
| 653 |
except Exception as e:
|
|
|
|
| 662 |
raise HTTPException(status_code=401, detail="Authentication required")
|
| 663 |
|
| 664 |
try:
|
|
|
|
|
|
|
| 665 |
firestore_client = fs.client()
|
| 666 |
except Exception as e:
|
| 667 |
raise HTTPException(status_code=503, detail="Database unavailable")
|