@vue-skuilder/db 0.3.2 → 0.3.3

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.
@@ -1,5 +1,5 @@
1
1
  import "../_virtual/_rolldown/runtime.mjs";
2
- import { COUNT_ONLY_SCORE, isCountOnlyTag, tagRole } from "@vue-skuilder/common";
2
+ import { COUNT_ONLY_SCORE, courseSecurity, isCountOnlyTag, presentationOk, skillNeed, tagRole } from "@vue-skuilder/common";
3
3
  //#region src/diagnostics/tagElo.ts
4
4
  /**
5
5
  * A learner's per-tag ELO, read for display: one row per tag on their course
@@ -86,9 +86,13 @@ function step(line, at, before, after) {
86
86
  });
87
87
  }
88
88
  /** The learner's per-tag ELO for display. Null if the dataset has no registration for its course. */
89
- function tagEloView(ds) {
89
+ function tagEloView(ds, options = {}) {
90
90
  const elo = learnerCourseElo(ds);
91
91
  if (!elo) return null;
92
+ const security = courseSecurity(elo, options.security);
93
+ const securityByTag = new Map(security.tags.map((s) => [s.tag, s]));
94
+ const need = skillNeed(elo, options.need);
95
+ const needByTag = new Map(need.skills.map((s) => [s.tag, s]));
92
96
  const seen = /* @__PURE__ */ new Map();
93
97
  for (const h of ds.cardHistories) for (const r of h.records) {
94
98
  const p = r.performance;
@@ -139,7 +143,12 @@ function tagEloView(ds) {
139
143
  count: rank.count,
140
144
  vsGlobal: score === null ? null : score - elo.global.score,
141
145
  recent,
142
- recentOk: recent.filter((p) => p.ok).length,
146
+ recentOk: recent.filter(presentationOk).length,
147
+ ...securityByTag.has(tag) ? { security: securityByTag.get(tag) } : {},
148
+ ...needByTag.has(tag) ? {
149
+ need: needByTag.get(tag).need,
150
+ deficit: needByTag.get(tag).deficit
151
+ } : {},
143
152
  firstSeen: first,
144
153
  lastSeen: last,
145
154
  events: eventCounts.get(tag) ?? 0
@@ -168,7 +177,14 @@ function tagEloView(ds) {
168
177
  global: globalSeries,
169
178
  tags: tagSeries
170
179
  },
171
- seriesFrom: events[0]?.at ?? null
180
+ seriesFrom: events[0]?.at ?? null,
181
+ skillReference: need.reference,
182
+ security: {
183
+ secure: security.secure,
184
+ shaky: security.shaky,
185
+ unproven: security.unproven,
186
+ debt: security.debt
187
+ }
172
188
  };
173
189
  }
174
190
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"tagElo.mjs","names":[],"sources":["../../src/diagnostics/tagElo.ts"],"sourcesContent":["/**\n * A learner's per-tag ELO, read for display: one row per tag on their course\n * registration, the batches a view filters those rows by, and each rating's\n * trajectory through the dataset's sessions.\n *\n * The source is the learner's `CourseElo` (global + per-tag `{score, count,\n * recent}`). Session `eloEvents` add trajectories (per-tag before → after,\n * from when sessions began recording them); card-history records add when a\n * tag was first and last named by a response.\n */\nimport {\n COUNT_ONLY_SCORE,\n isCountOnlyTag,\n tagRole,\n type CourseElo,\n type EloRank,\n type TagPresentation,\n type TagRole,\n} from '@vue-skuilder/common';\nimport type { LearnerDataset } from './dataset';\n\n// ============================================================================\n// Batches\n// ============================================================================\n\n/**\n * A set of tags to view together, as data: every criterion given must hold.\n *\n * Plain data on purpose. Choosing which tags count is the same question the\n * tag-aware ELO distance filter has open (`tagAwareGap` in\n * `filters/eloDistance.ts`); a serializable batch can later move into a\n * strategy config and serve both.\n */\nexport interface TagBatch {\n id: string;\n label: string;\n /** Tag namespaces (see {@link tagNamespace}); `''` is tags with none. */\n namespaces?: string[];\n /** Tag roles; `'none'` is tags without one. */\n roles?: Array<TagRole | 'none'>;\n /** Tags starting with any of these. */\n prefixes?: string[];\n /** Tags starting with any of these are left out. */\n excludePrefixes?: string[];\n}\n\n/** What precedes a tag's role segment: `gpc` in `gpc:exercise:x`, `''` in `expose:x`. */\nfunction beforeRole(tag: string, role: TagRole): string {\n // tagRole takes the leftmost role segment; the leftmost of this one is it.\n const match = new RegExp(`(^|:)${role}:(?=.)`).exec(tag);\n return match ? tag.slice(0, match.index) : '';\n}\n\n/**\n * The colon-delimited segments that scope a tag: what comes before its role\n * (`gpc:exercise:x` → `gpc`), else its first segment (`concept:match:x` →\n * `concept`). `''` for a tag with neither (`femur`, `expose:x`).\n */\nexport function tagNamespace(tag: string): string {\n const role = tagRole(tag);\n if (role) return beforeRole(tag, role);\n const colon = tag.indexOf(':');\n return colon > 0 ? tag.slice(0, colon) : '';\n}\n\nexport function matchesTagBatch(tag: string, batch: TagBatch, role = tagRole(tag)): boolean {\n if (batch.namespaces && !batch.namespaces.includes(tagNamespace(tag))) return false;\n if (batch.roles && !batch.roles.includes(role ?? 'none')) return false;\n if (batch.prefixes && !batch.prefixes.some((p) => tag.startsWith(p))) return false;\n if (batch.excludePrefixes?.some((p) => tag.startsWith(p))) return false;\n return true;\n}\n\n/** The namespace × role batch a tag falls in, e.g. `gpc:exercise`, `concept`, or `(no namespace)`. */\nexport function tagGroupBatch(tag: string): TagBatch {\n const role = tagRole(tag);\n const ns = tagNamespace(tag);\n const id = [ns, role].filter(Boolean).join(':') || '(no namespace)';\n return { id, label: id, namespaces: [ns], roles: [role ?? 'none'] };\n}\n\n// ============================================================================\n// Rows\n// ============================================================================\n\nexport interface TagEloRow {\n tag: string;\n role: TagRole | null;\n namespace: string;\n /** Id of the tag's {@link tagGroupBatch}. */\n group: string;\n /**\n * The learner's rating on the tag. Null for a count-only tag: a bookkeeping\n * role (`intro`, `expose`), or the count-only sentinel.\n */\n score: number | null;\n /**\n * A real score stored on a bookkeeping-role tag, from before roles were\n * count-only. Not a rating: the framework ignores it.\n */\n staleScore?: number;\n count: number;\n /** `score − global`; null when score is. */\n vsGlobal: number | null;\n /** The rating's ring buffer of recent first attempts, oldest first. */\n recent: TagPresentation[];\n /** First-attempt correct entries in `recent`. */\n recentOk: number;\n /** First and last response whose per-tag performance named the tag, or a recent entry. */\n firstSeen: string | null;\n lastSeen: string | null;\n /** ELO events on the tag in the dataset's sessions. */\n events: number;\n}\n\nexport interface EloPoint {\n at: string;\n score: number;\n}\n\nexport interface TagEloView {\n global: EloRank;\n /** Every tag on the registration, highest score first, count-only tags last. */\n rows: TagEloRow[];\n /** The namespace × role batches present, graded ones first. */\n groups: TagBatch[];\n /**\n * Ratings through the dataset's ELO events: each series starts at its first\n * event's `before`, has a point per event, and ends at the current score at\n * `asOf`. A move between recorded events (a session that didn't save its\n * events) shows as a step at the next event, or at `asOf`. Tags with no\n * events have no series; count-only tags have none.\n */\n series: { global: EloPoint[]; tags: Record<string, EloPoint[]> };\n /** The first ELO event, or null: trajectories start here. */\n seriesFrom: string | null;\n}\n\n/** The learner's `CourseElo` for the dataset's course, or null if not registered. */\nexport function learnerCourseElo(ds: LearnerDataset): CourseElo | null {\n const elo = ds.registration?.courses?.find((c) => c.courseID === ds.courseId)?.elo;\n if (typeof elo === 'number') return { global: { score: elo, count: 0 }, tags: {}, misc: {} };\n if (!elo || typeof elo !== 'object' || !elo.global) return null;\n return { ...elo, tags: elo.tags ?? {}, misc: elo.misc ?? {} };\n}\n\nfunction minIso(a: string | null, b: string): string {\n return a === null || b < a ? b : a;\n}\n\nfunction maxIso(a: string | null, b: string): string {\n return a === null || b > a ? b : a;\n}\n\n/**\n * Extend a series by one event. A `before` that differs from where the line\n * stands gets its own point: the rating moved between recorded events (a\n * session that closed without saving its events), shown as a step here.\n */\nfunction step(line: EloPoint[], at: string, before: number, after: number): void {\n if (before !== COUNT_ONLY_SCORE && line[line.length - 1]?.score !== before)\n line.push({ at, score: before });\n line.push({ at, score: after });\n}\n\n/** The learner's per-tag ELO for display. Null if the dataset has no registration for its course. */\nexport function tagEloView(ds: LearnerDataset): TagEloView | null {\n const elo = learnerCourseElo(ds);\n if (!elo) return null;\n\n // When each tag was named by a response, from card history.\n const seen = new Map<string, { first: string | null; last: string | null }>();\n for (const h of ds.cardHistories) {\n for (const r of h.records) {\n const p = r.performance as unknown;\n if (!p || typeof p !== 'object') continue;\n for (const tag of Object.keys(p)) {\n if (tag === '_global') continue;\n const s = seen.get(tag) ?? { first: null, last: null };\n s.first = minIso(s.first, r.timeStamp);\n s.last = maxIso(s.last, r.timeStamp);\n seen.set(tag, s);\n }\n }\n }\n\n // Trajectories, from session ELO events in time order.\n const events = ds.sessions\n .flatMap((s) => s.eloEvents ?? [])\n .sort((a, b) => a.at.localeCompare(b.at));\n const globalSeries: EloPoint[] = [];\n const tagSeries: Record<string, EloPoint[]> = {};\n const eventCounts = new Map<string, number>();\n for (const e of events) {\n step(globalSeries, e.at, e.global.before, e.global.after);\n for (const [tag, t] of Object.entries(e.tags ?? {})) {\n eventCounts.set(tag, (eventCounts.get(tag) ?? 0) + 1);\n if (t.score === null || isCountOnlyTag(tag) || t.after === COUNT_ONLY_SCORE) continue;\n step((tagSeries[tag] ??= []), e.at, t.before, t.after);\n }\n }\n\n const rows: TagEloRow[] = Object.entries(elo.tags).map(([tag, rank]) => {\n const role = tagRole(tag);\n const countOnly = isCountOnlyTag(tag) || rank.score === COUNT_ONLY_SCORE;\n const score = countOnly ? null : rank.score;\n const recent = rank.recent ?? [];\n let { first, last } = seen.get(tag) ?? { first: null, last: null };\n for (const p of recent) {\n first = minIso(first, p.at);\n last = maxIso(last, p.at);\n }\n return {\n tag,\n role,\n namespace: tagNamespace(tag),\n group: tagGroupBatch(tag).id,\n score,\n ...(countOnly && rank.score !== COUNT_ONLY_SCORE ? { staleScore: rank.score } : {}),\n count: rank.count,\n vsGlobal: score === null ? null : score - elo.global.score,\n recent,\n recentOk: recent.filter((p) => p.ok).length,\n firstSeen: first,\n lastSeen: last,\n events: eventCounts.get(tag) ?? 0,\n };\n });\n rows.sort((a, b) =>\n a.score === null || b.score === null\n ? Number(a.score === null) - Number(b.score === null) || a.tag.localeCompare(b.tag)\n : b.score - a.score || a.tag.localeCompare(b.tag)\n );\n\n // Close each line at the current rating, so it reaches `asOf` and shows any\n // move the events didn't record.\n if (globalSeries.length > 0) globalSeries.push({ at: ds.asOf, score: elo.global.score });\n for (const row of rows) {\n const line = tagSeries[row.tag];\n if (line && row.score !== null) line.push({ at: ds.asOf, score: row.score });\n }\n\n const groups = new Map<string, TagBatch>();\n for (const row of rows) if (!groups.has(row.group)) groups.set(row.group, tagGroupBatch(row.tag));\n const countOnlyGroup = (b: TagBatch): boolean =>\n b.roles?.some((r) => r === 'intro' || r === 'expose') ?? false;\n\n return {\n global: elo.global,\n rows,\n groups: [...groups.values()].sort(\n (a, b) => Number(countOnlyGroup(a)) - Number(countOnlyGroup(b)) || a.id.localeCompare(b.id)\n ),\n series: { global: globalSeries, tags: tagSeries },\n seriesFrom: events[0]?.at ?? null,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AA+CA,SAAS,WAAW,KAAa,MAAuB;CAEtD,MAAM,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,CAAC,KAAK,IAAI;AACxD,QAAO,QAAQ,IAAI,MAAM,GAAG,MAAM,MAAM,GAAG;;;;;;;AAQ7C,SAAgB,aAAa,KAAqB;CAChD,MAAM,OAAO,QAAQ,IAAI;AACzB,KAAI,KAAM,QAAO,WAAW,KAAK,KAAK;CACtC,MAAM,QAAQ,IAAI,QAAQ,IAAI;AAC9B,QAAO,QAAQ,IAAI,IAAI,MAAM,GAAG,MAAM,GAAG;;AAG3C,SAAgB,gBAAgB,KAAa,OAAiB,OAAO,QAAQ,IAAI,EAAW;AAC1F,KAAI,MAAM,cAAc,CAAC,MAAM,WAAW,SAAS,aAAa,IAAI,CAAC,CAAE,QAAO;AAC9E,KAAI,MAAM,SAAS,CAAC,MAAM,MAAM,SAAS,QAAQ,OAAO,CAAE,QAAO;AACjE,KAAI,MAAM,YAAY,CAAC,MAAM,SAAS,MAAM,MAAM,IAAI,WAAW,EAAE,CAAC,CAAE,QAAO;AAC7E,KAAI,MAAM,iBAAiB,MAAM,MAAM,IAAI,WAAW,EAAE,CAAC,CAAE,QAAO;AAClE,QAAO;;;AAIT,SAAgB,cAAc,KAAuB;CACnD,MAAM,OAAO,QAAQ,IAAI;CACzB,MAAM,KAAK,aAAa,IAAI;CAC5B,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,QAAQ,CAAC,KAAK,IAAI,I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AAE,QAAQ;GAAc,MAAM;GAAW;EACjD,YAAY,OAAO,IAAI,MAAM;EAC9B"}
1
+ {"version":3,"file":"tagElo.mjs","names":[],"sources":["../../src/diagnostics/tagElo.ts"],"sourcesContent":["/**\n * A learner's per-tag ELO, read for display: one row per tag on their course\n * registration, the batches a view filters those rows by, and each rating's\n * trajectory through the dataset's sessions.\n *\n * The source is the learner's `CourseElo` (global + per-tag `{score, count,\n * recent}`). Session `eloEvents` add trajectories (per-tag before → after,\n * from when sessions began recording them); card-history records add when a\n * tag was first and last named by a response.\n */\nimport {\n COUNT_ONLY_SCORE,\n courseSecurity,\n isCountOnlyTag,\n presentationOk,\n skillNeed,\n tagRole,\n type CourseElo,\n type CourseSecurity,\n type SkillNeedConfig,\n type TagSecurity,\n type TagSecurityConfig,\n type TagSelector,\n type EloRank,\n type TagPresentation,\n type TagRole,\n} from '@vue-skuilder/common';\nimport type { LearnerDataset } from './dataset';\n\n// ============================================================================\n// Batches\n// ============================================================================\n\n/**\n * A set of tags to view together, as data: every criterion given must hold.\n *\n * Plain data on purpose. Choosing which tags count is the same question the\n * tag-aware ELO distance filter has open (`tagAwareGap` in\n * `filters/eloDistance.ts`); a serializable batch can later move into a\n * strategy config and serve both.\n */\nexport interface TagBatch {\n id: string;\n label: string;\n /** Tag namespaces (see {@link tagNamespace}); `''` is tags with none. */\n namespaces?: string[];\n /** Tag roles; `'none'` is tags without one. */\n roles?: Array<TagRole | 'none'>;\n /** Tags starting with any of these. */\n prefixes?: string[];\n /** Tags starting with any of these are left out. */\n excludePrefixes?: string[];\n}\n\n/** What precedes a tag's role segment: `gpc` in `gpc:exercise:x`, `''` in `expose:x`. */\nfunction beforeRole(tag: string, role: TagRole): string {\n // tagRole takes the leftmost role segment; the leftmost of this one is it.\n const match = new RegExp(`(^|:)${role}:(?=.)`).exec(tag);\n return match ? tag.slice(0, match.index) : '';\n}\n\n/**\n * The colon-delimited segments that scope a tag: what comes before its role\n * (`gpc:exercise:x` → `gpc`), else its first segment (`concept:match:x` →\n * `concept`). `''` for a tag with neither (`femur`, `expose:x`).\n */\nexport function tagNamespace(tag: string): string {\n const role = tagRole(tag);\n if (role) return beforeRole(tag, role);\n const colon = tag.indexOf(':');\n return colon > 0 ? tag.slice(0, colon) : '';\n}\n\nexport function matchesTagBatch(tag: string, batch: TagBatch, role = tagRole(tag)): boolean {\n if (batch.namespaces && !batch.namespaces.includes(tagNamespace(tag))) return false;\n if (batch.roles && !batch.roles.includes(role ?? 'none')) return false;\n if (batch.prefixes && !batch.prefixes.some((p) => tag.startsWith(p))) return false;\n if (batch.excludePrefixes?.some((p) => tag.startsWith(p))) return false;\n return true;\n}\n\n/** The namespace × role batch a tag falls in, e.g. `gpc:exercise`, `concept`, or `(no namespace)`. */\nexport function tagGroupBatch(tag: string): TagBatch {\n const role = tagRole(tag);\n const ns = tagNamespace(tag);\n const id = [ns, role].filter(Boolean).join(':') || '(no namespace)';\n return { id, label: id, namespaces: [ns], roles: [role ?? 'none'] };\n}\n\n// ============================================================================\n// Rows\n// ============================================================================\n\nexport interface TagEloRow {\n tag: string;\n role: TagRole | null;\n namespace: string;\n /** Id of the tag's {@link tagGroupBatch}. */\n group: string;\n /**\n * The learner's rating on the tag. Null for a count-only tag: a bookkeeping\n * role (`intro`, `expose`), or the count-only sentinel.\n */\n score: number | null;\n /**\n * A real score stored on a bookkeeping-role tag, from before roles were\n * count-only. Not a rating: the framework ignores it.\n */\n staleScore?: number;\n count: number;\n /** `score − global`; null when score is. */\n vsGlobal: number | null;\n /** The rating's ring buffer of recent first attempts, oldest first. */\n recent: TagPresentation[];\n /** Entries in `recent` right on this tag (per-tag, not the card's ok). */\n recentOk: number;\n /** Secure / shaky / unproven, for tags the security selector picks (met exercise tags by default). */\n security?: TagSecurity;\n /** 0–1 need from skillNeed; absent for tags that don't qualify as skills. */\n need?: number;\n /** Skill reference − rating; absent with need. */\n deficit?: number;\n /** First and last response whose per-tag performance named the tag, or a recent entry. */\n firstSeen: string | null;\n lastSeen: string | null;\n /** ELO events on the tag in the dataset's sessions. */\n events: number;\n}\n\nexport interface EloPoint {\n at: string;\n score: number;\n}\n\nexport interface TagEloView {\n global: EloRank;\n /** Every tag on the registration, highest score first, count-only tags last. */\n rows: TagEloRow[];\n /** The namespace × role batches present, graded ones first. */\n groups: TagBatch[];\n /**\n * Ratings through the dataset's ELO events: each series starts at its first\n * event's `before`, has a point per event, and ends at the current score at\n * `asOf`. A move between recorded events (a session that didn't save its\n * events) shows as a step at the next event, or at `asOf`. Tags with no\n * events have no series; count-only tags have none.\n */\n series: { global: EloPoint[]; tags: Record<string, EloPoint[]> };\n /** The first ELO event, or null: trajectories start here. */\n seriesFrom: string | null;\n /** Median rating over the learner's qualifying skills (skillNeed); null if too few. */\n skillReference: number | null;\n /** Security totals over the selected tags. */\n security: Omit<CourseSecurity, 'tags'>;\n}\n\n/** How the view reads skills: a course may pass its own selectors and thresholds. */\nexport interface TagEloViewOptions {\n security?: { selector?: TagSelector; config?: TagSecurityConfig };\n need?: SkillNeedConfig;\n}\n\n/** The learner's `CourseElo` for the dataset's course, or null if not registered. */\nexport function learnerCourseElo(ds: LearnerDataset): CourseElo | null {\n const elo = ds.registration?.courses?.find((c) => c.courseID === ds.courseId)?.elo;\n if (typeof elo === 'number') return { global: { score: elo, count: 0 }, tags: {}, misc: {} };\n if (!elo || typeof elo !== 'object' || !elo.global) return null;\n return { ...elo, tags: elo.tags ?? {}, misc: elo.misc ?? {} };\n}\n\nfunction minIso(a: string | null, b: string): string {\n return a === null || b < a ? b : a;\n}\n\nfunction maxIso(a: string | null, b: string): string {\n return a === null || b > a ? b : a;\n}\n\n/**\n * Extend a series by one event. A `before` that differs from where the line\n * stands gets its own point: the rating moved between recorded events (a\n * session that closed without saving its events), shown as a step here.\n */\nfunction step(line: EloPoint[], at: string, before: number, after: number): void {\n if (before !== COUNT_ONLY_SCORE && line[line.length - 1]?.score !== before)\n line.push({ at, score: before });\n line.push({ at, score: after });\n}\n\n/** The learner's per-tag ELO for display. Null if the dataset has no registration for its course. */\nexport function tagEloView(ds: LearnerDataset, options: TagEloViewOptions = {}): TagEloView | null {\n const elo = learnerCourseElo(ds);\n if (!elo) return null;\n\n const security = courseSecurity(elo, options.security);\n const securityByTag = new Map(security.tags.map((s) => [s.tag, s]));\n const need = skillNeed(elo, options.need);\n const needByTag = new Map(need.skills.map((s) => [s.tag, s]));\n\n // When each tag was named by a response, from card history.\n const seen = new Map<string, { first: string | null; last: string | null }>();\n for (const h of ds.cardHistories) {\n for (const r of h.records) {\n const p = r.performance as unknown;\n if (!p || typeof p !== 'object') continue;\n for (const tag of Object.keys(p)) {\n if (tag === '_global') continue;\n const s = seen.get(tag) ?? { first: null, last: null };\n s.first = minIso(s.first, r.timeStamp);\n s.last = maxIso(s.last, r.timeStamp);\n seen.set(tag, s);\n }\n }\n }\n\n // Trajectories, from session ELO events in time order.\n const events = ds.sessions\n .flatMap((s) => s.eloEvents ?? [])\n .sort((a, b) => a.at.localeCompare(b.at));\n const globalSeries: EloPoint[] = [];\n const tagSeries: Record<string, EloPoint[]> = {};\n const eventCounts = new Map<string, number>();\n for (const e of events) {\n step(globalSeries, e.at, e.global.before, e.global.after);\n for (const [tag, t] of Object.entries(e.tags ?? {})) {\n eventCounts.set(tag, (eventCounts.get(tag) ?? 0) + 1);\n if (t.score === null || isCountOnlyTag(tag) || t.after === COUNT_ONLY_SCORE) continue;\n step((tagSeries[tag] ??= []), e.at, t.before, t.after);\n }\n }\n\n const rows: TagEloRow[] = Object.entries(elo.tags).map(([tag, rank]) => {\n const role = tagRole(tag);\n const countOnly = isCountOnlyTag(tag) || rank.score === COUNT_ONLY_SCORE;\n const score = countOnly ? null : rank.score;\n const recent = rank.recent ?? [];\n let { first, last } = seen.get(tag) ?? { first: null, last: null };\n for (const p of recent) {\n first = minIso(first, p.at);\n last = maxIso(last, p.at);\n }\n return {\n tag,\n role,\n namespace: tagNamespace(tag),\n group: tagGroupBatch(tag).id,\n score,\n ...(countOnly && rank.score !== COUNT_ONLY_SCORE ? { staleScore: rank.score } : {}),\n count: rank.count,\n vsGlobal: score === null ? null : score - elo.global.score,\n recent,\n recentOk: recent.filter(presentationOk).length,\n ...(securityByTag.has(tag) ? { security: securityByTag.get(tag) } : {}),\n ...(needByTag.has(tag)\n ? { need: needByTag.get(tag)!.need, deficit: needByTag.get(tag)!.deficit }\n : {}),\n firstSeen: first,\n lastSeen: last,\n events: eventCounts.get(tag) ?? 0,\n };\n });\n rows.sort((a, b) =>\n a.score === null || b.score === null\n ? Number(a.score === null) - Number(b.score === null) || a.tag.localeCompare(b.tag)\n : b.score - a.score || a.tag.localeCompare(b.tag)\n );\n\n // Close each line at the current rating, so it reaches `asOf` and shows any\n // move the events didn't record.\n if (globalSeries.length > 0) globalSeries.push({ at: ds.asOf, score: elo.global.score });\n for (const row of rows) {\n const line = tagSeries[row.tag];\n if (line && row.score !== null) line.push({ at: ds.asOf, score: row.score });\n }\n\n const groups = new Map<string, TagBatch>();\n for (const row of rows) if (!groups.has(row.group)) groups.set(row.group, tagGroupBatch(row.tag));\n const countOnlyGroup = (b: TagBatch): boolean =>\n b.roles?.some((r) => r === 'intro' || r === 'expose') ?? false;\n\n return {\n global: elo.global,\n rows,\n groups: [...groups.values()].sort(\n (a, b) => Number(countOnlyGroup(a)) - Number(countOnlyGroup(b)) || a.id.localeCompare(b.id)\n ),\n series: { global: globalSeries, tags: tagSeries },\n seriesFrom: events[0]?.at ?? null,\n skillReference: need.reference,\n security: {\n secure: security.secure,\n shaky: security.shaky,\n unproven: security.unproven,\n debt: security.debt,\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAuDA,SAAS,WAAW,KAAa,MAAuB;CAEtD,MAAM,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,CAAC,KAAK,IAAI;AACxD,QAAO,QAAQ,IAAI,MAAM,GAAG,MAAM,MAAM,GAAG;;;;;;;AAQ7C,SAAgB,aAAa,KAAqB;CAChD,MAAM,OAAO,QAAQ,IAAI;AACzB,KA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