@vue-skuilder/db 0.2.33 → 0.2.35

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.
Files changed (49) hide show
  1. package/dist/{contentSource-JmWYu8IK.d.ts → contentSource-BteiDpxH.d.ts} +2 -2
  2. package/dist/{contentSource-CTQ4kWhR.d.cts → contentSource-FQZcZopC.d.cts} +2 -2
  3. package/dist/core/index.d.cts +5 -5
  4. package/dist/core/index.d.ts +5 -5
  5. package/dist/core/index.js +2 -1
  6. package/dist/core/index.js.map +1 -1
  7. package/dist/core/index.mjs +2 -1
  8. package/dist/core/index.mjs.map +1 -1
  9. package/dist/{dataLayerProvider-DfI_KYAe.d.cts → dataLayerProvider-3y21KtF-.d.cts} +1 -1
  10. package/dist/{dataLayerProvider-rlLE2Mf-.d.ts → dataLayerProvider-C_QWzHf-.d.ts} +1 -1
  11. package/dist/diagnostics/index.d.cts +108 -5
  12. package/dist/diagnostics/index.d.ts +108 -5
  13. package/dist/diagnostics/index.js +129 -0
  14. package/dist/diagnostics/index.js.map +1 -1
  15. package/dist/diagnostics/index.mjs +128 -0
  16. package/dist/diagnostics/index.mjs.map +1 -1
  17. package/dist/impl/couch/index.d.cts +3 -3
  18. package/dist/impl/couch/index.d.ts +3 -3
  19. package/dist/impl/couch/index.js +2 -1
  20. package/dist/impl/couch/index.js.map +1 -1
  21. package/dist/impl/couch/index.mjs +2 -1
  22. package/dist/impl/couch/index.mjs.map +1 -1
  23. package/dist/impl/static/index.d.cts +4 -4
  24. package/dist/impl/static/index.d.ts +4 -4
  25. package/dist/impl/static/index.js +2 -1
  26. package/dist/impl/static/index.js.map +1 -1
  27. package/dist/impl/static/index.mjs +2 -1
  28. package/dist/impl/static/index.mjs.map +1 -1
  29. package/dist/{index-Ktg72jKb.d.cts → index-BIum9Ue2.d.cts} +1 -1
  30. package/dist/{index-CVGehe_t.d.ts → index-C745YB_6.d.ts} +1 -1
  31. package/dist/index.d.cts +12 -10
  32. package/dist/index.d.ts +12 -10
  33. package/dist/index.js +27 -17
  34. package/dist/index.js.map +1 -1
  35. package/dist/index.mjs +32 -18
  36. package/dist/index.mjs.map +1 -1
  37. package/dist/{types-D0oQeJAi.d.cts → types-BcWVH4ww.d.cts} +1 -1
  38. package/dist/{types-dXWfyz9B.d.ts → types-DF0JuPbs.d.ts} +1 -1
  39. package/dist/{types-legacy-BkOYOR6U.d.cts → types-legacy-DdVjg81H.d.cts} +1 -1
  40. package/dist/{types-legacy-BkOYOR6U.d.ts → types-legacy-DdVjg81H.d.ts} +1 -1
  41. package/dist/util/packer/index.d.cts +3 -3
  42. package/dist/util/packer/index.d.ts +3 -3
  43. package/package.json +3 -3
  44. package/src/core/navigators/filters/eloDistance.ts +10 -0
  45. package/src/courseConfigRegistration.ts +22 -10
  46. package/src/diagnostics/derive.ts +6 -0
  47. package/src/diagnostics/index.ts +1 -0
  48. package/src/diagnostics/tagElo.ts +257 -0
  49. package/src/study/SpacedRepetition.ts +23 -6
@@ -1,5 +1,5 @@
1
1
  import { CourseConfig } from '@vue-skuilder/common';
2
- import { D as DocType } from './types-legacy-BkOYOR6U.cjs';
2
+ import { D as DocType } from './types-legacy-DdVjg81H.cjs';
3
3
 
