Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | /** * Session Summary Utilities * * Utilities for filtering and organizing session results for display. */ import type { ProblemSlot, SessionPart, SessionPlan, SlotResult } from '@/db/schema/session-plans' // ============================================================================ // Types // ============================================================================ /** * A problem result with its associated slot and part information */ export interface ProblemWithContext { /** The result data (if completed) */ result: SlotResult /** The problem slot */ slot: ProblemSlot /** The session part this problem belongs to */ part: SessionPart /** Global problem number (1-based, across all parts) */ problemNumber: number } /** * Reason why a problem needs attention */ export type AttentionReason = 'incorrect' | 'slow' | 'help-used' /** * A problem that needs the student's attention */ export interface ProblemNeedingAttention extends ProblemWithContext { /** Why this problem needs attention */ reasons: AttentionReason[] } // ============================================================================ // Functions // ============================================================================ /** * Build a list of all completed problems with their context. */ export function getProblemsWithContext(plan: SessionPlan): ProblemWithContext[] { const results = plan.results as SlotResult[] const resultMap = new Map<string, SlotResult>() // Build a map for quick lookup for (const result of results) { const key = `${result.partNumber}-${result.slotIndex}` resultMap.set(key, result) } const problems: ProblemWithContext[] = [] let globalNumber = 0 for (const part of plan.parts) { for (const slot of part.slots) { globalNumber++ const key = `${part.partNumber}-${slot.index}` const result = resultMap.get(key) if (result) { problems.push({ result, slot, part, problemNumber: globalNumber, }) } } } return problems } /** * Filter problems that need the student's attention. * * Criteria: * - Incorrect answer * - Slow response (would have triggered auto-pause threshold) * - Used significant help (level 3+) */ export function filterProblemsNeedingAttention( problems: ProblemWithContext[], autoPauseThresholdMs: number ): ProblemNeedingAttention[] { const needsAttention: ProblemNeedingAttention[] = [] for (const problem of problems) { const reasons: AttentionReason[] = [] // Check if incorrect if (!problem.result.isCorrect) { reasons.push('incorrect') } // Check if slow (would have triggered auto-pause) if (problem.result.responseTimeMs > autoPauseThresholdMs) { reasons.push('slow') } // Check if used help if (problem.result.hadHelp) { reasons.push('help-used') } // Only include if there's at least one reason if (reasons.length > 0) { needsAttention.push({ ...problem, reasons, }) } } // Sort by severity: incorrect first, then by multiple reasons return needsAttention.sort((a, b) => { // Incorrect problems always first const aIncorrect = a.reasons.includes('incorrect') ? 0 : 1 const bIncorrect = b.reasons.includes('incorrect') ? 0 : 1 if (aIncorrect !== bIncorrect) return aIncorrect - bIncorrect // Then by number of reasons (more = more attention needed) if (b.reasons.length !== a.reasons.length) { return b.reasons.length - a.reasons.length } // Finally by problem number return a.problemNumber - b.problemNumber }) } /** * Group problems by part for display. */ export function groupProblemsByPart( problems: ProblemWithContext[] ): Map<SessionPart, ProblemWithContext[]> { const grouped = new Map<SessionPart, ProblemWithContext[]>() for (const problem of problems) { const existing = grouped.get(problem.part) ?? [] existing.push(problem) grouped.set(problem.part, existing) } return grouped } /** * Check if a problem is from a vertical part (abacus/visualization) */ export function isVerticalPart(type: SessionPart['type']): boolean { return type === 'abacus' || type === 'visualization' } /** * Get a human-readable label for part type */ export function getPartTypeLabel(type: SessionPart['type']): string { switch (type) { case 'abacus': return 'Abacus' case 'visualization': return 'Visualize' case 'linear': return 'Mental Math' default: return type } } /** * Format a problem as a simple equation string */ export function formatProblemAsEquation(terms: number[], answer: number): string { const parts = terms.map((term, i) => { if (i === 0) return String(term) return term < 0 ? ` − ${Math.abs(term)}` : ` + ${term}` }) return `${parts.join('')} = ${answer}` } |