Tesneem commited on
Commit
d4e49a0
Β·
verified Β·
1 Parent(s): eac0422

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -48
app.py CHANGED
@@ -530,57 +530,35 @@ def fetch_student_stage_summary(
530
  "notable_quotes": notable_quotes,
531
  }
532
 
533
- # ---------- Render the summary panel dynamically ----------
534
- if mongo_uri and student_choice != "(All)" and source_choice != "(All)":
535
- stage = SOURCE_TO_STAGE.get(source_choice.strip())
536
- if stage:
537
- # set to your actual summaries collection name
538
- summaries_coll_name = "summaries_IFE_2025"
539
- summary = fetch_student_stage_summary(
540
- mongo_uri, db_name, summaries_coll_name, coll_name,
541
- student=student_choice, stage=stage
542
- )
543
- if summary:
544
- st.markdown("---")
545
- st.subheader(f"Summary β€” {student_choice} ({stage.replace('_', ' ').title()})")
546
- c1, c2 = st.columns(2)
547
- with c1:
548
- st.markdown(f"**Most Consistent:** {summary.get('most_consistent') or 'β€”'}")
549
- st.markdown(f"**Most Developed:** {summary.get('most_developed') or 'β€”'}")
550
- with c2:
551
- strengths = summary.get("top_strengths") or []
552
- st.markdown("**Top Strengths:** " + (", ".join(strengths) if strengths else "β€”"))
553
-
554
- st.markdown("**Notable Quotes:**")
555
- for q in (summary.get("notable_quotes") or [])[:3]:
556
- st.markdown(f"> {q}")
557
  # # ------------------- Output (Tabs) -------------------
558
- tab_radar, tab_analyses = st.tabs(["πŸ“ˆ Radar", "πŸ“ Analyses"])
559
 
560
  with tab_radar:
561
- # Recompute a local copy for the tab (prevents reusing the same figure object)
562
- df_plot_local = df_final.copy()
563
- avg_label_local = None
564
-
565
- if not df_plot_local.empty:
566
- cols = list(SKILL_GROUPS.keys()) if grouped else SKILLS
567
- show_cohort_avg = st.toggle("Show cohort average (all students)", value=True, key="toggle_avg_radar")
568
- if show_cohort_avg:
569
- avg_vals = df_plot_local[cols].mean()
570
- avg_row = {"label": "Average (All Students)"}
571
- avg_row.update({k: float(avg_vals[k]) for k in cols})
572
- df_plot_local = pd.concat([df_plot_local, pd.DataFrame([avg_row])], ignore_index=True)
573
- avg_label_local = "Average (All Students)"
574
-
575
- # Build a fresh figure for the tab or copy if you already built one above:
576
- fig_tab = plot_radar(df_plot_local, grouped, chart_title, avg_label=avg_label_local)
577
- # fig_tab = go.Figure(fig) # <- alternative if you already computed `fig` above
578
-
579
- # Unique key to avoid Plotly id collisions on reruns/tab switches
580
- key_suffix = f"{student_choice}|{source_choice}|{int(grouped)}|{int(overlay_sources)}"
581
- st.plotly_chart(fig_tab, use_container_width=True, key=f"radar_tab_{key_suffix}")
582
-
583
- st.caption(f"{len(df_final)} line(s) aggregated." if not df_final.empty else "No data.")
 
584
 
585
  with tab_analyses:
586
  st.subheader("Student Analysis (Markdown)")
 
530
  "notable_quotes": notable_quotes,
531
  }
532
 
533
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
534
  # # ------------------- Output (Tabs) -------------------
535
+ tab_radar, tab_analyses = st.tabs(["πŸ“ˆ Summary", "πŸ“ Analyses"])
536
 
537
  with tab_radar:
538
+ # ---------- Render the summary panel dynamically ----------
539
+ if mongo_uri and student_choice != "(All)" and source_choice != "(All)":
540
+ stage = SOURCE_TO_STAGE.get(source_choice.strip())
541
+ if stage:
542
+ # set to your actual summaries collection name
543
+ summaries_coll_name = "summaries_IFE_2025"
544
+ summary = fetch_student_stage_summary(
545
+ mongo_uri, db_name, summaries_coll_name, coll_name,
546
+ student=student_choice, stage=stage
547
+ )
548
+ if summary:
549
+ st.markdown("---")
550
+ st.subheader(f"Summary β€” {student_choice} ({stage.replace('_', ' ').title()})")
551
+ c1, c2 = st.columns(2)
552
+ with c1:
553
+ st.markdown(f"**Most Consistent:** {summary.get('most_consistent') or 'β€”'}")
554
+ st.markdown(f"**Most Developed:** {summary.get('most_developed') or 'β€”'}")
555
+ with c2:
556
+ strengths = summary.get("top_strengths") or []
557
+ st.markdown("**Top Strengths:** " + (", ".join(strengths) if strengths else "β€”"))
558
+
559
+ st.markdown("**Notable Quotes:**")
560
+ for q in (summary.get("notable_quotes") or [])[:3]:
561
+ st.markdown(f"> {q}")
562
 
563
  with tab_analyses:
564
  st.subheader("Student Analysis (Markdown)")