4
4
  interface StaticCourseManifest {
5
5
  version: string;
@@ -1,5 +1,5 @@
1
1
  import { CourseConfig } from '@vue-skuilder/common';
2
- import { D as DocType } from './types-legacy-BkOYOR6U.js';
2
+ import { D as DocType } from './types-legacy-DdVjg81H.js';
3
3
 
4
4
  interface StaticCourseManifest {
5
5
  version: string;
@@ -165,4 +165,4 @@ interface QuestionRecord extends CardRecord, Evaluation {
165
165
  priorAttemps: number;
166
166
  }
167
167
 
168
- export { type CardData as C, DocType as D, type Field as F, GuestUsername as G, type QuestionRecord as Q, type SkuilderCourseData as S, type Tag as T, type DisplayableData as a, type CardRecord as b, type CardHistory as c, type QualifiedCardID as d, type TagStub as e, DocTypePrefixes as f, type CourseListData as g, type DataShapeData as h, type QuestionData as i, log as l };
168
+ export { type CardData as C, DocType as D, type Field as F, GuestUsername as G, type QualifiedCardID as Q, type SkuilderCourseData as S, type TagStub as T, type Tag as a, type DisplayableData as b, type CardRecord as c, type QuestionRecord as d, type CardHistory as e, DocTypePrefixes as f, type CourseListData as g, type DataShapeData as h, type QuestionData as i, log as l };
@@ -165,4 +165,4 @@ interface QuestionRecord extends CardRecord, Evaluation {
165
165
  priorAttemps: number;
166
166
  }
167
167
 
168
- export { type CardData as C, DocType as D, type Field as F, GuestUsername as G, type QuestionRecord as Q, type SkuilderCourseData as S, type Tag as T, type DisplayableData as a, type CardRecord as b, type CardHistory as c, type QualifiedCardID as d, type TagStub as e, DocTypePrefixes as f, type CourseListData as g, type DataShapeData as h, type QuestionData as i, log as l };
168
+ export { type CardData as C, DocType as D, type Field as F, GuestUsername as G, type QualifiedCardID as Q, type SkuilderCourseData as S, type TagStub as T, type Tag as a, type DisplayableData as b, type CardRecord as c, type QuestionRecord as d, type CardHistory as e, DocTypePrefixes as f, type CourseListData as g, type DataShapeData as h, type QuestionData as i, log as l };
@@ -1,5 +1,5 @@
1
- export { A as AttachmentData, C as ChunkMetadata, D as DesignDocument, I as IndexMetadata, a as PackedCourseData, P as PackerConfig, S as StaticCourseManifest } from '../../types-D0oQeJAi.cjs';
2
- export { C as CouchDBToStaticPacker } from '../../index-Ktg72jKb.cjs';
1
+ export { A as AttachmentData, C as ChunkMetadata, D as DesignDocument, I as IndexMetadata, a as PackedCourseData, P as PackerConfig, S as StaticCourseManifest } from '../../types-BcWVH4ww.cjs';
2
+ export { C as CouchDBToStaticPacker } from '../../index-BIum9Ue2.cjs';
3
3
  import '@vue-skuilder/common';
4
- import '../../types-legacy-BkOYOR6U.cjs';
4
+ import '../../types-legacy-DdVjg81H.cjs';
5
5
  import 'moment';
@@ -1,5 +1,5 @@
1
- export { A as AttachmentData, C as ChunkMetadata, D as DesignDocument, I as IndexMetadata, a as PackedCourseData, P as PackerConfig, S as StaticCourseManifest } from '../../types-dXWfyz9B.js';
2
- export { C as CouchDBToStaticPacker } from '../../index-CVGehe_t.js';
1
+ export { A as AttachmentData, C as ChunkMetadata, D as DesignDocument, I as IndexMetadata, a as PackedCourseData, P as PackerConfig, S as StaticCourseManifest } from '../../types-DF0JuPbs.js';
2
+ export { C as CouchDBToStaticPacker } from '../../index-C745YB_6.js';
3
3
  import '@vue-skuilder/common';
4
- import '../../types-legacy-BkOYOR6U.js';
4
+ import '../../types-legacy-DdVjg81H.js';
5
5
  import 'moment';
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.2.33",
7
+ "version": "0.2.35",
8
8
  "description": "Database layer for vue-skuilder",
9
9
  "main": "dist/index.js",
10
10
  "module": "dist/index.mjs",
@@ -60,7 +60,7 @@
60
60
  },
61
61
  "dependencies": {
62
62
  "@nilock2/pouchdb-authentication": "^1.0.2",
63
- "@vue-skuilder/common": "0.2.33",
63
+ "@vue-skuilder/common": "0.2.35",
64
64
  "cross-fetch": "^4.1.0",
65
65
  "moment": "^2.29.4",
66
66
  "pouchdb": "^9.0.0",
@@ -75,5 +75,5 @@
75
75
  "vite": "^8.0.0",
76
76
  "vitest": "^4.1.0"
77
77
  },
78
- "stableVersion": "0.2.33"
78
+ "stableVersion": "0.2.35"
79
79
  }
