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 | 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 16x 16x 16x 16x 16x 16x 509x 16x 16x 2x 2x 2x 2x 16x 16x 15x 15x 16x 16x 2x 2x 2x 2x 16x 16x 16x 16x 2x 2x 2x 2x 2x 16x 16x 16x 16x 16x 16x 16x 13x 16x 16x 16x 16x 2x 16x 16x 16x 16x 16x 16x 16x 13x 16x 16x 16x 16x 2x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 15x 16x 16x 16x 2x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 13x 16x 16x 16x 16x 16x 16x 16x 16x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 2x 2x 2x 2x 2x 2x 2x 3x 3x 3x 3x 3x 3x 3x 3x 5x 5x 3x 3x 3x 2x 2x 2x 2x 2x 6x 6x 6x 6x | /**
* Skill Readiness Assessment
*
* Pure functions to evaluate whether a student is truly ready to advance
* past a skill, using four equal dimensions:
*
* 1. Mastery: BKT P(known) + confidence
* 2. Volume: Practice depth (problems + sessions)
* 3. Speed: Automaticity / muscle memory
* 4. Consistency: Reliable execution (accuracy + no-help streak)
*
* All readiness criteria are computed from existing SlotResult fields
* (responseTimeMs, isCorrect, hadHelp, skillsExercised, problem.terms).
* No new metrics are tracked — just smarter analysis of what's already there.
*/
import type { SkillBktResult } from '@/lib/curriculum/bkt/types'
import type { ProblemResultWithContext } from '@/lib/curriculum/session-planner'
import { READINESS_THRESHOLDS } from '@/lib/curriculum/config/readiness-thresholds'
// =============================================================================
// Types
// =============================================================================
export interface MasteryDimension {
met: boolean
pKnown: number
confidence: number
}
export interface VolumeDimension {
met: boolean
opportunities: number
sessionCount: number
}
export interface SpeedDimension {
met: boolean
/** Median seconds per term, or null if no data */
medianSecondsPerTerm: number | null
}
export interface ConsistencyDimension {
met: boolean
recentAccuracy: number
lastFiveAllCorrect: boolean
recentHelpCount: number
}
export interface SkillReadinessDimensions {
mastery: MasteryDimension
volume: VolumeDimension
speed: SpeedDimension
consistency: ConsistencyDimension
}
export interface SkillReadinessResult {
skillId: string
/** True when all four dimensions are met */
isSolid: boolean
dimensions: SkillReadinessDimensions
}
// =============================================================================
// Helpers
// =============================================================================
/**
* Filter results to those relevant for a skill's readiness assessment.
* Excludes retries and sentinel records (recency-refresh).
*/
function filterResultsForSkill(
allResults: ProblemResultWithContext[],
skillId: string
): ProblemResultWithContext[] {
return allResults.filter(
(r) =>
r.skillsExercised.includes(skillId) && r.source !== 'recency-refresh' && r.isRetry !== true
)
}
/**
* Compute median of a numeric array.
*/
function median(values: number[]): number | null {
if (values.length === 0) return null
const sorted = [...values].sort((a, b) => a - b)
const mid = Math.floor(sorted.length / 2)
return sorted.length % 2 !== 0 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2
}
/**
* Count distinct sessions in a set of results.
*/
function countDistinctSessions(results: ProblemResultWithContext[]): number {
const sessionIds = new Set(results.map((r) => r.sessionId))
return sessionIds.size
}
// =============================================================================
// Dimension Assessment
// =============================================================================
function assessMastery(bktResult: SkillBktResult | undefined): MasteryDimension {
const pKnown = bktResult?.pKnown ?? 0
const confidence = bktResult?.confidence ?? 0
return {
met:
pKnown >= READINESS_THRESHOLDS.pKnownThreshold &&
confidence >= READINESS_THRESHOLDS.confidenceThreshold,
pKnown,
confidence,
}
}
function assessVolume(results: ProblemResultWithContext[]): VolumeDimension {
const opportunities = results.length
const sessionCount = countDistinctSessions(results)
return {
met:
opportunities >= READINESS_THRESHOLDS.minOpportunities &&
sessionCount >= READINESS_THRESHOLDS.minSessions,
opportunities,
sessionCount,
}
}
function assessSpeed(results: ProblemResultWithContext[]): SpeedDimension {
// Sort by timestamp descending, take the most recent N
const sorted = [...results].sort(
(a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime()
)
const recent = sorted.slice(0, READINESS_THRESHOLDS.speedWindowSize)
// Compute seconds per term for each problem
const secondsPerTerm = recent
.filter((r) => r.problem.terms.length > 0)
.map((r) => r.responseTimeMs / (r.problem.terms.length * 1000))
const medianSecondsPerTerm = median(secondsPerTerm)
return {
met:
medianSecondsPerTerm !== null &&
medianSecondsPerTerm <= READINESS_THRESHOLDS.maxMedianSecondsPerTerm,
medianSecondsPerTerm,
}
}
function assessConsistency(results: ProblemResultWithContext[]): ConsistencyDimension {
// Sort by timestamp descending for recency-based checks
const sorted = [...results].sort(
(a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime()
)
// Recent accuracy over the window
const recentWindow = sorted.slice(0, READINESS_THRESHOLDS.accuracyWindowSize)
const recentCorrect = recentWindow.filter((r) => r.isCorrect).length
const recentAccuracy = recentWindow.length > 0 ? recentCorrect / recentWindow.length : 0
// Last N all correct
const lastN = sorted.slice(0, READINESS_THRESHOLDS.lastNAllCorrect)
const lastFiveAllCorrect =
lastN.length >= READINESS_THRESHOLDS.lastNAllCorrect && lastN.every((r) => r.isCorrect)
// Help-free in last N
const helpWindow = sorted.slice(0, READINESS_THRESHOLDS.noHelpInLastN)
const recentHelpCount = helpWindow.filter((r) => r.hadHelp).length
const helpFree = helpWindow.length >= READINESS_THRESHOLDS.noHelpInLastN && recentHelpCount === 0
const accuracyMet =
recentWindow.length >= READINESS_THRESHOLDS.accuracyWindowSize &&
recentAccuracy >= READINESS_THRESHOLDS.minAccuracy
return {
met: accuracyMet && lastFiveAllCorrect && helpFree,
recentAccuracy,
lastFiveAllCorrect,
recentHelpCount,
}
}
// =============================================================================
// Public API
// =============================================================================
/**
* Assess readiness for a single skill.
*
* Takes the full problem history (already loaded by getSessionMode) plus
* BKT result for the skill. Returns per-dimension pass/fail with detail values.
*/
export function assessSkillReadiness(
skillId: string,
allResults: ProblemResultWithContext[],
bktResult: SkillBktResult | undefined
): SkillReadinessResult {
const filtered = filterResultsForSkill(allResults, skillId)
const mastery = assessMastery(bktResult)
const volume = assessVolume(filtered)
const speed = assessSpeed(filtered)
const consistency = assessConsistency(filtered)
// A skill with 0 opportunities doesn't block (student hasn't encountered it yet)
const isSolid =
filtered.length === 0 || (mastery.met && volume.met && speed.met && consistency.met)
return {
skillId,
isSolid,
dimensions: { mastery, volume, speed, consistency },
}
}
/**
* Assess readiness for all currently practicing skills.
*
* Returns a Map of skillId → SkillReadinessResult.
*/
export function assessAllSkillsReadiness(
allResults: ProblemResultWithContext[],
bktResults: SkillBktResult[],
practicingIds: Set<string>
): Map<string, SkillReadinessResult> {
const bktMap = new Map(bktResults.map((r) => [r.skillId, r]))
const readiness = new Map<string, SkillReadinessResult>()
for (const skillId of practicingIds) {
readiness.set(skillId, assessSkillReadiness(skillId, allResults, bktMap.get(skillId)))
}
return readiness
}
/**
* Convert a readiness map to a plain object (for JSON serialization).
*/
export function readinessMapToRecord(
map: Map<string, SkillReadinessResult>
): Record<string, SkillReadinessResult> {
return Object.fromEntries(map.entries())
}
|