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 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 | /** * Console Reporter * * Formats journey simulation results for console output. * Designed for vitest test output visibility. */ import type { ComparisonResult, JourneyResult } from '../types' /** * Format a journey result for console output. */ export function formatJourneyResults(result: JourneyResult): string { const lines: string[] = [] lines.push('') lines.push('═══════════════════════════════════════════════════════════') lines.push(' JOURNEY SIMULATION RESULTS ') lines.push('═══════════════════════════════════════════════════════════') lines.push('') // Configuration lines.push(`Profile: ${result.config.profile.name}`) lines.push(`Mode: ${result.config.mode}`) lines.push(`Sessions: ${result.config.sessionCount}`) lines.push(`Duration: ${result.config.sessionDurationMinutes} min/session`) lines.push(`Seed: ${result.config.seed}`) lines.push(`Skills: ${result.config.practicingSkills.length}`) lines.push(`Runtime: ${result.runtimeMs}ms`) lines.push('') // Final Metrics lines.push('───────────────────────────────────────────────────────────') lines.push(' FINAL METRICS ') lines.push('───────────────────────────────────────────────────────────') lines.push('') lines.push(`BKT Correlation: ${formatPercent(result.finalMetrics.bktCorrelation, true)}`) lines.push( `Weak Skill Surfacing: ${result.finalMetrics.weakSkillSurfacing.toFixed(2)}x baseline` ) lines.push(`Accuracy Improvement: ${formatDelta(result.finalMetrics.accuracyImprovement)}`) lines.push('') // Per-Session Progress lines.push('───────────────────────────────────────────────────────────') lines.push(' PER-SESSION PROGRESS ') lines.push('───────────────────────────────────────────────────────────') lines.push('') lines.push('Session Accuracy Problems BKT Correlation') lines.push('------- -------- -------- ---------------') for (const snapshot of result.snapshots) { // Calculate BKT correlation for this snapshot const bktCorr = calculateSnapshotCorrelation(snapshot, result.config.practicingSkills) lines.push( ` ${String(snapshot.sessionNumber).padStart(2)} ${formatPercent(snapshot.accuracy).padStart(6)} ${String(snapshot.problemsAttempted).padStart(6)} ${formatPercent(bktCorr, true).padStart(6)}` ) } lines.push('') // Skill Trajectories (top weak and strong) lines.push('───────────────────────────────────────────────────────────') lines.push(' SKILL HIGHLIGHTS ') lines.push('───────────────────────────────────────────────────────────') lines.push('') const lastSnapshot = result.snapshots[result.snapshots.length - 1] // Find weakest and strongest skills by true probability (Hill function) const skillsByProbability = [...lastSnapshot.trueSkillProbabilities.entries()].sort( (a, b) => a[1] - b[1] ) const weakest = skillsByProbability.slice(0, 3) const strongest = skillsByProbability.slice(-3).reverse() lines.push('Weakest Skills (True Probability):') for (const [skillId, probability] of weakest) { const bkt = lastSnapshot.bktEstimates.get(skillId)?.pKnown ?? 0 const exposure = lastSnapshot.cumulativeExposures.get(skillId) ?? 0 lines.push( ` ${skillId.padEnd(30)} True: ${formatPercent(probability)} BKT: ${formatPercent(bkt)} Exp: ${exposure}` ) } lines.push('') lines.push('Strongest Skills (True Probability):') for (const [skillId, probability] of strongest) { const bkt = lastSnapshot.bktEstimates.get(skillId)?.pKnown ?? 0 const exposure = lastSnapshot.cumulativeExposures.get(skillId) ?? 0 lines.push( ` ${skillId.padEnd(30)} True: ${formatPercent(probability)} BKT: ${formatPercent(bkt)} Exp: ${exposure}` ) } lines.push('') lines.push('═══════════════════════════════════════════════════════════') return lines.join('\n') } /** * Format a comparison between adaptive and classic modes. */ export function formatComparisonResults(comparison: ComparisonResult): string { const lines: string[] = [] lines.push('') lines.push('═══════════════════════════════════════════════════════════') lines.push(' A/B COMPARISON: ADAPTIVE vs CLASSIC ') lines.push('═══════════════════════════════════════════════════════════') lines.push('') const adaptive = comparison.adaptiveResult const classic = comparison.classicResult lines.push(`Profile: ${adaptive.config.profile.name}`) lines.push(`Sessions: ${adaptive.config.sessionCount}`) lines.push(`Seed: ${adaptive.config.seed}`) lines.push('') lines.push('───────────────────────────────────────────────────────────') lines.push(' METRIC COMPARISON ') lines.push('───────────────────────────────────────────────────────────') lines.push('') lines.push('Metric Adaptive Classic Delta') lines.push('------------------------- ---------- ---------- ----------') lines.push( `BKT Correlation ${formatPercent(adaptive.finalMetrics.bktCorrelation, true).padStart(10)} ${formatPercent(classic.finalMetrics.bktCorrelation, true).padStart(10)} ${formatDelta(comparison.correlationDelta, true).padStart(10)}` ) lines.push( `Weak Skill Surfacing ${(adaptive.finalMetrics.weakSkillSurfacing.toFixed(2) + 'x').padStart(10)} ${(classic.finalMetrics.weakSkillSurfacing.toFixed(2) + 'x').padStart(10)} ${formatDelta(comparison.weakSkillSurfacingDelta).padStart(10)}` ) lines.push( `Accuracy Improvement ${formatPercent(adaptive.finalMetrics.accuracyImprovement).padStart(10)} ${formatPercent(classic.finalMetrics.accuracyImprovement).padStart(10)} ${formatDelta(comparison.accuracyImprovementDelta).padStart(10)}` ) lines.push('') // Winner determination lines.push('───────────────────────────────────────────────────────────') lines.push(' WINNER ') lines.push('───────────────────────────────────────────────────────────') lines.push('') let adaptiveWins = 0 let classicWins = 0 if (comparison.correlationDelta > 0.05) { adaptiveWins++ lines.push( ' BKT Correlation: ADAPTIVE (+' + formatPercent(comparison.correlationDelta) + ')' ) } else if (comparison.correlationDelta < -0.05) { classicWins++ lines.push( ' BKT Correlation: CLASSIC (' + formatPercent(comparison.correlationDelta) + ')' ) } else { lines.push(' BKT Correlation: TIE') } if (comparison.weakSkillSurfacingDelta > 0.1) { adaptiveWins++ lines.push( ' Weak Skill Surfacing: ADAPTIVE (+' + comparison.weakSkillSurfacingDelta.toFixed(2) + 'x)' ) } else if (comparison.weakSkillSurfacingDelta < -0.1) { classicWins++ lines.push( ' Weak Skill Surfacing: CLASSIC (' + comparison.weakSkillSurfacingDelta.toFixed(2) + 'x)' ) } else { lines.push(' Weak Skill Surfacing: TIE') } if (comparison.accuracyImprovementDelta > 0.02) { adaptiveWins++ lines.push( ' Accuracy Improvement: ADAPTIVE (+' + formatPercent(comparison.accuracyImprovementDelta) + ')' ) } else if (comparison.accuracyImprovementDelta < -0.02) { classicWins++ lines.push( ' Accuracy Improvement: CLASSIC (' + formatPercent(comparison.accuracyImprovementDelta) + ')' ) } else { lines.push(' Accuracy Improvement: TIE') } lines.push('') if (adaptiveWins > classicWins) { lines.push(` Overall: ADAPTIVE WINS (${adaptiveWins}-${classicWins})`) } else if (classicWins > adaptiveWins) { lines.push(` Overall: CLASSIC WINS (${classicWins}-${adaptiveWins})`) } else { lines.push(` Overall: TIE (${adaptiveWins}-${classicWins})`) } lines.push('') lines.push('═══════════════════════════════════════════════════════════') return lines.join('\n') } /** * Log journey results to console. */ export function logJourneyResults(result: JourneyResult): void { console.log(formatJourneyResults(result)) } /** * Log comparison results to console. */ export function logComparisonResults(comparison: ComparisonResult): void { console.log(formatComparisonResults(comparison)) } // Helper functions function formatPercent(value: number, signed = false): string { const percent = (value * 100).toFixed(1) if (signed && value > 0) { return `+${percent}%` } return `${percent}%` } function formatDelta(value: number, asPercent = false): string { if (asPercent) { const percent = (value * 100).toFixed(1) return value >= 0 ? `+${percent}%` : `${percent}%` } const formatted = value.toFixed(2) return value >= 0 ? `+${formatted}` : formatted } function calculateSnapshotCorrelation( snapshot: { trueSkillProbabilities: Map<string, number> bktEstimates: Map<string, { pKnown: number }> }, skillIds: string[] ): number { const pairs: Array<[number, number]> = [] for (const skillId of skillIds) { const trueProbability = snapshot.trueSkillProbabilities.get(skillId) ?? 0 const bktEstimate = snapshot.bktEstimates.get(skillId)?.pKnown ?? 0.5 pairs.push([trueProbability, bktEstimate]) } if (pairs.length < 2) return 0 const n = pairs.length const sumX = pairs.reduce((s, [x]) => s + x, 0) const sumY = pairs.reduce((s, [, y]) => s + y, 0) const sumXY = pairs.reduce((s, [x, y]) => s + x * y, 0) const sumX2 = pairs.reduce((s, [x]) => s + x * x, 0) const sumY2 = pairs.reduce((s, [, y]) => s + y * y, 0) const numerator = n * sumXY - sumX * sumY const denominator = Math.sqrt((n * sumX2 - sumX ** 2) * (n * sumY2 - sumY ** 2)) return denominator === 0 ? 0 : numerator / denominator } |