Tesneem commited on
Commit
fabfbc2
·
verified ·
1 Parent(s): 4d52461

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +84 -0
app.py CHANGED
@@ -246,6 +246,90 @@ fig = plot_radar(df_final, grouped, chart_title)
246
  st.plotly_chart(fig, use_container_width=True)
247
  st.caption(f"{len(df_final)} line(s) aggregated." if not df_final.empty else "No data.")
248
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
 
250
  # # app.py — Student Skill Radar (MongoDB, secrets-based, no CSV)
251
  # import os
 
246
  st.plotly_chart(fig, use_container_width=True)
247
  st.caption(f"{len(df_final)} line(s) aggregated." if not df_final.empty else "No data.")
248
 
249
+ # ================== Dynamic Stage Summaries ==================
250
+
251
+ STAGE_TO_SOURCE = {
252
+ "onboarding": "onboarding_responses",
253
+ "week_2": "week_2_responses",
254
+ "week_3": "week_3_responses",
255
+ "closing": "closing_responses" # for future
256
+ }
257
+ SOURCE_TO_STAGE = {v: k for k, v in STAGE_TO_SOURCE.items()}
258
+
259
+ def fetch_student_summary(uri, db, summaries_coll, responses_coll, student, stage):
260
+ """Fetch summary for a student/stage, filling missing or cut-off quotes from responses."""
261
+ if not (uri and student and stage):
262
+ return {}
263
+
264
+ c = _client(uri)
265
+ summary_doc = c[db][summaries_coll].find_one(
266
+ {"student_name": student, "stage": stage},
267
+ {"_id": 0, "most_consistent": 1, "most_developed": 1,
268
+ "top_strengths": 1, "notable_quotes": 1}
269
+ ) or {}
270
+
271
+ most_consistent = summary_doc.get("most_consistent")
272
+ most_developed = summary_doc.get("most_developed")
273
+ top_strengths = summary_doc.get("top_strengths", [])
274
+ notable_quotes = summary_doc.get("notable_quotes", [])
275
+
276
+ # If notable quotes missing or incomplete, pull from responses_IFE_2025
277
+ stage_source = STAGE_TO_SOURCE.get(stage)
278
+ if stage_source:
279
+ responses = list(c[db][responses_coll].find(
280
+ {"student": student, "source": stage_source},
281
+ {"_id": 0, "answer": 1, "skills": 1}
282
+ ))
283
+
284
+ # Fix cut-off quotes
285
+ fixed_quotes = []
286
+ for q in notable_quotes:
287
+ if len(q.strip()) < 50: # arbitrary cutoff detection
288
+ # Try to find a full match in responses
289
+ for r in responses:
290
+ if q.strip() in (r.get("answer") or ""):
291
+ fixed_quotes.append(r.get("answer"))
292
+ break
293
+ else:
294
+ fixed_quotes.append(q)
295
+ notable_quotes = fixed_quotes
296
+
297
+ # If still no quotes, pick up to 3 top scoring answers
298
+ if not notable_quotes:
299
+ scored_answers = []
300
+ for r in responses:
301
+ skills = r.get("skills", {})
302
+ max_skill_score = max(
303
+ (to_01_or_nan(v) for v in skills.values() if v is not None),
304
+ default=0
305
+ )
306
+ scored_answers.append((max_skill_score, r.get("answer")))
307
+ scored_answers.sort(reverse=True, key=lambda x: x[0])
308
+ notable_quotes = [ans for _, ans in scored_answers[:3] if ans]
309
+
310
+ return {
311
+ "most_consistent": most_consistent,
312
+ "most_developed": most_developed,
313
+ "top_strengths": top_strengths,
314
+ "notable_quotes": notable_quotes
315
+ }
316
+
317
+ # Render summaries dynamically when a single student & single source/stage is selected
318
+ if student_choice != "(All)" and source_choice != "(All)":
319
+ stage = SOURCE_TO_STAGE.get(source_choice)
320
+ if stage:
321
+ summary_data = fetch_student_summary(
322
+ mongo_uri, db_name, "summaries_IFE_2025",
323
+ coll_name, student_choice, stage
324
+ )
325
+ if summary_data:
326
+ st.subheader(f"Summary — {student_choice} ({stage})")
327
+ st.markdown(f"**Most Consistent Skill:** {summary_data.get('most_consistent', 'N/A')}")
328
+ st.markdown(f"**Most Developed Skill:** {summary_data.get('most_developed', 'N/A')}")
329
+ st.markdown("**Top Strengths:** " + ", ".join(summary_data.get('top_strengths', [])) or "N/A")
330
+ st.markdown("**Notable Quotes:**")
331
+ for q in summary_data.get("notable_quotes", []):
332
+ st.markdown(f"> {q}")
333
 
334
  # # app.py — Student Skill Radar (MongoDB, secrets-based, no CSV)
335
  # import os