Tesneem commited on
Commit
e73844f
·
verified ·
1 Parent(s): d541640

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py CHANGED
@@ -248,6 +248,32 @@ import unicodedata
248
  from collections import Counter
249
  from difflib import SequenceMatcher
250
  import math
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251
 
252
  def _normalize_quotes_spaces(s: str) -> str:
253
  if not s:
 
248
  from collections import Counter
249
  from difflib import SequenceMatcher
250
  import math
251
+ # Stage <-> Source mapping
252
+ STAGE_TO_SOURCE = {
253
+ "onboarding": "onboarding_responses",
254
+ "week_2": "week_2_responses",
255
+ "week_3": "week_3_responses",
256
+ "closing": "closing_responses", # future-proof
257
+ }
258
+ SOURCE_TO_STAGE = {v: k for k, v in STAGE_TO_SOURCE.items()}
259
+
260
+ def _responses_for_student_stage(uri, db, responses_coll, student: str, stage: str) -> list[dict]:
261
+ """Return responses for a student at a stage (mapped to source) with non-empty answers."""
262
+ if not (uri and student and stage):
263
+ return []
264
+ src = STAGE_TO_SOURCE.get(stage)
265
+ if not src:
266
+ return []
267
+ try:
268
+ c = _client(uri)
269
+ docs = list(c[db][responses_coll].find(
270
+ {"student": student, "source": src},
271
+ {"_id": 0, "answer": 1, "skills": 1}
272
+ ))
273
+ # keep only responses with a non-empty answer
274
+ return [d for d in docs if (d.get("answer") or "").strip()]
275
+ except Exception:
276
+ return []
277
 
278
  def _normalize_quotes_spaces(s: str) -> str:
279
  if not s: