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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 2x 95x 95x 95x 95x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 1x 1x 1x 1x 1x 1x 1x 96x 97x 97x 97x 97x 97x 3x 3x 94x 94x 94x 94x 94x 94x 12x 12x 1x 1x 1x 1x 1x 13x 13x 13x 13x 2x 2x 11x 11x 11x 11x 13x 2x 2x 13x 1x 1x 13x 1x 1x 13x 1x 1x 13x 1x 1x 13x 2x 2x 11x 11x 11x 1x 1x 1x 1x 1x 12x 12x 12x 12x 3x 3x 9x 9x 25x 25x 25x 28x 17x 14x 14x 17x 4x 4x 17x 28x 25x 25x 9x 9x | import type { GeneratedProblem, SlotResult } from '../../db/schema/session-plans'
import { MAX_RESPONSE_TIME_CAP_MS } from '../curriculum/timing/constants'
import type { SkillConfig, SuccessCriteria, TuningAdjustment } from './types'
import { generateRealisticProblems } from './problem-generation'
import { designSequenceForClassification } from './bkt-simulation'
/**
* Generate slot results for a skill config (problem history with correct/incorrect sequences)
*/
export function generateSlotResults(
config: SkillConfig,
startIndex: number,
sessionStartTime: Date
): SlotResult[] {
// Generate realistic problems targeting the skill
const realisticProblems = generateRealisticProblems(config.skillId, config.problems)
// Design a sequence that will reliably produce the target BKT classification
const correctnessSequence = designSequenceForClassification(
config.skillId,
config.problems,
config.targetClassification
)
// Index the timing anomalies for O(1) lookup while mapping attempts.
const anomalyByIndex = new Map(
(config.timingAnomalies ?? []).map((anomaly) => [anomaly.atIndex, anomaly])
)
return realisticProblems.map((realistic, i) => {
const isCorrect = correctnessSequence[i]
// Convert to the schema's GeneratedProblem format
const problem: GeneratedProblem = {
terms: realistic.terms,
answer: realistic.answer,
skillsRequired: realistic.skillsUsed,
generationTrace: realistic.generationTrace,
}
// Generate a plausible wrong answer if incorrect
const wrongAnswer =
realistic.answer + (Math.random() > 0.5 ? 1 : -1) * (Math.floor(Math.random() * 3) + 1)
// A timing anomaly (if any) overrides the generated response time and,
// when idle-capped, layers in the #156 capture-guard fields.
const anomaly = anomalyByIndex.get(i)
const responseTimeMs = anomaly
? anomaly.responseTimeMs
: (() => {
const range = config.responseTimeMsRange ?? { min: 4000, max: 6000 }
return range.min + Math.random() * (range.max - range.min)
})()
const baseResult = {
slotId: crypto.randomUUID(),
partNumber: 1 as const,
slotIndex: startIndex + i,
problem,
studentAnswer: isCorrect ? realistic.answer : wrongAnswer,
isCorrect,
responseTimeMs,
skillsExercised: realistic.skillsUsed, // ALL skills used, not just target
usedOnScreenAbacus: false,
timestamp: new Date(sessionStartTime.getTime() + (startIndex + i) * 10000),
incorrectAttempts: isCorrect ? 0 : 1,
// Only present for idle-capped anomalies; a bare huge responseTimeMs with
// no guard flags is exactly the "legacy poison" shape the classifier keys on.
...(anomaly?.idleCapped
? {
wasIdleCapped: true,
responseTimeMsRaw: anomaly.idleCapped.rawResponseTimeMs,
capReason: anomaly.idleCapped.capReason ?? 'idle-exceeded',
capThresholdMs: anomaly.idleCapped.capThresholdMs ?? MAX_RESPONSE_TIME_CAP_MS,
capSource: anomaly.idleCapped.capSource ?? 'client',
}
: {}),
}
// If simulating legacy data, omit hadHelp and helpTrigger
// This tests the NaN handling code path for old data missing these fields
if (config.simulateLegacyData) {
return baseResult as SlotResult
}
return {
...baseResult,
hadHelp: false,
helpTrigger: 'none' as const,
}
})
}
/**
* Check if a profile's outcomes meet its success criteria
*/
export function checkSuccessCriteria(
classifications: Record<string, number>,
criteria?: SuccessCriteria
): { success: boolean; reasons: string[] } {
if (!criteria) {
return { success: true, reasons: [] }
}
const reasons: string[] = []
const { weak, developing, strong } = classifications
if (criteria.minWeak !== undefined && weak < criteria.minWeak) {
reasons.push(`Need at least ${criteria.minWeak} weak skills, got ${weak}`)
}
if (criteria.maxWeak !== undefined && weak > criteria.maxWeak) {
reasons.push(`Need at most ${criteria.maxWeak} weak skills, got ${weak}`)
}
if (criteria.minDeveloping !== undefined && developing < criteria.minDeveloping) {
reasons.push(`Need at least ${criteria.minDeveloping} developing skills, got ${developing}`)
}
if (criteria.maxDeveloping !== undefined && developing > criteria.maxDeveloping) {
reasons.push(`Need at most ${criteria.maxDeveloping} developing skills, got ${developing}`)
}
if (criteria.minStrong !== undefined && strong < criteria.minStrong) {
reasons.push(`Need at least ${criteria.minStrong} strong skills, got ${strong}`)
}
if (criteria.maxStrong !== undefined && strong > criteria.maxStrong) {
reasons.push(`Need at most ${criteria.maxStrong} strong skills, got ${strong}`)
}
return { success: reasons.length === 0, reasons }
}
/**
* Apply tuning adjustments to skill history
*/
export function applyTuningAdjustments(
skillHistory: SkillConfig[],
adjustments?: TuningAdjustment[]
): SkillConfig[] {
if (!adjustments || adjustments.length === 0) {
return skillHistory
}
return skillHistory.map((config) => {
const newConfig = { ...config }
for (const adj of adjustments) {
if (adj.skillId === 'all' || adj.skillId === config.skillId) {
if (adj.problemsAdd !== undefined) {
newConfig.problems = newConfig.problems + adj.problemsAdd
}
if (adj.problemsMultiplier !== undefined) {
newConfig.problems = Math.round(newConfig.problems * adj.problemsMultiplier)
}
}
}
return newConfig
})
}
|