Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -529,107 +529,107 @@ def fetch_student_stage_summary(
|
|
| 529 |
"notable_quotes": notable_quotes,
|
| 530 |
}
|
| 531 |
|
| 532 |
-
#
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
#
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
# ------------------- Output (Tabs) -------------------
|
| 557 |
-
tab_radar, tab_analyses = st.tabs(["π Radar", "π Analyses"])
|
| 558 |
-
|
| 559 |
-
with tab_radar:
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
with tab_analyses:
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
|
| 634 |
|
| 635 |
|
|
|
|
| 529 |
"notable_quotes": notable_quotes,
|
| 530 |
}
|
| 531 |
|
| 532 |
+
# ---------- Render the summary panel dynamically ----------
|
| 533 |
+
if mongo_uri and student_choice != "(All)" and source_choice != "(All)":
|
| 534 |
+
stage = SOURCE_TO_STAGE.get(source_choice.strip())
|
| 535 |
+
if stage:
|
| 536 |
+
# set to your actual summaries collection name
|
| 537 |
+
summaries_coll_name = "summaries_IFE_2025"
|
| 538 |
+
summary = fetch_student_stage_summary(
|
| 539 |
+
mongo_uri, db_name, summaries_coll_name, coll_name,
|
| 540 |
+
student=student_choice, stage=stage
|
| 541 |
+
)
|
| 542 |
+
if summary:
|
| 543 |
+
st.markdown("---")
|
| 544 |
+
st.subheader(f"Summary β {student_choice} ({stage.replace('_', ' ').title()})")
|
| 545 |
+
c1, c2 = st.columns(2)
|
| 546 |
+
with c1:
|
| 547 |
+
st.markdown(f"**Most Consistent:** {summary.get('most_consistent') or 'β'}")
|
| 548 |
+
st.markdown(f"**Most Developed:** {summary.get('most_developed') or 'β'}")
|
| 549 |
+
with c2:
|
| 550 |
+
strengths = summary.get("top_strengths") or []
|
| 551 |
+
st.markdown("**Top Strengths:** " + (", ".join(strengths) if strengths else "β"))
|
| 552 |
+
|
| 553 |
+
st.markdown("**Notable Quotes:**")
|
| 554 |
+
for q in (summary.get("notable_quotes") or [])[:3]:
|
| 555 |
+
st.markdown(f"> {q}")
|
| 556 |
+
# # ------------------- Output (Tabs) -------------------
|
| 557 |
+
# tab_radar, tab_analyses = st.tabs(["π Radar", "π Analyses"])
|
| 558 |
+
|
| 559 |
+
# with tab_radar:
|
| 560 |
+
# # plot the radar (uses df_plot, avg_label already computed above)
|
| 561 |
+
# fig = plot_radar(df_plot, grouped, chart_title, avg_label=avg_label)
|
| 562 |
+
# st.plotly_chart(fig, use_container_width=True)
|
| 563 |
+
# st.caption(f"{len(df_final)} line(s) aggregated." if not df_final.empty else "No data.")
|
| 564 |
+
|
| 565 |
+
# # Dynamic stage summary panel (only if a specific student + source selected,
|
| 566 |
+
# # and only if they actually answered that week)
|
| 567 |
+
# if mongo_uri and student_choice != "(All)" and source_choice != "(All)":
|
| 568 |
+
# # Map the selected source (e.g., 'onboarding_responses') to stage (e.g., 'onboarding')
|
| 569 |
+
# stage = SOURCE_TO_STAGE.get(source_choice.strip())
|
| 570 |
+
# if stage:
|
| 571 |
+
# # summaries collection name (adjust if needed)
|
| 572 |
+
# summaries_coll_name = "summaries_IFE_2025"
|
| 573 |
+
|
| 574 |
+
# summary = fetch_student_stage_summary(
|
| 575 |
+
# mongo_uri, db_name, summaries_coll_name, coll_name,
|
| 576 |
+
# student=student_choice, stage=stage
|
| 577 |
+
# )
|
| 578 |
+
# if summary:
|
| 579 |
+
# st.markdown("---")
|
| 580 |
+
# st.subheader(f"Summary β {student_choice} ({stage.replace('_', ' ').title()})")
|
| 581 |
+
|
| 582 |
+
# c1, c2 = st.columns(2)
|
| 583 |
+
# with c1:
|
| 584 |
+
# st.markdown(f"**Most Consistent:** {summary.get('most_consistent') or 'β'}")
|
| 585 |
+
# st.markdown(f"**Most Developed:** {summary.get('most_developed') or 'β'}")
|
| 586 |
+
# with c2:
|
| 587 |
+
# strengths = summary.get("top_strengths") or []
|
| 588 |
+
# st.markdown("**Top Strengths:** " + (", ".join(strengths) if strengths else "β"))
|
| 589 |
+
|
| 590 |
+
# st.markdown("**Notable Quotes:**")
|
| 591 |
+
# for q in (summary.get("notable_quotes") or [])[:3]:
|
| 592 |
+
# st.markdown(f"> {q}")
|
| 593 |
+
|
| 594 |
+
# with tab_analyses:
|
| 595 |
+
# st.subheader("Student Analysis (Markdown)")
|
| 596 |
+
|
| 597 |
+
# # Use the folder you defined at top (ANALYSES_DIR), or expose it in the sidebar if you prefer.
|
| 598 |
+
# idx = _build_analysis_index(ANALYSES_DIR)
|
| 599 |
+
|
| 600 |
+
# if student_choice == "(All)":
|
| 601 |
+
# st.info("Pick a specific student on the left to view their analysis.")
|
| 602 |
+
# # (Optional) show what's available so you can browse:
|
| 603 |
+
# if idx:
|
| 604 |
+
# st.caption("Available analyses:")
|
| 605 |
+
# st.write(", ".join(sorted({name.title() for name in idx.keys()})))
|
| 606 |
+
# else:
|
| 607 |
+
# # Normalize the selected student name to match filenames
|
| 608 |
+
# norm = _normalize_name(student_choice)
|
| 609 |
+
# path = idx.get(norm)
|
| 610 |
+
|
| 611 |
+
# # If exact match not found, try simple underscore variant
|
| 612 |
+
# if not path:
|
| 613 |
+
# alt = student_choice.replace(" ", "_")
|
| 614 |
+
# path = idx.get(_normalize_name(alt))
|
| 615 |
+
|
| 616 |
+
# if path:
|
| 617 |
+
# md = _load_markdown(path)
|
| 618 |
+
# if md.strip():
|
| 619 |
+
# st.markdown(md, unsafe_allow_html=False)
|
| 620 |
+
# # Optional download button
|
| 621 |
+
# with open(path, "rb") as f:
|
| 622 |
+
# st.download_button(
|
| 623 |
+
# "Download analysis (.md)", f,
|
| 624 |
+
# file_name=os.path.basename(path), mime="text/markdown"
|
| 625 |
+
# )
|
| 626 |
+
# else:
|
| 627 |
+
# st.warning("Analysis file found but empty.")
|
| 628 |
+
# else:
|
| 629 |
+
# st.warning(f"No analysis found for **{student_choice}** in `{ANALYSES_DIR}` yet.")
|
| 630 |
+
# if idx:
|
| 631 |
+
# st.caption("Available analyses:")
|
| 632 |
+
# st.write(", ".join(sorted({name.title() for name in idx.keys()})))
|
| 633 |
|
| 634 |
|
| 635 |
|