@vue-skuilder/db 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{contentSource-CSI0pJ2D.d.ts → contentSource-CPM872yn.d.ts} +2 -1
- package/dist/core/index.cjs +163 -49
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.ts +3 -3
- package/dist/core/navigators/filters/eloDistance.mjs.map +1 -1
- package/dist/core/navigators/filters/skillPressure.mjs +109 -0
- package/dist/core/navigators/filters/skillPressure.mjs.map +1 -0
- package/dist/core/navigators/generators/prescribed.mjs.map +1 -1
- package/dist/core/navigators/index.mjs +7 -3
- package/dist/core/navigators/index.mjs.map +1 -1
- package/dist/core/versionStamps.mjs +1 -1
- package/dist/{dataLayerProvider-D5n1gGc_.d.ts → dataLayerProvider-CaNgzRCz.d.ts} +1 -1
- package/dist/diagnostics/derive.mjs.map +1 -1
- package/dist/diagnostics/index.cjs +16 -3
- package/dist/diagnostics/index.cjs.map +1 -1
- package/dist/diagnostics/index.d.ts +29 -6
- package/dist/diagnostics/tagElo.mjs +20 -4
- package/dist/diagnostics/tagElo.mjs.map +1 -1
- package/dist/impl/couch/index.cjs +2 -1
- package/dist/impl/couch/index.cjs.map +1 -1
- package/dist/impl/couch/index.d.ts +2 -2
- package/dist/impl/static/index.cjs +2 -1
- package/dist/impl/static/index.cjs.map +1 -1
- package/dist/impl/static/index.d.ts +2 -2
- package/dist/index.cjs +211 -91
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/study/services/tagRecent.mjs +2 -1
- package/dist/study/services/tagRecent.mjs.map +1 -1
- package/package.json +3 -3
- package/src/core/navigators/filters/eloDistance.ts +2 -2
- package/src/core/navigators/filters/index.ts +3 -0
- package/src/core/navigators/filters/skillPressure.ts +194 -0
- package/src/core/navigators/generators/prescribed.ts +5 -6
- package/src/core/navigators/index.ts +5 -0
- package/src/diagnostics/derive.ts +6 -1
- package/src/diagnostics/tagElo.ts +43 -3
- package/src/study/services/tagRecent.test.ts +57 -3
- package/src/study/services/tagRecent.ts +8 -1
- package/tests/core/navigators/skillPressureFilter.test.ts +84 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { A as AdminDBInterface, d as AssignedCard, a as AssignedContent, c as AssignedCourse, b as AssignedTag, C as ClassroomDBInterface, S as StudentClassroomDBInterface, T as TeacherClassroomDBInterface } from './classroomDB-DLTtLZct.js';
|
|
2
|
-
import { U as UserDBInterface, g as CourseRegistrationDoc, m as SessionEloEvent, S as StudySessionItem, W as WeightedCard, R as ReplanHints, o as StudyContentSource, x as SessionStateSnapshotProvider, G as GeneratorResult, N as NavigatorRole, c as ContentNavigationStrategyData, F as FilterKind, y as RegulatorConfig, C as CourseDBInterface } from './contentSource-
|
|
3
|
-
export { P as ActivityRecord, ae as CardFilter, ag as CardFilterFactory, ah as CardGenerator, aj as CardGeneratorFactory, K as ClassroomRegistration, J as ClassroomRegistrationDesignation, L as ClassroomRegistrationDoc, d as ContentNavigator, v as ContentSourceID, b as CourseInfo, Q as CourseRegistration, a as CoursesDBInterface, aB as DEFAULT_REGULATOR_CONFIG, aM as DocumentUpdater, af as FilterContext, at as FilterImpact, ai as GeneratorContext, as as GeneratorSummary, _ as HYDRATION_MARKER_ID, $ as HydrationMarker, aF as INTAKE_CLOCK_KEY, aE as IntakeClockState, av as LearnableWeight, a0 as NavigatorConstructor, ab as NavigatorRoles, aa as Navigators, aw as OrchestrationContext, au as PipelineForecaster, aq as PipelineRunReport, l as RegulatorName, j as RegulatorReading, ar as RunReportCard, f as ScheduledCard, h as SessionStateSnapshot, M as SessionTrackingData, a8 as StrategyContribution, e as StudySessionDoc, p as StudySessionFailedItem, q as StudySessionFailedNewItem, r as StudySessionFailedReviewItem, s as StudySessionNewItem, t as StudySessionReviewItem, k as StudySessionRunCard, n as StudySessionRunCardTrail, i as StudySessionRunSummary, O as UserConfig, H as UserCourseSetting, E as UserCourseSettings, B as UserDBAuthenticator, z as UserDBReader, A as UserDBWriter, Y as UserHydrationState, Z as UserHydrationStatus, T as UserOutcomeRecord, I as UsrCrsDataInterface, aL as applyReading, ax as computeDeviation, az as computeEffectiveWeight, ay as computeSpread, aA as createOrchestrationContext, ap as drainCapturedRuns, aH as frozenMsAt, am as getActivePipeline, a9 as getCardOrigin, aP as getLapses, a5 as getRegisteredFilterKind, a2 as getRegisteredNavigator, a6 as getRegisteredNavigatorNames, a4 as getRegisteredNavigatorRole, ao as getRunsForSession, aO as getStreak, w as getStudySource, a3 as hasRegisteredNavigator, a7 as initializeNavigatorRegistry, aI as intakeHours, aK as intakeReading, ad as isFilter, ac as isGenerator, u as isReview, V as makeStudySessionId, al as mountPipelineDebugger, aN as newInterval, X as newSessionId, ak as pipelineDebugAPI, a1 as registerNavigator, aG as resetIntakeClock, aD as reviewMassReading, aC as reviewWeight, an as setDebugSessionId, aJ as stepIntakeClock } from './contentSource-
|
|
4
|
-
import { D as DataLayerProvider } from './dataLayerProvider-
|
|
2
|
+
import { U as UserDBInterface, g as CourseRegistrationDoc, m as SessionEloEvent, S as StudySessionItem, W as WeightedCard, R as ReplanHints, o as StudyContentSource, x as SessionStateSnapshotProvider, G as GeneratorResult, N as NavigatorRole, c as ContentNavigationStrategyData, F as FilterKind, y as RegulatorConfig, C as CourseDBInterface } from './contentSource-CPM872yn.js';
|
|
3
|
+
export { P as ActivityRecord, ae as CardFilter, ag as CardFilterFactory, ah as CardGenerator, aj as CardGeneratorFactory, K as ClassroomRegistration, J as ClassroomRegistrationDesignation, L as ClassroomRegistrationDoc, d as ContentNavigator, v as ContentSourceID, b as CourseInfo, Q as CourseRegistration, a as CoursesDBInterface, aB as DEFAULT_REGULATOR_CONFIG, aM as DocumentUpdater, af as FilterContext, at as FilterImpact, ai as GeneratorContext, as as GeneratorSummary, _ as HYDRATION_MARKER_ID, $ as HydrationMarker, aF as INTAKE_CLOCK_KEY, aE as IntakeClockState, av as LearnableWeight, a0 as NavigatorConstructor, ab as NavigatorRoles, aa as Navigators, aw as OrchestrationContext, au as PipelineForecaster, aq as PipelineRunReport, l as RegulatorName, j as RegulatorReading, ar as RunReportCard, f as ScheduledCard, h as SessionStateSnapshot, M as SessionTrackingData, a8 as StrategyContribution, e as StudySessionDoc, p as StudySessionFailedItem, q as StudySessionFailedNewItem, r as StudySessionFailedReviewItem, s as StudySessionNewItem, t as StudySessionReviewItem, k as StudySessionRunCard, n as StudySessionRunCardTrail, i as StudySessionRunSummary, O as UserConfig, H as UserCourseSetting, E as UserCourseSettings, B as UserDBAuthenticator, z as UserDBReader, A as UserDBWriter, Y as UserHydrationState, Z as UserHydrationStatus, T as UserOutcomeRecord, I as UsrCrsDataInterface, aL as applyReading, ax as computeDeviation, az as computeEffectiveWeight, ay as computeSpread, aA as createOrchestrationContext, ap as drainCapturedRuns, aH as frozenMsAt, am as getActivePipeline, a9 as getCardOrigin, aP as getLapses, a5 as getRegisteredFilterKind, a2 as getRegisteredNavigator, a6 as getRegisteredNavigatorNames, a4 as getRegisteredNavigatorRole, ao as getRunsForSession, aO as getStreak, w as getStudySource, a3 as hasRegisteredNavigator, a7 as initializeNavigatorRegistry, aI as intakeHours, aK as intakeReading, ad as isFilter, ac as isGenerator, u as isReview, V as makeStudySessionId, al as mountPipelineDebugger, aN as newInterval, X as newSessionId, ak as pipelineDebugAPI, a1 as registerNavigator, aG as resetIntakeClock, aD as reviewMassReading, aC as reviewWeight, an as setDebugSessionId, aJ as stepIntakeClock } from './contentSource-CPM872yn.js';
|
|
4
|
+
import { D as DataLayerProvider } from './dataLayerProvider-CaNgzRCz.js';
|
|
5
5
|
import { e as CardHistory, c as CardRecord, d as QuestionRecord } from './types-legacy-DdVjg81H.js';
|
|
6
6
|
export { C as CardData, g as CourseListData, h as DataShapeData, b as DisplayableData, D as DocType, f as DocTypePrefixes, F as Field, G as GuestUsername, Q as QualifiedCardID, i as QuestionData, S as SkuilderCourseData, a as Tag, T as TagStub, l as log } from './types-legacy-DdVjg81H.js';
|
|
7
7
|
import { SrsBacklogDebug, StrategyPressureDebug, Loggable } from './core/index.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "../../_virtual/_rolldown/runtime.mjs";
|
|
2
|
-
import { pushTagPresentation } from "@vue-skuilder/common";
|
|
2
|
+
import { TAG_OK_MIN_PERF, pushTagPresentation } from "@vue-skuilder/common";
|
|
3
3
|
//#region src/study/services/tagRecent.ts
|
|
4
4
|
/**
|
|
5
5
|
* Mastery signal: per-tag ring buffer of recent presentations.
|
|
@@ -51,6 +51,7 @@ function recordTagPresentations(userElo, perf, records, cardId, at) {
|
|
|
51
51
|
const entry = {
|
|
52
52
|
at,
|
|
53
53
|
ok,
|
|
54
|
+
tagOk: score > TAG_OK_MIN_PERF,
|
|
54
55
|
perf: score,
|
|
55
56
|
card: cardId
|
|
56
57
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tagRecent.mjs","names":[],"sources":["../../../src/study/services/tagRecent.ts"],"sourcesContent":["import {\n CourseElo,\n EloRank,\n TaggedPerformance,\n TagPresentation,\n pushTagPresentation,\n} from '@vue-skuilder/common';\nimport { CardRecord } from '@db/core';\n\n/**\n * Mastery signal: per-tag ring buffer of recent presentations.\n *\n * Written on the same path as the per-tag ELO update, one entry per\n * *presentation* of a card. Retries within a presentation (a record with\n * `priorAttemps > 0`, or any record after the first on the current card)\n * are not evidence and add nothing — including the \"dismiss-failed\" final\n * penalty, which reaches the ELO path on a retry record.\n *\n * Only tags the question actually graded (numeric perf) get an entry;\n * count-only exposure tags (`null`) carry no correctness signal.\n */\n\n/** The record for the presentation being graded, or null if none is visible. */\nfunction currentRecord(records: readonly CardRecord[]): CardRecord | null {\n return records.length ? records[records.length - 1] : null;\n}\n\n/**\n * Whether the record under grading is the first attempt of its presentation.\n *\n * `priorAttemps` is the authoritative marker (written by the question view).\n * When it is absent (non-question records, or a caller that did not push the\n * record onto `currentCard.records`), fall back to the presentation's record\n * count. With no record visible at all we cannot tell, and say no.\n */\nexport function isFirstAttempt(records: readonly CardRecord[]): boolean {\n const rec = currentRecord(records);\n if (!rec) return false;\n const prior = (rec as { priorAttemps?: unknown }).priorAttemps;\n if (typeof prior === 'number') return prior === 0;\n return records.length === 1;\n}\n\n/**\n * Append a presentation entry to every scored tag in `perf`, mutating\n * `userElo.tags[tag]` in place (each rank object is replaced, not mutated).\n * No-op for retries. Returns the tags that received an entry.\n */\nexport function recordTagPresentations(\n userElo: CourseElo,\n perf: TaggedPerformance,\n records: readonly CardRecord[],\n cardId: string,\n at: string\n): string[] {\n if (!isFirstAttempt(records)) return [];\n const rec = currentRecord(records) as { isCorrect?: unknown } | null;\n const ok = rec?.isCorrect === true;\n\n const written: string[] = [];\n for (const [tag, score] of Object.entries(perf)) {\n if (tag === '_global') continue;\n if (typeof score !== 'number') continue; // count-only exposure tag\n const rank: EloRank = userElo.tags[tag] ?? { score: userElo.global.score, count: 0 };\n const entry: TagPresentation = {
|
|
1
|
+
{"version":3,"file":"tagRecent.mjs","names":[],"sources":["../../../src/study/services/tagRecent.ts"],"sourcesContent":["import {\n CourseElo,\n EloRank,\n TAG_OK_MIN_PERF,\n TaggedPerformance,\n TagPresentation,\n pushTagPresentation,\n} from '@vue-skuilder/common';\nimport { CardRecord } from '@db/core';\n\n/**\n * Mastery signal: per-tag ring buffer of recent presentations.\n *\n * Written on the same path as the per-tag ELO update, one entry per\n * *presentation* of a card. Retries within a presentation (a record with\n * `priorAttemps > 0`, or any record after the first on the current card)\n * are not evidence and add nothing — including the \"dismiss-failed\" final\n * penalty, which reaches the ELO path on a retry record.\n *\n * Only tags the question actually graded (numeric perf) get an entry;\n * count-only exposure tags (`null`) carry no correctness signal.\n */\n\n/** The record for the presentation being graded, or null if none is visible. */\nfunction currentRecord(records: readonly CardRecord[]): CardRecord | null {\n return records.length ? records[records.length - 1] : null;\n}\n\n/**\n * Whether the record under grading is the first attempt of its presentation.\n *\n * `priorAttemps` is the authoritative marker (written by the question view).\n * When it is absent (non-question records, or a caller that did not push the\n * record onto `currentCard.records`), fall back to the presentation's record\n * count. With no record visible at all we cannot tell, and say no.\n */\nexport function isFirstAttempt(records: readonly CardRecord[]): boolean {\n const rec = currentRecord(records);\n if (!rec) return false;\n const prior = (rec as { priorAttemps?: unknown }).priorAttemps;\n if (typeof prior === 'number') return prior === 0;\n return records.length === 1;\n}\n\n/**\n * Append a presentation entry to every scored tag in `perf`, mutating\n * `userElo.tags[tag]` in place (each rank object is replaced, not mutated).\n * No-op for retries. Returns the tags that received an entry.\n */\nexport function recordTagPresentations(\n userElo: CourseElo,\n perf: TaggedPerformance,\n records: readonly CardRecord[],\n cardId: string,\n at: string\n): string[] {\n if (!isFirstAttempt(records)) return [];\n const rec = currentRecord(records) as { isCorrect?: unknown } | null;\n const ok = rec?.isCorrect === true;\n\n const written: string[] = [];\n for (const [tag, score] of Object.entries(perf)) {\n if (tag === '_global') continue;\n if (typeof score !== 'number') continue; // count-only exposure tag\n const rank: EloRank = userElo.tags[tag] ?? { score: userElo.global.score, count: 0 };\n const entry: TagPresentation = {\n at,\n ok,\n tagOk: score > TAG_OK_MIN_PERF,\n perf: score,\n card: cardId,\n };\n userElo.tags[tag] = pushTagPresentation(rank, entry);\n written.push(tag);\n }\n return written;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAwBA,SAAS,cAAc,SAAmD;AACxE,QAAO,QAAQ,SAAS,QAAQ,QAAQ,SAAS,KAAK;;;;;;;;;;AAWxD,SAAgB,eAAe,SAAyC;CACtE,MAAM,MAAM,cAAc,QAAQ;AAClC,KAAI,CAAC,IAAK,QAAO;CACjB,MAAM,QAAS,IAAmC;AAClD,KAAI,OAAO,UAAU,SAAU,QAAO,UAAU;AAChD,QAAO,QAAQ,WAAW;;;;;;;AAQ5B,SAAgB,uBACd,SACA,MACA,SACA,QACA,IACU;AACV,KAAI,CAAC,eAAe,QAAQ,CAAE,QAAO,EAAE;CAEvC,MAAM,KADM,cAAc,QAAQ,EAClB,cAAc;CAE9B,MAAM,UAAoB,EAAE;AAC5B,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,KAAK,EAAE;AAC/C,MAAI,QAAQ,UAAW;AACvB,MAAI,OAAO,UAAU,SAAU;EAC/B,MAAM,OAAgB,QAAQ,KAAK,QAAQ;GAAE,OAAO,QAAQ,OAAO;GAAO,OAAO;GAAG;EACpF,MAAM,QAAyB;GAC7B;GACA;GACA,OAAO,QAAQ;GACf,MAAM;GACN,MAAM;GACP;AACD,UAAQ,KAAK,OAAO,oBAAoB,MAAM,MAAM;AACpD,UAAQ,KAAK,IAAI;;AAEnB,QAAO"}
|
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"publishConfig": {
|
|
14
14
|
"access": "public"
|
|
15
15
|
},
|
|
16
|
-
"version": "0.3.
|
|
16
|
+
"version": "0.3.4",
|
|
17
17
|
"description": "Database layer for vue-skuilder",
|
|
18
18
|
"main": "dist/index.cjs",
|
|
19
19
|
"module": "dist/index.mjs",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
71
|
"@nilock2/pouchdb-authentication": "^1.0.2",
|
|
72
|
-
"@vue-skuilder/common": "0.3.
|
|
72
|
+
"@vue-skuilder/common": "0.3.4",
|
|
73
73
|
"cross-fetch": "^4.1.0",
|
|
74
74
|
"moment": "^2.29.4",
|
|
75
75
|
"pouchdb": "^9.0.0",
|
|
@@ -87,5 +87,5 @@
|
|
|
87
87
|
"vite": "^8.0.0",
|
|
88
88
|
"vitest": "^4.1.0"
|
|
89
89
|
},
|
|
90
|
-
"stableVersion": "0.3.
|
|
90
|
+
"stableVersion": "0.3.4"
|
|
91
91
|
}
|
|
@@ -35,8 +35,8 @@ import { logger } from '../../../util/logger';
|
|
|
35
35
|
//
|
|
36
36
|
// Intro cards pass through untouched. They carry an `intro`-role tag, grade
|
|
37
37
|
// nothing, and their ELO is a placeholder, so a distance on it means nothing.
|
|
38
|
-
// Penalising them
|
|
39
|
-
//
|
|
38
|
+
// Penalising them starves established learners of intros: a learner rated
|
|
39
|
+
// well above the placeholder sees every intro at the curve's floor.
|
|
40
40
|
//
|
|
41
41
|
// A `signal`, not a gate: it expresses preference, not readiness. `liveOnly`:
|
|
42
42
|
// forecasts and card-space scans start every card at 1.0 without a generator,
|
|
@@ -5,5 +5,8 @@ export type { CardFilter, FilterContext, CardFilterFactory, FilterKind } from '.
|
|
|
5
5
|
export { createEloDistanceFilter, default as EloDistanceFilter } from './eloDistance';
|
|
6
6
|
export type { EloDistanceConfig } from './eloDistance';
|
|
7
7
|
|
|
8
|
+
export { default as SkillPressureFilter, skillPressures } from './skillPressure';
|
|
9
|
+
export type { SkillPressureConfig } from './skillPressure';
|
|
10
|
+
|
|
8
11
|
export { default as UserTagPreferenceFilter } from './userTagPreference';
|
|
9
12
|
export type { UserTagPreferenceState } from './userTagPreference';
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import {
|
|
2
|
+
courseSecurity,
|
|
3
|
+
skillNeed,
|
|
4
|
+
type CourseElo,
|
|
5
|
+
type SkillNeedConfig,
|
|
6
|
+
type TagSecurityConfig,
|
|
7
|
+
type TagSecurityStatus,
|
|
8
|
+
} from '@vue-skuilder/common';
|
|
9
|
+
import type { CourseDBInterface } from '../../interfaces/courseDB';
|
|
10
|
+
import type { UserDBInterface } from '../../interfaces/userDB';
|
|
11
|
+
import type { ContentNavigationStrategyData } from '../../types/contentNavigationStrategy';
|
|
12
|
+
import { ContentNavigator } from '../index';
|
|
13
|
+
import type { WeightedCard } from '../index';
|
|
14
|
+
import type { GeneratorResult } from '../generators/types';
|
|
15
|
+
import type { CardFilter, FilterContext, FilterKind } from './types';
|
|
16
|
+
|
|
17
|
+
// ============================================================================
|
|
18
|
+
// SKILL PRESSURE FILTER
|
|
19
|
+
// ============================================================================
|
|
20
|
+
//
|
|
21
|
+
// Leans selection toward the learner's weakest skills: a card exercising a
|
|
22
|
+
// skill under pressure gets a small, bounded boost. "Which skill", kept
|
|
23
|
+
// separate from ELO distance's "what difficulty", so each is its own line in
|
|
24
|
+
// a card's provenance.
|
|
25
|
+
//
|
|
26
|
+
// A skill's pressure (0–1) is the larger of:
|
|
27
|
+
// - need (common/skillNeed): how far its rating sits below the median of the
|
|
28
|
+
// learner's skills;
|
|
29
|
+
// - insecurity (common/tagSecurity), when enabled: a fixed weight for a met
|
|
30
|
+
// skill that is shaky (right too rarely lately) or unproven (too little
|
|
31
|
+
// recent evidence). This is what works down the insecure count a course may
|
|
32
|
+
// gate new material on; need alone misses skills rated near the median but
|
|
33
|
+
// missed lately, and skills with too few responses to rate.
|
|
34
|
+
//
|
|
35
|
+
// multiplier = 1 + gain · (the card's highest skill pressure). The max over a
|
|
36
|
+
// card's tags, never the product, so a card naming several weak skills isn't
|
|
37
|
+
// boosted several times.
|
|
38
|
+
//
|
|
39
|
+
// Acts on the whole heap, reviews included: its first effect under a review
|
|
40
|
+
// backlog is on *which* reviews are served. A boost can't bring a card that no
|
|
41
|
+
// generator retrieved; retrieval of a weak skill's unseen cards is a
|
|
42
|
+
// generator's job.
|
|
43
|
+
//
|
|
44
|
+
// A `signal`. Not added by default: it re-weights every candidate, so a course
|
|
45
|
+
// opts in with a `skillPressure` strategy doc (serializedData: a
|
|
46
|
+
// SkillPressureConfig as JSON, or empty for the defaults).
|
|
47
|
+
//
|
|
48
|
+
// ============================================================================
|
|
49
|
+
|
|
50
|
+
export interface SkillPressureConfig extends SkillNeedConfig {
|
|
51
|
+
/** Boost at pressure 1: multiplier = 1 + gain · pressure. Default 0.5 (cap ×1.5). */
|
|
52
|
+
gain?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Insecurity as pressure. `false` turns it off (need only). Weights are
|
|
55
|
+
* need-equivalents, 0–1. Default: shaky 0.8, unproven 0.5. Uses the same
|
|
56
|
+
* tag selector as need.
|
|
57
|
+
*/
|
|
58
|
+
security?:
|
|
59
|
+
| false
|
|
60
|
+
| {
|
|
61
|
+
shaky?: number;
|
|
62
|
+
unproven?: number;
|
|
63
|
+
/** Thresholds for secure / shaky / unproven. Default: the framework's. */
|
|
64
|
+
config?: TagSecurityConfig;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const DEFAULT_GAIN = 0.5;
|
|
69
|
+
const DEFAULT_SECURITY_WEIGHTS: Record<Exclude<TagSecurityStatus, 'secure'>, number> = {
|
|
70
|
+
shaky: 0.8,
|
|
71
|
+
unproven: 0.5,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
interface SkillPressureEntry {
|
|
75
|
+
pressure: number;
|
|
76
|
+
why: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Pressure per skill tag for this learner; tags under no pressure are absent. */
|
|
80
|
+
export function skillPressures(
|
|
81
|
+
elo: CourseElo,
|
|
82
|
+
config: SkillPressureConfig = {}
|
|
83
|
+
): Map<string, SkillPressureEntry> {
|
|
84
|
+
const out = new Map<string, SkillPressureEntry>();
|
|
85
|
+
const raise = (tag: string, pressure: number, why: string): void => {
|
|
86
|
+
if (pressure <= 0) return;
|
|
87
|
+
const prev = out.get(tag);
|
|
88
|
+
if (!prev || pressure > prev.pressure) out.set(tag, { pressure, why });
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
for (const s of skillNeed(elo, config).skills) {
|
|
92
|
+
raise(s.tag, s.need, `need ${s.need.toFixed(2)} (${Math.round(s.deficit)} below the skill median)`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (config.security !== false) {
|
|
96
|
+
const weights = { ...DEFAULT_SECURITY_WEIGHTS, ...(config.security ?? {}) };
|
|
97
|
+
const { include, exclude, roles } = config;
|
|
98
|
+
const security = courseSecurity(elo, {
|
|
99
|
+
selector: { include, exclude, roles },
|
|
100
|
+
config: config.security ? config.security.config : undefined,
|
|
101
|
+
});
|
|
102
|
+
for (const s of security.tags) {
|
|
103
|
+
if (s.status === 'secure') continue;
|
|
104
|
+
const n = Math.min(s.attempts, 12);
|
|
105
|
+
raise(
|
|
106
|
+
s.tag,
|
|
107
|
+
weights[s.status],
|
|
108
|
+
s.status === 'shaky' ? `shaky (${s.right}/${n} right)` : `unproven (${s.attempts} recent attempts)`
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return out;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async function applySkillPressure(
|
|
116
|
+
cards: WeightedCard[],
|
|
117
|
+
context: FilterContext,
|
|
118
|
+
config: SkillPressureConfig,
|
|
119
|
+
source: { name: string; strategyId: string }
|
|
120
|
+
): Promise<WeightedCard[]> {
|
|
121
|
+
if (!context.userCourseElo) return cards;
|
|
122
|
+
const pressures = skillPressures(context.userCourseElo, config);
|
|
123
|
+
if (pressures.size === 0) return cards;
|
|
124
|
+
const gain = config.gain ?? DEFAULT_GAIN;
|
|
125
|
+
|
|
126
|
+
return cards.map((card) => {
|
|
127
|
+
let top: { tag: string; entry: SkillPressureEntry } | null = null;
|
|
128
|
+
for (const tag of card.tags ?? []) {
|
|
129
|
+
const entry = pressures.get(tag);
|
|
130
|
+
if (entry && (!top || entry.pressure > top.entry.pressure)) top = { tag, entry };
|
|
131
|
+
}
|
|
132
|
+
if (!top) return card;
|
|
133
|
+
|
|
134
|
+
const multiplier = 1 + gain * top.entry.pressure;
|
|
135
|
+
const score = card.score * multiplier;
|
|
136
|
+
return {
|
|
137
|
+
...card,
|
|
138
|
+
score,
|
|
139
|
+
provenance: [
|
|
140
|
+
...card.provenance,
|
|
141
|
+
{
|
|
142
|
+
strategy: 'skillPressure',
|
|
143
|
+
strategyName: source.name,
|
|
144
|
+
strategyId: source.strategyId,
|
|
145
|
+
action: 'boosted',
|
|
146
|
+
score,
|
|
147
|
+
reason: `skill pressure: ${top.tag} ${top.entry.why} → ×${multiplier.toFixed(2)}`,
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* The skill pressure filter as a strategy-doc navigator (`implementingClass:
|
|
156
|
+
* 'skillPressure'`, serializedData: a SkillPressureConfig as JSON, or empty).
|
|
157
|
+
*/
|
|
158
|
+
export default class SkillPressureFilter extends ContentNavigator implements CardFilter {
|
|
159
|
+
name: string;
|
|
160
|
+
/** See CardFilter.kind. Static, so the pipeline plan can read it without an instance. */
|
|
161
|
+
static readonly kind: FilterKind = 'signal';
|
|
162
|
+
readonly kind = SkillPressureFilter.kind;
|
|
163
|
+
private config: SkillPressureConfig;
|
|
164
|
+
|
|
165
|
+
constructor(
|
|
166
|
+
user: UserDBInterface,
|
|
167
|
+
course: CourseDBInterface,
|
|
168
|
+
strategyData: ContentNavigationStrategyData
|
|
169
|
+
) {
|
|
170
|
+
super(user, course, strategyData);
|
|
171
|
+
this.name = strategyData.name || 'Skill Pressure';
|
|
172
|
+
let parsed: SkillPressureConfig = {};
|
|
173
|
+
try {
|
|
174
|
+
parsed = strategyData.serializedData ? JSON.parse(strategyData.serializedData) : {};
|
|
175
|
+
} catch {
|
|
176
|
+
parsed = {};
|
|
177
|
+
}
|
|
178
|
+
this.config = parsed;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
transform(cards: WeightedCard[], context: FilterContext): Promise<WeightedCard[]> {
|
|
182
|
+
return applySkillPressure(cards, context, this.config, {
|
|
183
|
+
name: this.name,
|
|
184
|
+
strategyId: this.strategyId || 'NAVIGATION_STRATEGY-skillPressure',
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async getWeightedCards(_limit: number): Promise<GeneratorResult> {
|
|
189
|
+
throw new Error(
|
|
190
|
+
'SkillPressureFilter is a filter and should not be used as a generator. ' +
|
|
191
|
+
'Use Pipeline with a generator and this filter via transform().'
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
@@ -35,16 +35,15 @@ import { logger } from '@db/util/logger';
|
|
|
35
35
|
//
|
|
36
36
|
// KNOWN LATENT BUG (2026-11-17): this generator decides targets, support,
|
|
37
37
|
// boost hints and pressure *before* the gates run, and knows nothing about
|
|
38
|
-
// them. It will target and support cards a gate is certain to block (
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
//
|
|
38
|
+
// them. It will target and support cards a gate is certain to block (e.g. a
|
|
39
|
+
// target whose prerequisites sit behind a course gate that never opens), so
|
|
40
|
+
// the group can never complete. Harmless while every such card stays gated;
|
|
41
|
+
// but staleness escalates the support boost hint to its cap on those tags,
|
|
42
42
|
// so the day one becomes ungated it gets that boost at once (a pressure
|
|
43
43
|
// mania). Proposed fix: Pipeline offers generators the gate-kind filters
|
|
44
44
|
// (e.g. `context.gate(cardIds)`), and prescribed treats gated candidates as
|
|
45
45
|
// blocked: not emitted, not boosted, not escalating. That would also replace
|
|
46
|
-
// this file's own hierarchy walk.
|
|
47
|
-
// (Watch: "Prescribed targets gated cards").
|
|
46
|
+
// this file's own hierarchy walk.
|
|
48
47
|
//
|
|
49
48
|
// ============================================================================
|
|
50
49
|
|
|
@@ -200,18 +200,21 @@ export async function initializeNavigatorRegistry(): Promise<void> {
|
|
|
200
200
|
relativePriorityModule,
|
|
201
201
|
userTagPreferenceModule,
|
|
202
202
|
eloDistanceModule,
|
|
203
|
+
skillPressureModule,
|
|
203
204
|
] = await Promise.all([
|
|
204
205
|
import('./filters/hierarchyDefinition'),
|
|
205
206
|
import('./filters/interferenceMitigator'),
|
|
206
207
|
import('./filters/relativePriority'),
|
|
207
208
|
import('./filters/userTagPreference'),
|
|
208
209
|
import('./filters/eloDistance'),
|
|
210
|
+
import('./filters/skillPressure'),
|
|
209
211
|
]);
|
|
210
212
|
registerNavigator('hierarchyDefinition', hierarchyModule.default);
|
|
211
213
|
registerNavigator('interferenceMitigator', interferenceModule.default);
|
|
212
214
|
registerNavigator('relativePriority', relativePriorityModule.default);
|
|
213
215
|
registerNavigator('userTagPreference', userTagPreferenceModule.default);
|
|
214
216
|
registerNavigator('eloDistance', eloDistanceModule.default);
|
|
217
|
+
registerNavigator('skillPressure', skillPressureModule.default);
|
|
215
218
|
|
|
216
219
|
logger.debug(
|
|
217
220
|
`[NavigatorRegistry] Initialized ${navigatorRegistry.size} navigators: ${getRegisteredNavigatorNames().join(', ')}`
|
|
@@ -412,6 +415,7 @@ export enum Navigators {
|
|
|
412
415
|
RELATIVE_PRIORITY = 'relativePriority',
|
|
413
416
|
USER_TAG_PREFERENCE = 'userTagPreference',
|
|
414
417
|
ELO_DISTANCE = 'eloDistance',
|
|
418
|
+
SKILL_PRESSURE = 'skillPressure',
|
|
415
419
|
}
|
|
416
420
|
|
|
417
421
|
// ============================================================================
|
|
@@ -452,6 +456,7 @@ export const NavigatorRoles: Record<Navigators, NavigatorRole> = {
|
|
|
452
456
|
[Navigators.RELATIVE_PRIORITY]: NavigatorRole.FILTER,
|
|
453
457
|
[Navigators.USER_TAG_PREFERENCE]: NavigatorRole.FILTER,
|
|
454
458
|
[Navigators.ELO_DISTANCE]: NavigatorRole.FILTER,
|
|
459
|
+
[Navigators.SKILL_PRESSURE]: NavigatorRole.FILTER,
|
|
455
460
|
};
|
|
456
461
|
|
|
457
462
|
/**
|
|
@@ -13,7 +13,7 @@ import type {
|
|
|
13
13
|
StudySessionRunSummary,
|
|
14
14
|
} from '../core/types/studySession';
|
|
15
15
|
import type { CardSummary, DatasetRecord, LearnerDataset } from './dataset';
|
|
16
|
-
import type { TagBatch } from './tagElo';
|
|
16
|
+
import type { TagBatch, TagEloViewOptions } from './tagElo';
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Course-supplied meaning for the generic views. Every member is optional and
|
|
@@ -36,6 +36,11 @@ export interface DiagnosticsInterpreters {
|
|
|
36
36
|
* batches it finds on its own. Default: none.
|
|
37
37
|
*/
|
|
38
38
|
tagBatches?: TagBatch[];
|
|
39
|
+
/**
|
|
40
|
+
* How the ELO view reads skills: which tags security and need consider, and
|
|
41
|
+
* their thresholds. Default: exercise-role tags, framework thresholds.
|
|
42
|
+
*/
|
|
43
|
+
tagEloOptions?: TagEloViewOptions;
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
export const isSkillTag = (i: DiagnosticsInterpreters | undefined, tag: string): boolean =>
|
|
@@ -10,9 +10,17 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import {
|
|
12
12
|
COUNT_ONLY_SCORE,
|
|
13
|
+
courseSecurity,
|
|
13
14
|
isCountOnlyTag,
|
|
15
|
+
presentationOk,
|
|
16
|
+
skillNeed,
|
|
14
17
|
tagRole,
|
|
15
18
|
type CourseElo,
|
|
19
|
+
type CourseSecurity,
|
|
20
|
+
type SkillNeedConfig,
|
|
21
|
+
type TagSecurity,
|
|
22
|
+
type TagSecurityConfig,
|
|
23
|
+
type TagSelector,
|
|
16
24
|
type EloRank,
|
|
17
25
|
type TagPresentation,
|
|
18
26
|
type TagRole,
|
|
@@ -104,8 +112,14 @@ export interface TagEloRow {
|
|
|
104
112
|
vsGlobal: number | null;
|
|
105
113
|
/** The rating's ring buffer of recent first attempts, oldest first. */
|
|
106
114
|
recent: TagPresentation[];
|
|
107
|
-
/**
|
|
115
|
+
/** Entries in `recent` right on this tag (per-tag, not the card's ok). */
|
|
108
116
|
recentOk: number;
|
|
117
|
+
/** Secure / shaky / unproven, for tags the security selector picks (met exercise tags by default). */
|
|
118
|
+
security?: TagSecurity;
|
|
119
|
+
/** 0–1 need from skillNeed; absent for tags that don't qualify as skills. */
|
|
120
|
+
need?: number;
|
|
121
|
+
/** Skill reference − rating; absent with need. */
|
|
122
|
+
deficit?: number;
|
|
109
123
|
/** First and last response whose per-tag performance named the tag, or a recent entry. */
|
|
110
124
|
firstSeen: string | null;
|
|
111
125
|
lastSeen: string | null;
|
|
@@ -134,6 +148,16 @@ export interface TagEloView {
|
|
|
134
148
|
series: { global: EloPoint[]; tags: Record<string, EloPoint[]> };
|
|
135
149
|
/** The first ELO event, or null: trajectories start here. */
|
|
136
150
|
seriesFrom: string | null;
|
|
151
|
+
/** Median rating over the learner's qualifying skills (skillNeed); null if too few. */
|
|
152
|
+
skillReference: number | null;
|
|
153
|
+
/** Security totals over the selected tags. */
|
|
154
|
+
security: Omit<CourseSecurity, 'tags'>;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** How the view reads skills: a course may pass its own selectors and thresholds. */
|
|
158
|
+
export interface TagEloViewOptions {
|
|
159
|
+
security?: { selector?: TagSelector; config?: TagSecurityConfig };
|
|
160
|
+
need?: SkillNeedConfig;
|
|
137
161
|
}
|
|
138
162
|
|
|
139
163
|
/** The learner's `CourseElo` for the dataset's course, or null if not registered. */
|
|
@@ -164,10 +188,15 @@ function step(line: EloPoint[], at: string, before: number, after: number): void
|
|
|
164
188
|
}
|
|
165
189
|
|
|
166
190
|
/** The learner's per-tag ELO for display. Null if the dataset has no registration for its course. */
|
|
167
|
-
export function tagEloView(ds: LearnerDataset): TagEloView | null {
|
|
191
|
+
export function tagEloView(ds: LearnerDataset, options: TagEloViewOptions = {}): TagEloView | null {
|
|
168
192
|
const elo = learnerCourseElo(ds);
|
|
169
193
|
if (!elo) return null;
|
|
170
194
|
|
|
195
|
+
const security = courseSecurity(elo, options.security);
|
|
196
|
+
const securityByTag = new Map(security.tags.map((s) => [s.tag, s]));
|
|
197
|
+
const need = skillNeed(elo, options.need);
|
|
198
|
+
const needByTag = new Map(need.skills.map((s) => [s.tag, s]));
|
|
199
|
+
|
|
171
200
|
// When each tag was named by a response, from card history.
|
|
172
201
|
const seen = new Map<string, { first: string | null; last: string | null }>();
|
|
173
202
|
for (const h of ds.cardHistories) {
|
|
@@ -220,7 +249,11 @@ export function tagEloView(ds: LearnerDataset): TagEloView | null {
|
|
|
220
249
|
count: rank.count,
|
|
221
250
|
vsGlobal: score === null ? null : score - elo.global.score,
|
|
222
251
|
recent,
|
|
223
|
-
recentOk: recent.filter(
|
|
252
|
+
recentOk: recent.filter(presentationOk).length,
|
|
253
|
+
...(securityByTag.has(tag) ? { security: securityByTag.get(tag) } : {}),
|
|
254
|
+
...(needByTag.has(tag)
|
|
255
|
+
? { need: needByTag.get(tag)!.need, deficit: needByTag.get(tag)!.deficit }
|
|
256
|
+
: {}),
|
|
224
257
|
firstSeen: first,
|
|
225
258
|
lastSeen: last,
|
|
226
259
|
events: eventCounts.get(tag) ?? 0,
|
|
@@ -253,5 +286,12 @@ export function tagEloView(ds: LearnerDataset): TagEloView | null {
|
|
|
253
286
|
),
|
|
254
287
|
series: { global: globalSeries, tags: tagSeries },
|
|
255
288
|
seriesFrom: events[0]?.at ?? null,
|
|
289
|
+
skillReference: need.reference,
|
|
290
|
+
security: {
|
|
291
|
+
secure: security.secure,
|
|
292
|
+
shaky: security.shaky,
|
|
293
|
+
unproven: security.unproven,
|
|
294
|
+
debt: security.debt,
|
|
295
|
+
},
|
|
256
296
|
};
|
|
257
297
|
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
TAG_RECENT_MAX,
|
|
4
|
+
courseSecurity,
|
|
5
|
+
pushTagPresentation,
|
|
6
|
+
tagSecurity,
|
|
7
|
+
type CourseElo,
|
|
8
|
+
type EloRank,
|
|
9
|
+
} from '@vue-skuilder/common';
|
|
3
10
|
import { isFirstAttempt, recordTagPresentations } from './tagRecent';
|
|
4
11
|
import type { CardRecord } from '@db/core';
|
|
5
12
|
|
|
@@ -61,7 +68,7 @@ describe('recordTagPresentations', () => {
|
|
|
61
68
|
);
|
|
62
69
|
expect(written).toEqual(['gpc:exercise:th-TH']);
|
|
63
70
|
expect(elo.tags['gpc:exercise:th-TH'].recent).toEqual([
|
|
64
|
-
{ at: '2026-09-18T00:00:00.000Z', ok: true, perf: 0.6, card: 'c-ml-worth-3' },
|
|
71
|
+
{ at: '2026-09-18T00:00:00.000Z', ok: true, tagOk: true, perf: 0.6, card: 'c-ml-worth-3' },
|
|
65
72
|
]);
|
|
66
73
|
expect(elo.tags['gpc:expose:w-W']).toBeUndefined();
|
|
67
74
|
});
|
|
@@ -69,7 +76,7 @@ describe('recordTagPresentations', () => {
|
|
|
69
76
|
it('records a first-attempt miss as ok:false', () => {
|
|
70
77
|
const elo = blank();
|
|
71
78
|
recordTagPresentations(elo, { _global: 0, 'gpc:exercise:sh-SH': 0 }, [rec(0, false)], 'c-ml-hush-2', 't');
|
|
72
|
-
expect(elo.tags['gpc:exercise:sh-SH'].recent).toEqual([{ at: 't', ok: false, perf: 0, card: 'c-ml-hush-2' }]);
|
|
79
|
+
expect(elo.tags['gpc:exercise:sh-SH'].recent).toEqual([{ at: 't', ok: false, tagOk: false, perf: 0, card: 'c-ml-hush-2' }]);
|
|
73
80
|
});
|
|
74
81
|
|
|
75
82
|
it('adds nothing for a retry (priorAttemps > 0), even a correct one', () => {
|
|
@@ -99,3 +106,50 @@ describe('recordTagPresentations', () => {
|
|
|
99
106
|
expect(elo.tags['t'].recent![0].card).toBe('card-3');
|
|
100
107
|
});
|
|
101
108
|
});
|
|
109
|
+
|
|
110
|
+
describe('tagSecurity', () => {
|
|
111
|
+
const day = (d: number) => `2026-11-${String(d).padStart(2, '0')}T12:00:00.000Z`;
|
|
112
|
+
const rank = (oks: boolean[], days: number[]): EloRank => ({
|
|
113
|
+
score: 1500,
|
|
114
|
+
count: oks.length,
|
|
115
|
+
recent: oks.map((ok, i) => ({ at: day(days[i]), ok: true, tagOk: ok, perf: ok ? 0.8 : 0, card: `c${i}` })),
|
|
116
|
+
});
|
|
117
|
+
const cfg = { dayOf: (at: string) => at.slice(0, 10) };
|
|
118
|
+
|
|
119
|
+
it('unproven below minAttempts, shaky under 75% of the window, secure otherwise', () => {
|
|
120
|
+
const five = Array(5).fill(true);
|
|
121
|
+
expect(tagSecurity('t', rank(five, [1, 1, 2, 2, 3]), cfg).status).toBe('unproven');
|
|
122
|
+
// 12 attempts, 8 right (67%): shaky; the card-level ok (all true) is ignored
|
|
123
|
+
const eightOfTwelve = [...Array(8).fill(true), ...Array(4).fill(false)];
|
|
124
|
+
expect(tagSecurity('t', rank(eightOfTwelve, Array(12).fill(0).map((_, i) => 1 + (i % 3))), cfg).status).toBe('shaky');
|
|
125
|
+
// 6 of 6 right, all on one day: unproven (needs two days)
|
|
126
|
+
expect(tagSecurity('t', rank(Array(6).fill(true), Array(6).fill(4)), cfg).status).toBe('unproven');
|
|
127
|
+
expect(tagSecurity('t', rank(Array(6).fill(true), [4, 4, 4, 5, 5, 5]), cfg).status).toBe('secure');
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('falls back to perf for entries without tagOk (hinted 0.5 is not right)', () => {
|
|
131
|
+
const r: EloRank = {
|
|
132
|
+
score: 1500,
|
|
133
|
+
count: 6,
|
|
134
|
+
recent: [0.6, 0.8, 0.5, 0.8, 0.8, 0.8].map((perf, i) => ({ at: day(1 + (i % 2)), ok: true, perf, card: `c${i}` })),
|
|
135
|
+
};
|
|
136
|
+
const s = tagSecurity('t', r, cfg);
|
|
137
|
+
expect(s.right).toBe(5);
|
|
138
|
+
expect(s.status).toBe('secure');
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('courseSecurity counts met exercise tags only; a met tag with no buffer is unproven', () => {
|
|
142
|
+
const elo: CourseElo = {
|
|
143
|
+
global: { score: 1500, count: 100 },
|
|
144
|
+
tags: {
|
|
145
|
+
'gpc:exercise:a-AE': rank(Array(6).fill(true), [1, 1, 1, 2, 2, 2]),
|
|
146
|
+
'gpc:exercise:a-EY': { score: 1300, count: 9 },
|
|
147
|
+
'gpc:expose:a-AE': { score: -1, count: 4 },
|
|
148
|
+
},
|
|
149
|
+
misc: {},
|
|
150
|
+
};
|
|
151
|
+
const c = courseSecurity(elo, { config: cfg });
|
|
152
|
+
expect(c.tags.map((t) => t.tag).sort()).toEqual(['gpc:exercise:a-AE', 'gpc:exercise:a-EY']);
|
|
153
|
+
expect([c.secure, c.shaky, c.unproven, c.debt]).toEqual([1, 0, 1, 1]);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CourseElo,
|
|
3
3
|
EloRank,
|
|
4
|
+
TAG_OK_MIN_PERF,
|
|
4
5
|
TaggedPerformance,
|
|
5
6
|
TagPresentation,
|
|
6
7
|
pushTagPresentation,
|
|
@@ -62,7 +63,13 @@ export function recordTagPresentations(
|
|
|
62
63
|
if (tag === '_global') continue;
|
|
63
64
|
if (typeof score !== 'number') continue; // count-only exposure tag
|
|
64
65
|
const rank: EloRank = userElo.tags[tag] ?? { score: userElo.global.score, count: 0 };
|
|
65
|
-
const entry: TagPresentation = {
|
|
66
|
+
const entry: TagPresentation = {
|
|
67
|
+
at,
|
|
68
|
+
ok,
|
|
69
|
+
tagOk: score > TAG_OK_MIN_PERF,
|
|
70
|
+
perf: score,
|
|
71
|
+
card: cardId,
|
|
72
|
+
};
|
|
66
73
|
userElo.tags[tag] = pushTagPresentation(rank, entry);
|
|
67
74
|
written.push(tag);
|
|
68
75
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import type { CourseElo, EloRank } from '@vue-skuilder/common';
|
|
3
|
+
import SkillPressureFilter, { skillPressures } from '../../../src/core/navigators/filters/skillPressure';
|
|
4
|
+
import type { WeightedCard } from '../../../src/core/navigators/index';
|
|
5
|
+
import type { FilterContext } from '../../../src/core/navigators/filters/types';
|
|
6
|
+
import type { CourseDBInterface } from '../../../src/core/interfaces/courseDB';
|
|
7
|
+
import type { UserDBInterface } from '../../../src/core/interfaces/userDB';
|
|
8
|
+
import type { ContentNavigationStrategyData } from '../../../src/core/types/contentNavigationStrategy';
|
|
9
|
+
|
|
10
|
+
/** A rated skill with `n` first attempts, `right` of them right, over two days. */
|
|
11
|
+
function skill(score: number, n = 12, right = n): EloRank {
|
|
12
|
+
return {
|
|
13
|
+
score,
|
|
14
|
+
count: Math.max(n, 10),
|
|
15
|
+
recent: Array.from({ length: n }, (_, i) => ({
|
|
16
|
+
at: `2026-11-0${1 + (i % 2)}T12:00:00.000Z`,
|
|
17
|
+
ok: i < right,
|
|
18
|
+
tagOk: i < right,
|
|
19
|
+
perf: i < right ? 0.8 : 0,
|
|
20
|
+
card: `c${i}`,
|
|
21
|
+
})),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const elo: CourseElo = {
|
|
26
|
+
global: { score: 1500, count: 500 },
|
|
27
|
+
tags: {
|
|
28
|
+
'exercise:a': skill(1500),
|
|
29
|
+
'exercise:b': skill(1500),
|
|
30
|
+
'exercise:c': skill(1500),
|
|
31
|
+
'exercise:d': skill(1500),
|
|
32
|
+
'exercise:low': skill(1350), // 150 below the median: need 1
|
|
33
|
+
'exercise:shaky': skill(1500, 12, 6), // at the median, right half the time
|
|
34
|
+
},
|
|
35
|
+
misc: {},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const card = (id: string, tags: string[]): WeightedCard => ({
|
|
39
|
+
cardId: id,
|
|
40
|
+
courseId: 'c',
|
|
41
|
+
score: 1,
|
|
42
|
+
tags,
|
|
43
|
+
provenance: [{ strategy: 'test', strategyName: 'T', strategyId: 'T', action: 'generated', score: 1, reason: 't' }],
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
function filter(serializedData = ''): SkillPressureFilter {
|
|
47
|
+
return new SkillPressureFilter({} as UserDBInterface, {} as CourseDBInterface, {
|
|
48
|
+
name: 'Skill Pressure',
|
|
49
|
+
serializedData,
|
|
50
|
+
} as ContentNavigationStrategyData);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const ctx = (userCourseElo?: CourseElo): FilterContext => ({
|
|
54
|
+
user: {} as UserDBInterface,
|
|
55
|
+
course: {} as CourseDBInterface,
|
|
56
|
+
userElo: 1500,
|
|
57
|
+
...(userCourseElo ? { userCourseElo } : {}),
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('skill pressure', () => {
|
|
61
|
+
it('pressures low-rated skills by need, and shaky ones by insecurity', () => {
|
|
62
|
+
const p = skillPressures(elo);
|
|
63
|
+
expect(p.get('exercise:low')?.pressure).toBe(1);
|
|
64
|
+
expect(p.get('exercise:shaky')?.pressure).toBe(0.8);
|
|
65
|
+
expect(p.has('exercise:a')).toBe(false);
|
|
66
|
+
expect(skillPressures(elo, { security: false }).has('exercise:shaky')).toBe(false);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('boosts by the card’s neediest tag (max, not product), up to ×1.5', async () => {
|
|
70
|
+
const out = await filter().transform(
|
|
71
|
+
[card('both', ['exercise:low', 'exercise:shaky']), card('shaky', ['exercise:shaky']), card('fine', ['exercise:a'])],
|
|
72
|
+
ctx(elo)
|
|
73
|
+
);
|
|
74
|
+
expect(out[0].score).toBeCloseTo(1.5);
|
|
75
|
+
expect(out[1].score).toBeCloseTo(1.4);
|
|
76
|
+
expect(out[2].score).toBe(1);
|
|
77
|
+
expect(out[0].provenance.at(-1)?.reason).toContain('exercise:low');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('passes everything through without the learner’s ratings', async () => {
|
|
81
|
+
const cards = [card('x', ['exercise:low'])];
|
|
82
|
+
expect(await filter().transform(cards, ctx())).toEqual(cards);
|
|
83
|
+
});
|
|
84
|
+
});
|