-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport.py
More file actions
67 lines (58 loc) · 2.36 KB
/
Copy pathreport.py
File metadata and controls
67 lines (58 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Exportable session report (Markdown).
Pulls the current session's attempts back out of the SQLite store
(``memory.store``) so the report reflects exactly what was persisted, and
adds the cross-session weak-topic picture alongside it. Meant to be handed
to ``st.download_button`` from ``app.py``.
"""
from __future__ import annotations
from datetime import datetime
from pathlib import Path
from memory import store
def build_session_report(session_id: str, db_path: str | Path | None = None) -> str:
attempts = store.get_session_attempts(session_id, db_path=db_path)
cumulative = store.get_cumulative_stats(db_path=db_path)
total = len(attempts)
correct = sum(1 for a in attempts if a["is_correct"])
weak_this_session = sorted({a["topic"] for a in attempts if not a["is_correct"]})
weakest_overall = cumulative["weakest_topics"]
lines = [
"# Java Interview Coach — Session Report",
"",
f"_Generated {datetime.now().strftime('%Y-%m-%d %H:%M')}_",
"",
"## This Session",
f"- Questions answered: **{total}**",
f"- Correct: **{correct}/{total}**",
"- Topics to review: "
+ (", ".join(weak_this_session) if weak_this_session else "None — nice work!"),
"",
"## All-Time Progress",
f"- Total questions answered across all sessions: **{cumulative['total_questions']}**",
f"- Total correct across all sessions: **{cumulative['total_correct']}**",
f"- Total practice sessions: **{cumulative['total_sessions']}**",
"- Weakest topics overall: "
+ (", ".join(weakest_overall) if weakest_overall else "Not enough data yet"),
"",
"## Question-by-Question",
"",
]
if not attempts:
lines.append("_No questions were answered this session._")
else:
for i, a in enumerate(attempts, start=1):
verdict = "CORRECT" if a["is_correct"] else "INCORRECT"
lines += [
f"### {i}. [{a['topic']}] — {verdict}",
"",
f"**Question:** {a['question']}",
"",
f"**Your answer:** {a['answer']}",
"",
"**Feedback / ideal answer:**",
"",
f"{a['feedback']}",
"",
"---",
"",
]
return "\n".join(lines)