@@ -207,6 +207,16 @@ interface TagGap {
207
207
  * cards and act like a second global rating. The framework may want the
208
208
  * course to say which tags are skills (cf. LP's diagnostics interpreter
209
209
  * `isSkillTag`), e.g. as tag patterns in the strategy config.
210
+ * The admin ELO viewer (in progress, 2026-10) answers the same question for
211
+ * display with its own tag batches (role × namespace). Before tag-aware goes
212
+ * on by default, make that one predicate:
213
+ * - a serializable selector (roles, prefix patterns), beside `tagRoles.ts`
214
+ * in common, so a strategy doc can carry it;
215
+ * - an `EloDistanceConfig` field for it, read by `tagAwareGap`;
216
+ * - `tagAwareGap` moved to a pure module (this file imports `core`, which
217
+ * the diagnostics entry can't), so the viewer can show what the filter
218
+ * would compute;
219
+ * - the viewer's default batch read from the course's eloDistance config.
210
220
  * 3. New cards matter most, and that dump couldn't show them. An unseen
211
221
  * card's tag ratings fall back to its global, so for new cards this reads
212
222
  * "card global vs the learner's rating on that skill". Measuring it needs a
@@ -1,4 +1,11 @@
1
- import { CourseConfig, DataShape, NameSpacer, toZodJSON } from '@vue-skuilder/common';
1
+ import {
2
+ CourseConfig,
3
+ DataShape,
4
+ NameSpacer,
5
+ SeedMeta,
6
+ toCourseElo,
7
+ toZodJSON,
8
+ } from '@vue-skuilder/common';
2
9
  import { CourseDBInterface } from './core/interfaces/courseDB.js';
3
10
  import { logger } from './util/logger.js';
4
11
 
@@ -12,6 +19,7 @@ export interface CustomQuestionsData {
12
19
  dataShapes?: DataShape[];
13
20
  views?: { name?: string }[];
14
21
  seedData?: unknown[];
22
+ seedMeta?: (item: unknown) => SeedMeta;
15
23
  }[]; // Question class constructors
16
24
  dataShapes: DataShape[]; // DataShape definitions for studio-ui
17
25
  views: { name?: string }[]; // Vue components for rendering
@@ -36,6 +44,7 @@ export interface ProcessedQuestionData {
36
44
  dataShapes?: DataShape[];
37
45
  views?: { name?: string }[];
38
46
  seedData?: unknown[];
47
+ seedMeta?: (item: unknown) => SeedMeta;
39
48
  };
40
49
  dataShapes: DataShape[];
41
50
  views: { name?: string }[];
@@ -388,19 +397,22 @@ export async function registerSeedData(
388
397
  logger.info(`Registering seed data for question: ${question.name}`);
389
398
 
390
399
  try {
391
- const seedDataPromises = question.questionClass.seedData
392
- .filter(() => question.dataShapes.length > 0)
393
- .map((seedDataItem: unknown) =>
394
- courseDB.addNote(
400
+ if (question.dataShapes.length > 0) {
401
+ // One note at a time: notes sharing a tag would race on the tag doc, and a lost
402
+ // tag write aborts the note's remaining cards.
403
+ for (const seedDataItem of question.questionClass.seedData) {
404
+ const meta = question.questionClass.seedMeta?.(seedDataItem) ?? {};
405
+ await courseDB.addNote(
395
406
  question.course,
396
407
  question.dataShapes[0],
397
408
  seedDataItem,
398
409
  username,
399
- []
400
- )
401
- );
402
-
403
- await Promise.all(seedDataPromises);
410
+ meta.tags ?? [],
411
+ undefined,
412
+ meta.elo !== undefined ? toCourseElo(meta.elo) : undefined
413
+ );
414
+ }
415
+ }
404
416
  logger.info(`Seed data registered for question: ${question.name}`);
405
417
  } catch (error) {
406
418
  logger.warn(
@@ -13,6 +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
17
 
17
18
  /**
18
19
  * Course-supplied meaning for the generic views. Every member is optional and
@@ -30,6 +31,11 @@ export interface DiagnosticsInterpreters {
30
31
  snapshotMetrics?(snapshot: SessionStateSnapshot): Record<string, number>;
31
32
  /** Which `snapshotMetrics` labels count as progress (for `stalled`). Default: none. */
32
33
  progressMetrics?: string[];
34
+ /**
35
+ * Named tag batches for the ELO view, offered beside the namespace × role
36
+ * batches it finds on its own. Default: none.
37
+ */
38
+ tagBatches?: TagBatch[];
33
39
  }
34
40
 
35
41
  export const isSkillTag = (i: DiagnosticsInterpreters | undefined, tag: string): boolean =>
@@ -15,6 +15,7 @@ export * from './loader';
15
15
  export * from './derive';
16
16
  export * from './text';
17
17
  export * from './pipeline';
18
+ export * from './tagElo';
18
19
  export type {
19
20
  SessionEloEvent,
20
21
  SessionStateSnapshot,
@@ -0,0 +1,257 @@
1
+ /**
2
+ * A learner's per-tag ELO, read for display: one row per tag on their course
3
+ * registration, the batches a view filters those rows by, and each rating's
4
+ * trajectory through the dataset's sessions.
5
+ *
6
+ * The source is the learner's `CourseElo` (global + per-tag `{score, count,
7
+ * recent}`). Session `eloEvents` add trajectories (per-tag before → after,
8
+ * from when sessions began recording them); card-history records add when a
9
+ * tag was first and last named by a response.
10
+ */
11
+ import {
12
+ COUNT_ONLY_SCORE,
13
+ isCountOnlyTag,
14
+ tagRole,
15
+ type CourseElo,
16
+ type EloRank,
17
+ type TagPresentation,
18
+ type TagRole,
19
+ } from '@vue-skuilder/common';
20
+ import type { LearnerDataset } from './dataset';
21
+
22
+ // ============================================================================
23
+ // Batches
24
+ // ============================================================================
25
+
26
+ /**
27
+ * A set of tags to view together, as data: every criterion given must hold.
28
+ *
29
+ * Plain data on purpose. Choosing which tags count is the same question the
30
+ * tag-aware ELO distance filter has open (`tagAwareGap` in
31
+ * `filters/eloDistance.ts`); a serializable batch can later move into a
32
+ * strategy config and serve both.
33
+ */
34
+ export interface TagBatch {
35
+ id: string;
36
+ label: string;
37
+ /** Tag namespaces (see {@link tagNamespace}); `''` is tags with none. */
38
+ namespaces?: string[];
39
+ /** Tag roles; `'none'` is tags without one. */
40
+ roles?: Array<TagRole | 'none'>;
41
+ /** Tags starting with any of these. */
42
+ prefixes?: string[];
43
+ /** Tags starting with any of these are left out. */
44
+ excludePrefixes?: string[];
45
+ }
46
+
47
+ /** What precedes a tag's role segment: `gpc` in `gpc:exercise:x`, `''` in `expose:x`. */
48
+ function beforeRole(tag: string, role: TagRole): string {
49
+ // tagRole takes the leftmost role segment; the leftmost of this one is it.
50
+ const match = new RegExp(`(^|:)${role}:(?=.)`).exec(tag);
51
+ return match ? tag.slice(0, match.index) : '';
52
+ }
53
+
54
+ /**
55
+ * The colon-delimited segments that scope a tag: what comes before its role
56
+ * (`gpc:exercise:x` → `gpc`), else its first segment (`concept:match:x` →
57
+ * `concept`). `''` for a tag with neither (`femur`, `expose:x`).
58
+ */
59
+ export function tagNamespace(tag: string): string {
60
+ const role = tagRole(tag);
61
+ if (role) return beforeRole(tag, role);
62
+ const colon = tag.indexOf(':');
63
+ return colon > 0 ? tag.slice(0, colon) : '';
64
+ }
65
+
66
+ export function matchesTagBatch(tag: string, batch: TagBatch, role = tagRole(tag)): boolean {
67
+ if (batch.namespaces && !batch.namespaces.includes(tagNamespace(tag))) return false;
68
+ if (batch.roles && !batch.roles.includes(role ?? 'none')) return false;
69
+ if (batch.prefixes && !batch.prefixes.some((p) => tag.startsWith(p))) return false;
70
+ if (batch.excludePrefixes?.some((p) => tag.startsWith(p))) return false;
71
+ return true;
72
+ }
73
+
74
+ /** The namespace × role batch a tag falls in, e.g. `gpc:exercise`, `concept`, or `(no namespace)`. */
75
+ export function tagGroupBatch(tag: string): TagBatch {
76
+ const role = tagRole(tag);
77
+ const ns = tagNamespace(tag);
78
+ const id = [ns, role].filter(Boolean).join(':') || '(no namespace)';
79
+ return { id, label: id, namespaces: [ns], roles: [role ?? 'none'] };
80
+ }
81
+
82
+ // ============================================================================
83
+ // Rows
84
+ // ============================================================================
85
+
86
+ export interface TagEloRow {
87
+ tag: string;
88
+ role: TagRole | null;
89
+ namespace: string;
90
+ /** Id of the tag's {@link tagGroupBatch}. */
91
+ group: string;
92
+ /**
93
+ * The learner's rating on the tag. Null for a count-only tag: a bookkeeping
94
+ * role (`intro`, `expose`), or the count-only sentinel.
95
+ */
96
+ score: number | null;
97
+ /**
98
+ * A real score stored on a bookkeeping-role tag, from before roles were
99
+ * count-only. Not a rating: the framework ignores it.
100
+ */
101
+ staleScore?: number;
102
+ count: number;
103
+ /** `score − global`; null when score is. */
104
+ vsGlobal: number | null;
105
+ /** The rating's ring buffer of recent first attempts, oldest first. */
106
+ recent: TagPresentation[];
107
+ /** First-attempt correct entries in `recent`. */
108
+ recentOk: number;
109
+ /** First and last response whose per-tag performance named the tag, or a recent entry. */
110
+ firstSeen: string | null;
111
+ lastSeen: string | null;
112
+ /** ELO events on the tag in the dataset's sessions. */
113
+ events: number;
114
+ }
115
+
116
+ export interface EloPoint {
117
+ at: string;
118
+ score: number;
119
+ }
120
+
121
+ export interface TagEloView {
122
+ global: EloRank;
123
+ /** Every tag on the registration, highest score first, count-only tags last. */
124
+ rows: TagEloRow[];
125
+ /** The namespace × role batches present, graded ones first. */
126
+ groups: TagBatch[];
127
+ /**
128
+ * Ratings through the dataset's ELO events: each series starts at its first
129
+ * event's `before`, has a point per event, and ends at the current score at
130
+ * `asOf`. A move between recorded events (a session that didn't save its
131
+ * events) shows as a step at the next event, or at `asOf`. Tags with no
132
+ * events have no series; count-only tags have none.
133
+ */
134
+ series: { global: EloPoint[]; tags: Record<string, EloPoint[]> };
135
+ /** The first ELO event, or null: trajectories start here. */
136
+ seriesFrom: string | null;
137
+ }
138
+
139
+ /** The learner's `CourseElo` for the dataset's course, or null if not registered. */
140
+ export function learnerCourseElo(ds: LearnerDataset): CourseElo | null {
141
+ const elo = ds.registration?.courses?.find((c) => c.courseID === ds.courseId)?.elo;
142
+ if (typeof elo === 'number') return { global: { score: elo, count: 0 }, tags: {}, misc: {} };
143
+ if (!elo || typeof elo !== 'object' || !elo.global) return null;
144
+ return { ...elo, tags: elo.tags ?? {}, misc: elo.misc ?? {} };
145
+ }
146
+
147
+ function minIso(a: string | null, b: string): string {
148
+ return a === null || b < a ? b : a;
149
+ }
150
+
151
+ function maxIso(a: string | null, b: string): string {
152
+ return a === null || b > a ? b : a;
153
+ }
154
+
155
+ /**
156
+ * Extend a series by one event. A `before` that differs from where the line
157
+ * stands gets its own point: the rating moved between recorded events (a
158
+ * session that closed without saving its events), shown as a step here.
159
+ */
160
+ function step(line: EloPoint[], at: string, before: number, after: number): void {
161
+ if (before !== COUNT_ONLY_SCORE && line[line.length - 1]?.score !== before)
162
+ line.push({ at, score: before });
163
+ line.push({ at, score: after });
164
+ }
165
+
166
+ /** 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 {
168
+ const elo = learnerCourseElo(ds);
169
+ if (!elo) return null;
170
+
171
+ // When each tag was named by a response, from card history.
172
+ const seen = new Map<string, { first: string | null; last: string | null }>();
173
+ for (const h of ds.cardHistories) {
174
+ for (const r of h.records) {
175
+ const p = r.performance as unknown;
176
+ if (!p || typeof p !== 'object') continue;
177
+ for (const tag of Object.keys(p)) {
178
+ if (tag === '_global') continue;
179
+ const s = seen.get(tag) ?? { first: null, last: null };
180
+ s.first = minIso(s.first, r.timeStamp);
181
+ s.last = maxIso(s.last, r.timeStamp);
182
+ seen.set(tag, s);
183
+ }
184
+ }
185
+ }
186
+
187
+ // Trajectories, from session ELO events in time order.
188
+ const events = ds.sessions
189
+ .flatMap((s) => s.eloEvents ?? [])
190
+ .sort((a, b) => a.at.localeCompare(b.at));
191
+ const globalSeries: EloPoint[] = [];
192
+ const tagSeries: Record<string, EloPoint[]> = {};
193
+ const eventCounts = new Map<string, number>();
194
+ for (const e of events) {
195
+ step(globalSeries, e.at, e.global.before, e.global.after);
196
+ for (const [tag, t] of Object.entries(e.tags ?? {})) {
197
+ eventCounts.set(tag, (eventCounts.get(tag) ?? 0) + 1);
198
+ if (t.score === null || isCountOnlyTag(tag) || t.after === COUNT_ONLY_SCORE) continue;
199
+ step((tagSeries[tag] ??= []), e.at, t.before, t.after);
200
+ }
201
+ }
202
+
203
+ const rows: TagEloRow[] = Object.entries(elo.tags).map(([tag, rank]) => {
204
+ const role = tagRole(tag);
205
+ const countOnly = isCountOnlyTag(tag) || rank.score === COUNT_ONLY_SCORE;
206
+ const score = countOnly ? null : rank.score;
207
+ const recent = rank.recent ?? [];
208
+ let { first, last } = seen.get(tag) ?? { first: null, last: null };
209
+ for (const p of recent) {
210
+ first = minIso(first, p.at);
211
+ last = maxIso(last, p.at);
212
+ }
213
+ return {
214
+ tag,
215
+ role,
216
+ namespace: tagNamespace(tag),
217
+ group: tagGroupBatch(tag).id,
218
+ score,
219
+ ...(countOnly && rank.score !== COUNT_ONLY_SCORE ? { staleScore: rank.score } : {}),
220
+ count: rank.count,
221
+ vsGlobal: score === null ? null : score - elo.global.score,
222
+ recent,
223
+ recentOk: recent.filter((p) => p.ok).length,
224
+ firstSeen: first,
225
+ lastSeen: last,
226
+ events: eventCounts.get(tag) ?? 0,
227
+ };
228
+ });
229
+ rows.sort((a, b) =>
230
+ a.score === null || b.score === null
231
+ ? Number(a.score === null) - Number(b.score === null) || a.tag.localeCompare(b.tag)
232
+ : b.score - a.score || a.tag.localeCompare(b.tag)
233
+ );
234
+
235
+ // Close each line at the current rating, so it reaches `asOf` and shows any
236
+ // move the events didn't record.
237
+ if (globalSeries.length > 0) globalSeries.push({ at: ds.asOf, score: elo.global.score });
238
+ for (const row of rows) {
239
+ const line = tagSeries[row.tag];
240
+ if (line && row.score !== null) line.push({ at: ds.asOf, score: row.score });
241
+ }
242
+
243
+ const groups = new Map<string, TagBatch>();
244
+ for (const row of rows) if (!groups.has(row.group)) groups.set(row.group, tagGroupBatch(row.tag));
245
+ const countOnlyGroup = (b: TagBatch): boolean =>
246
+ b.roles?.some((r) => r === 'intro' || r === 'expose') ?? false;
247
+
248
+ return {
249
+ global: elo.global,
250
+ rows,
251
+ groups: [...groups.values()].sort(
252
+ (a, b) => Number(countOnlyGroup(a)) - Number(countOnlyGroup(b)) || a.id.localeCompare(b.id)
253
+ ),
254
+ series: { global: globalSeries, tags: tagSeries },
255
+ seriesFrom: events[0]?.at ?? null,
256
+ };
257
+ }
@@ -8,6 +8,12 @@ import { logger } from '../util/logger';
8
8
  type Moment = moment.Moment;
9
9
  const duration = moment.duration;
10
10
 
11
+ /**
12
+ * Longest interval (seconds) after a correct answer flagged `fluent: false`.
13
+ * Matches the 20h floor in `lastSuccessfulInterval`: due again next day.
14
+ */
15
+ const SLOW_CORRECT_MAX_INTERVAL = 20 * 60 * 60;
16
+
11
17
  export interface DocumentUpdater {
12
18
  update<T extends PouchDB.Core.Document<object>>(id: string, update: Update<T>): Promise<T>;
13
19
  }
@@ -50,6 +56,7 @@ function newQuestionInterval(user: DocumentUpdater, cardHistory: CardHistory<Que
50
56
  cardHistory.lapses = getLapses(cardHistory.records);
51
57
  cardHistory.streak = getStreak(cardHistory.records);
52
58
 
59
+ let ret = interval;
53
60
  if (
54
61
  cardHistory.lapses &&
55
62
  cardHistory.streak &&
@@ -58,15 +65,21 @@ function newQuestionInterval(user: DocumentUpdater, cardHistory: CardHistory<Que
58
65
  ) {
59
66
  // weighted average of best-ever performance vs current performance, based
60
67
  // on how often the card has been failed, and the current streak of success
61
- const ret =
68
+ ret =
62
69
  (cardHistory.lapses * interval + cardHistory.streak * cardHistory.bestInterval) /
63
70
  (cardHistory.lapses + cardHistory.streak);
64
71
  logger.debug(`Weighted average interval calculation:
65
72
  \t(${cardHistory.lapses} * ${interval} + ${cardHistory.streak} * ${cardHistory.bestInterval}) / (${cardHistory.lapses} + ${cardHistory.streak}) = ${ret}`);
66
- return ret;
67
- } else {
68
- return interval;
69
73
  }
74
+
75
+ if (currentAttempt.fluent === false) {
76
+ // Correct but too slow: keep it coming back until it's fast on a first presentation.
77
+ logger.debug(
78
+ `Correct but not fluent: capping interval ${ret}s at ${SLOW_CORRECT_MAX_INTERVAL}s`
79
+ );
80
+ return Math.min(ret, SLOW_CORRECT_MAX_INTERVAL);
81
+ }
82
+ return ret;
70
83
  } else {
71
84
  return 0;
72
85
  }
@@ -75,13 +88,17 @@ function newQuestionInterval(user: DocumentUpdater, cardHistory: CardHistory<Que
75
88
  /**
76
89
  * Returns the amount of time, in seconds, of the most recent successful
77
90
  * interval for this card. An interval is successful if the user answers
78
- * a question correctly on the first attempt.
91
+ * a question correctly on the first attempt, and not flagged as too slow.
79
92
  *
80
93
  * @param cardHistory The record of user attempts with the question
81
94
  */
82
95
  function lastSuccessfulInterval(cardHistory: QuestionRecord[]): number {
83
96
  for (let i = cardHistory.length - 1; i >= 1; i--) {
84
- if (cardHistory[i].priorAttemps === 0 && cardHistory[i].isCorrect) {
97
+ if (
98
+ cardHistory[i].priorAttemps === 0 &&
99
+ cardHistory[i].isCorrect &&
100
+ cardHistory[i].fluent !== false
101
+ ) {
85
102
  const lastInterval = secondsBetween(cardHistory[i - 1].timeStamp, cardHistory[i].timeStamp);
86
103
  const ret = Math.max(lastInterval, 20 * 60 * 60);
87
104
  logger.debug(`Last interval w/ this card was: ${lastInterval}s, returning ${ret}s`);