Commit 5de9ad2
feat(teacher): course analytics page + confusion-hotspots widget (#579)
* feat(teacher): course analytics page + confusion-hotspots widget
Teachers had no way to see how an exercise performs across students. The
data existed — `lms_get_confusion_hotspots` already fused practice, exercise
and exam-question outcomes with Elo `item_ratings` — but it was reachable
only from an MCP client, had no widget, and nothing in the web app read it.
Adds both surfaces, and closes the gap that actually answers "is this too
hard?": `exercises.difficulty_level` (the teacher's own easy/medium/hard
label) was never compared against the rating the platform measured from real
attempts. Both surfaces now show the label beside the measured rating and
flag the divergence.
Web
- /dashboard/teacher/courses/[id]/analytics — server-rendered, 7/30/90-day
window via plain links (no client JS), linked from the course header.
- lib/analytics/confusion-hotspots.ts fuses four signals: practice drills,
exercise evaluations, lesson checkpoints and exam-question miss rates.
`lesson_checkpoint_attempts` was never read by any teacher surface
despite shipping a purpose-built `..._teacher_metrics_idx`.
- Sweeps use `fetchAllRows`, so a course busy enough to hit PostgREST's
1000-row cap cannot silently under-report. A signal that fails to load
becomes a named warning in the UI rather than an empty list that looks
like "nobody is struggling".
- Ownership-gated to the course author; every read runs under the teacher's
own RLS policies, no admin client.
MCP
- resources/confusion-hotspots/widget.tsx, wired to the existing tool.
- hardest_items now carries difficulty_level + mismatch.
- Hotspot scope "lesson" renamed to "practice": those rows are drill
topics, which may not map to a lesson at all.
- Demo fixtures (default / all-clear / empty) for no-DB previews.
Typing the Supabase client (rather than `SupabaseClient<any>`) caught two
real defects in the hand-written row shapes: `checkpoint_id` is a number,
and `submission_date` is nullable and so cannot be compared bare when
picking a student's latest retake.
Verified: Next build + typecheck + lint clean; mcp-server build (19 widgets)
and type check pass; widget rendered headlessly in all three fixture states;
page rendered live against seeded local data as creator@codeacademy.com and
the seed rows removed afterwards.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VqQTE7LDYPx7d15BcWLGfC
* test(analytics): cover the confusion-hotspots paths QA could not reach
The manual pass could only exercise practice and exercise hotspots with a
single student, because every source table was empty locally. Exam
questions, lesson checkpoints, the fetchAllRows paging loop and the warning
path all shipped unverified. 23 tests close that.
Each test was mutation-checked — the suite was re-run against a deliberately
broken copy of the logic to prove the assertions can fail:
- first-attempt-wins instead of latest-attempt → caught
- miss threshold moved from 70% to 50% → caught
- `easy` given a floor (so it could read easier) → caught
- oldest retake wins instead of newest → caught
That last mutation initially SURVIVED, which exposed a genuinely misleading
test: a NULL `submission_date` never passes the `.gte(cutoff)` window filter
(NULL comparisons are never true), so such a row cannot reach the retake
logic at all. The test claiming to prove null-handling was passing for the
wrong reason. Split into an honest pair: one that exercises retake selection
with two dated submissions, and one that pins the real upstream behaviour.
fake-supabase gains `range()` (needed by fetchAllRows) and a real `order()`.
`count` now reports the FULL match count rather than the post-limit count,
matching PostgREST — a per-page count would make a truncated sweep look
complete, defeating the assertion fetchAllRows exists to make. All 611
pre-existing tests still pass.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VqQTE7LDYPx7d15BcWLGfC
* fix(analytics): translate the hotspot detail lines on /es
The analytics page shipped its per-hotspot "why" line as a prebuilt English
sentence built inside lib/analytics/confusion-hotspots.ts, so on /es every
heading, badge and footer translated while the line carrying the actual
finding stayed in English:
4 of 5 student(s) still failing on their latest attempt · average 52%
3 of 5 student(s) missed it on their latest submission · 60% miss rate
Caught by rendering the page under /es for the QA screenshots, not by a test —
the strings were correct, just not translatable.
Hotspot now carries numbers only (`totalAttempts` replaces `evidence`) and the
page formats them through next-intl. Each signal counts something different, so
each scope gets its own message rather than one generic sentence that would
read wrong for three scopes out of four.
The MCP tool keeps its English `evidence` string on purpose: its reader is a
model, not a localised UI. Noted in the twin-implementation header.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VqQTE7LDYPx7d15BcWLGfC
* docs(screenshots): #579 teacher analytics + hotspots widget QA evidence
Page rendered against seeded data in the local Code Academy tenant with all
four signals populated (practice, exercise, checkpoint, exam question) and both
label-vs-Elo mismatch directions present. 7d/30d/90d differ because the seed
spreads attempts across three time bands, so the window switcher is shown doing
real work rather than re-rendering the same list.
Widget shots cover the three demo fixtures: default, all-clear, empty.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VqQTE7LDYPx7d15BcWLGfC
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 35ef2b8 commit 5de9ad2
18 files changed
Lines changed: 2244 additions & 34 deletions
File tree
- app/[locale]/dashboard/teacher/courses/[courseId]
- analytics
- components/teacher
- docs/screenshots
- lib/analytics
- mcp-server
- resources/confusion-hotspots
- src
- tools
- messages
- tests/unit
- support
Lines changed: 326 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
222 | 223 | | |
223 | 224 | | |
224 | 225 | | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
225 | 232 | | |
226 | 233 | | |
227 | 234 | | |
| |||
0 commit comments