skilltally 1.0.3 → 1.1.0
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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +13 -0
- package/README.md +12 -5
- package/bin/cli.mjs +163 -1
- package/gemini-extension.json +1 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/skills/skilltally/SKILL.md +23 -8
- package/src/install/prune.mjs +355 -0
- package/src/mcp/server.mjs +345 -0
- package/src/report/aggregate.mjs +206 -17
- package/src/report/chains.mjs +187 -0
- package/src/report/dashboard.mjs +1245 -0
- package/src/report/format.mjs +223 -2
package/src/report/aggregate.mjs
CHANGED
|
@@ -35,22 +35,50 @@ export function parseSince(sinceStr, now = new Date()) {
|
|
|
35
35
|
throw new Error(`Invalid --since value: "${sinceStr}" (use e.g. 7d, 30d, 90d, 4w, 6m, 2026-01-01, or all)`);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
function hostMatches(eventHost, filterHost) {
|
|
38
|
+
export function hostMatches(eventHost, filterHost) {
|
|
39
39
|
if (!filterHost || filterHost === 'all') return true;
|
|
40
40
|
if (eventHost === filterHost) return true;
|
|
41
41
|
if (filterHost === 'antigravity' && String(eventHost).startsWith('antigravity')) return true;
|
|
42
42
|
return false;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
const SPARK_CHARS = ['▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'];
|
|
46
|
+
|
|
47
|
+
export function isManualVia(via) {
|
|
48
|
+
return via === 'mention' || via === 'slash_command';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function buildDailySparklineSeries(daySetsMap, now = new Date(), days = 14) {
|
|
52
|
+
const endUtcMs = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate());
|
|
53
|
+
const series = [];
|
|
54
|
+
for (let i = days - 1; i >= 0; i--) {
|
|
55
|
+
const dayKey = new Date(endUtcMs - i * 86400_000).toISOString().slice(0, 10);
|
|
56
|
+
series.push(daySetsMap?.get(dayKey)?.size || 0);
|
|
57
|
+
}
|
|
58
|
+
return series;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function encodeSparkline(counts) {
|
|
62
|
+
if (!Array.isArray(counts) || counts.length === 0) return '';
|
|
63
|
+
const max = Math.max(0, ...counts);
|
|
64
|
+
if (max === 0) return '·'.repeat(counts.length);
|
|
65
|
+
return counts
|
|
66
|
+
.map((c) => {
|
|
67
|
+
if (!c || c <= 0) return '·';
|
|
68
|
+
if (max <= 1) return '█';
|
|
69
|
+
const idx = Math.min(7, Math.floor(((c - 1) / Math.max(1, max - 1)) * 7));
|
|
70
|
+
return SPARK_CHARS[idx];
|
|
71
|
+
})
|
|
72
|
+
.join('');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function prepareFilteredEvents({
|
|
46
76
|
events = [],
|
|
47
77
|
inventory = null,
|
|
48
78
|
config = {},
|
|
49
79
|
since = '30d',
|
|
50
80
|
host = null,
|
|
51
81
|
project = null,
|
|
52
|
-
bySource = false,
|
|
53
|
-
metric = 'activations',
|
|
54
82
|
now = new Date(),
|
|
55
83
|
} = {}) {
|
|
56
84
|
const sinceDate = since === null ? null : parseSince(since, now);
|
|
@@ -76,13 +104,78 @@ export function aggregateStats({
|
|
|
76
104
|
filtered.push(ev);
|
|
77
105
|
}
|
|
78
106
|
|
|
107
|
+
return {
|
|
108
|
+
sinceDate,
|
|
109
|
+
exclSkills,
|
|
110
|
+
exclSources,
|
|
111
|
+
filtered,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function findInventoryEntry(inventory, skill, source, bySource) {
|
|
116
|
+
if (!inventory) return null;
|
|
117
|
+
if (bySource && Array.isArray(inventory.skills)) {
|
|
118
|
+
const exact = inventory.skills.find(
|
|
119
|
+
(s) => (s.name === skill || s.dir_name === skill) && s.source === source
|
|
120
|
+
);
|
|
121
|
+
if (exact) return exact;
|
|
122
|
+
}
|
|
123
|
+
return inventory.index?.byName?.get(skill) ?? inventory.index?.byDirName?.get(skill) ?? null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function aggregateStats({
|
|
127
|
+
events = [],
|
|
128
|
+
inventory = null,
|
|
129
|
+
config = {},
|
|
130
|
+
since = '30d',
|
|
131
|
+
host = null,
|
|
132
|
+
project = null,
|
|
133
|
+
bySource = false,
|
|
134
|
+
metric = 'activations',
|
|
135
|
+
now = new Date(),
|
|
136
|
+
} = {}) {
|
|
137
|
+
const { sinceDate, exclSkills, exclSources, filtered } = prepareFilteredEvents({
|
|
138
|
+
events,
|
|
139
|
+
inventory,
|
|
140
|
+
config,
|
|
141
|
+
since,
|
|
142
|
+
host,
|
|
143
|
+
project,
|
|
144
|
+
now,
|
|
145
|
+
});
|
|
146
|
+
|
|
79
147
|
const hostTotals = {};
|
|
148
|
+
const viaTotals = {};
|
|
149
|
+
const modelTotals = {};
|
|
150
|
+
const projectTotals = {};
|
|
151
|
+
const allSessions = new Set();
|
|
152
|
+
let manualTotal = 0;
|
|
153
|
+
let autoTotal = 0;
|
|
80
154
|
const groups = new Map();
|
|
81
155
|
|
|
82
|
-
for (
|
|
156
|
+
for (let idx = 0; idx < filtered.length; idx++) {
|
|
157
|
+
const ev = filtered[idx];
|
|
83
158
|
const h = ev.host || 'unknown';
|
|
84
159
|
hostTotals[h] = (hostTotals[h] || 0) + 1;
|
|
85
160
|
|
|
161
|
+
const viaKey = ev.via || 'unknown';
|
|
162
|
+
viaTotals[viaKey] = (viaTotals[viaKey] || 0) + 1;
|
|
163
|
+
const isManual = isManualVia(viaKey);
|
|
164
|
+
if (isManual) manualTotal += 1;
|
|
165
|
+
else autoTotal += 1;
|
|
166
|
+
|
|
167
|
+
if (ev.model) {
|
|
168
|
+
modelTotals[ev.model] = (modelTotals[ev.model] || 0) + 1;
|
|
169
|
+
}
|
|
170
|
+
if (ev.project) {
|
|
171
|
+
projectTotals[ev.project] = (projectTotals[ev.project] || 0) + 1;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const globalSessKey = ev.session_id
|
|
175
|
+
? `${h}\0${ev.session_id}`
|
|
176
|
+
: ev.id || `${h}\0${ev.ts || ''}\0${idx}`;
|
|
177
|
+
allSessions.add(globalSessKey);
|
|
178
|
+
|
|
86
179
|
const key = bySource ? `${ev.skill}\0${ev.source || 'unknown'}` : ev.skill;
|
|
87
180
|
let bucket = groups.get(key);
|
|
88
181
|
if (!bucket) {
|
|
@@ -91,8 +184,14 @@ export function aggregateStats({
|
|
|
91
184
|
source: ev.source || 'unknown',
|
|
92
185
|
sources: new Set([ev.source || 'unknown']),
|
|
93
186
|
reads: 0,
|
|
187
|
+
manualReads: 0,
|
|
188
|
+
autoReads: 0,
|
|
189
|
+
via: {},
|
|
94
190
|
sessions: new Set(),
|
|
95
191
|
hosts: new Set(),
|
|
192
|
+
projects: new Set(),
|
|
193
|
+
models: new Set(),
|
|
194
|
+
daySessions: new Map(),
|
|
96
195
|
last_used: ev.ts || '',
|
|
97
196
|
};
|
|
98
197
|
groups.set(key, bucket);
|
|
@@ -104,22 +203,62 @@ export function aggregateStats({
|
|
|
104
203
|
}
|
|
105
204
|
|
|
106
205
|
bucket.reads += 1;
|
|
107
|
-
|
|
206
|
+
if (isManual) bucket.manualReads += 1;
|
|
207
|
+
else bucket.autoReads += 1;
|
|
208
|
+
bucket.via[viaKey] = (bucket.via[viaKey] || 0) + 1;
|
|
209
|
+
|
|
210
|
+
const sessKey = ev.session_id || ev.id || `${ev.ts}:${bucket.reads}`;
|
|
211
|
+
bucket.sessions.add(sessKey);
|
|
108
212
|
bucket.hosts.add(h);
|
|
109
|
-
if (ev.
|
|
110
|
-
|
|
213
|
+
if (ev.project) bucket.projects.add(ev.project);
|
|
214
|
+
if (ev.model) bucket.models.add(ev.model);
|
|
215
|
+
|
|
216
|
+
if (ev.ts) {
|
|
217
|
+
const tsMs = Date.parse(ev.ts);
|
|
218
|
+
if (Number.isFinite(tsMs)) {
|
|
219
|
+
const dayKey = new Date(tsMs).toISOString().slice(0, 10);
|
|
220
|
+
let daySet = bucket.daySessions.get(dayKey);
|
|
221
|
+
if (!daySet) {
|
|
222
|
+
daySet = new Set();
|
|
223
|
+
bucket.daySessions.set(dayKey, daySet);
|
|
224
|
+
}
|
|
225
|
+
daySet.add(sessKey);
|
|
226
|
+
}
|
|
227
|
+
if (!bucket.last_used || ev.ts > bucket.last_used) {
|
|
228
|
+
bucket.last_used = ev.ts;
|
|
229
|
+
}
|
|
111
230
|
}
|
|
112
231
|
}
|
|
113
232
|
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
233
|
+
const totalSessions = Math.max(1, allSessions.size);
|
|
234
|
+
|
|
235
|
+
const rows = [...groups.values()].map((b) => {
|
|
236
|
+
const invEntry = findInventoryEntry(inventory, b.skill, b.source, bySource);
|
|
237
|
+
const estTokens = invEntry?.est_tokens || 0;
|
|
238
|
+
const descChars = invEntry?.desc_chars || 0;
|
|
239
|
+
const activations = b.sessions.size;
|
|
240
|
+
const dailyCounts = buildDailySparklineSeries(b.daySessions, now, 14);
|
|
241
|
+
return {
|
|
242
|
+
skill: b.skill,
|
|
243
|
+
source: b.source,
|
|
244
|
+
sources: [...b.sources].sort(),
|
|
245
|
+
activations,
|
|
246
|
+
reads: b.reads,
|
|
247
|
+
last_used: b.last_used,
|
|
248
|
+
hosts: [...b.hosts].sort(),
|
|
249
|
+
via: b.via,
|
|
250
|
+
manualReads: b.manualReads,
|
|
251
|
+
autoReads: b.autoReads,
|
|
252
|
+
manualRatio: b.reads > 0 ? Number((b.manualReads / b.reads).toFixed(2)) : 0,
|
|
253
|
+
projects: [...b.projects].sort(),
|
|
254
|
+
models: [...b.models].sort(),
|
|
255
|
+
est_tokens: estTokens,
|
|
256
|
+
desc_chars: descChars,
|
|
257
|
+
tokenCostPerActivation: estTokens > 0 ? Math.round((totalSessions * estTokens) / Math.max(1, activations)) : 0,
|
|
258
|
+
dailyCounts,
|
|
259
|
+
sparkline: encodeSparkline(dailyCounts),
|
|
260
|
+
};
|
|
261
|
+
});
|
|
123
262
|
|
|
124
263
|
rows.sort((a, b) => {
|
|
125
264
|
if (metric === 'reads') {
|
|
@@ -148,6 +287,7 @@ export function aggregateStats({
|
|
|
148
287
|
const disabledCount = invSkills.filter(
|
|
149
288
|
(s) => !s.enabled && !exclSkills.has(s.name) && !exclSources.has(s.source)
|
|
150
289
|
).length;
|
|
290
|
+
const enabledEstTokens = enabledSkills.reduce((acc, s) => acc + (s.est_tokens || 0), 0);
|
|
151
291
|
|
|
152
292
|
const usedNames = new Set(rows.map((r) => r.skill));
|
|
153
293
|
const usedBySource = new Set(rows.map((r) => `${r.skill}\0${r.source}`));
|
|
@@ -188,6 +328,42 @@ export function aggregateStats({
|
|
|
188
328
|
(a, b) => b.estTokens - a.estTokens || b.skillCount - a.skillCount || a.source.localeCompare(b.source)
|
|
189
329
|
);
|
|
190
330
|
|
|
331
|
+
const manualOnlySkills = rows
|
|
332
|
+
.filter((r) => r.reads > 0 && r.autoReads === 0 && r.manualReads > 0)
|
|
333
|
+
.sort((a, b) => b.est_tokens - a.est_tokens || b.reads - a.reads)
|
|
334
|
+
.map((r) => ({
|
|
335
|
+
skill: r.skill,
|
|
336
|
+
source: r.source,
|
|
337
|
+
activations: r.activations,
|
|
338
|
+
reads: r.reads,
|
|
339
|
+
est_tokens: r.est_tokens,
|
|
340
|
+
via: r.via,
|
|
341
|
+
}));
|
|
342
|
+
|
|
343
|
+
const projectScopeCandidates = rows
|
|
344
|
+
.filter((r) => r.projects.length === 1 && r.source !== 'project' && r.source !== 'builtin')
|
|
345
|
+
.sort((a, b) => b.est_tokens - a.est_tokens || b.activations - a.activations)
|
|
346
|
+
.map((r) => ({
|
|
347
|
+
skill: r.skill,
|
|
348
|
+
source: r.source,
|
|
349
|
+
project: r.projects[0],
|
|
350
|
+
activations: r.activations,
|
|
351
|
+
reads: r.reads,
|
|
352
|
+
est_tokens: r.est_tokens,
|
|
353
|
+
}));
|
|
354
|
+
|
|
355
|
+
const highCostSkills = rows
|
|
356
|
+
.filter((r) => r.est_tokens > 0)
|
|
357
|
+
.sort((a, b) => b.tokenCostPerActivation - a.tokenCostPerActivation || b.est_tokens - a.est_tokens)
|
|
358
|
+
.slice(0, 10)
|
|
359
|
+
.map((r) => ({
|
|
360
|
+
skill: r.skill,
|
|
361
|
+
source: r.source,
|
|
362
|
+
activations: r.activations,
|
|
363
|
+
est_tokens: r.est_tokens,
|
|
364
|
+
tokenCostPerActivation: r.tokenCostPerActivation,
|
|
365
|
+
}));
|
|
366
|
+
|
|
191
367
|
return {
|
|
192
368
|
window: {
|
|
193
369
|
since: since ?? 'all',
|
|
@@ -198,13 +374,21 @@ export function aggregateStats({
|
|
|
198
374
|
events: filtered.length,
|
|
199
375
|
activations: rows.reduce((acc, r) => acc + r.activations, 0),
|
|
200
376
|
uniqueSkills: rows.length,
|
|
377
|
+
sessions: allSessions.size,
|
|
201
378
|
hosts: hostTotals,
|
|
379
|
+
via: viaTotals,
|
|
380
|
+
models: modelTotals,
|
|
381
|
+
projects: projectTotals,
|
|
382
|
+
manualReads: manualTotal,
|
|
383
|
+
autoReads: autoTotal,
|
|
202
384
|
},
|
|
203
385
|
inventory: {
|
|
204
386
|
enabled: enabledSkills.length,
|
|
205
387
|
disabled: disabledCount,
|
|
206
388
|
used: usedInstalledCount,
|
|
207
389
|
unused: unusedSkills.length,
|
|
390
|
+
enabledEstTokens,
|
|
391
|
+
usedEstTokens: Math.max(0, enabledEstTokens - totalEstTokens),
|
|
208
392
|
},
|
|
209
393
|
rows,
|
|
210
394
|
unused: {
|
|
@@ -213,5 +397,10 @@ export function aggregateStats({
|
|
|
213
397
|
totalEstTokens,
|
|
214
398
|
bySource: unusedGroups,
|
|
215
399
|
},
|
|
400
|
+
insights: {
|
|
401
|
+
manualOnlySkills,
|
|
402
|
+
projectScopeCandidates,
|
|
403
|
+
highCostSkills,
|
|
404
|
+
},
|
|
216
405
|
};
|
|
217
406
|
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { prepareFilteredEvents } from './aggregate.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Build skill transition chains, 3-step sequences, and co-occurrence pairs
|
|
5
|
+
* grouped by session_id within the requested filter window.
|
|
6
|
+
*/
|
|
7
|
+
export function buildChains({
|
|
8
|
+
events = [],
|
|
9
|
+
inventory = null,
|
|
10
|
+
config = {},
|
|
11
|
+
since = '30d',
|
|
12
|
+
host = null,
|
|
13
|
+
project = null,
|
|
14
|
+
limit = 20,
|
|
15
|
+
now = new Date(),
|
|
16
|
+
} = {}) {
|
|
17
|
+
const { sinceDate, filtered } = prepareFilteredEvents({
|
|
18
|
+
events,
|
|
19
|
+
inventory,
|
|
20
|
+
config,
|
|
21
|
+
since,
|
|
22
|
+
host,
|
|
23
|
+
project,
|
|
24
|
+
now,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const sessionMap = new Map();
|
|
28
|
+
for (let idx = 0; idx < filtered.length; idx++) {
|
|
29
|
+
const ev = filtered[idx];
|
|
30
|
+
if (!ev.session_id || !ev.skill) continue;
|
|
31
|
+
const sKey = `${ev.host || 'unknown'}\0${ev.session_id}`;
|
|
32
|
+
let list = sessionMap.get(sKey);
|
|
33
|
+
if (!list) {
|
|
34
|
+
list = [];
|
|
35
|
+
sessionMap.set(sKey, list);
|
|
36
|
+
}
|
|
37
|
+
const tsMs = Date.parse(ev.ts);
|
|
38
|
+
list.push({
|
|
39
|
+
skill: ev.skill,
|
|
40
|
+
tsMs: Number.isFinite(tsMs) ? tsMs : 0,
|
|
41
|
+
order: idx,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const skillSessions = new Map();
|
|
46
|
+
const transitionMap = new Map();
|
|
47
|
+
const sequenceMap = new Map();
|
|
48
|
+
const pairMap = new Map();
|
|
49
|
+
let multiSkillSessions = 0;
|
|
50
|
+
|
|
51
|
+
for (const [sKey, rawList] of sessionMap.entries()) {
|
|
52
|
+
rawList.sort((a, b) => a.tsMs - b.tsMs || a.order - b.order);
|
|
53
|
+
|
|
54
|
+
const seq = [];
|
|
55
|
+
for (const item of rawList) {
|
|
56
|
+
if (seq.length === 0 || seq[seq.length - 1].skill !== item.skill) {
|
|
57
|
+
seq.push({ skill: item.skill, tsMs: item.tsMs });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const uniqueSkills = [...new Set(seq.map((x) => x.skill))].sort();
|
|
62
|
+
for (const s of uniqueSkills) {
|
|
63
|
+
skillSessions.set(s, (skillSessions.get(s) || 0) + 1);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (uniqueSkills.length >= 2) {
|
|
67
|
+
multiSkillSessions += 1;
|
|
68
|
+
for (let i = 0; i < uniqueSkills.length; i++) {
|
|
69
|
+
for (let j = i + 1; j < uniqueSkills.length; j++) {
|
|
70
|
+
const a = uniqueSkills[i];
|
|
71
|
+
const b = uniqueSkills[j];
|
|
72
|
+
const pKey = `${a}\0${b}`;
|
|
73
|
+
let p = pairMap.get(pKey);
|
|
74
|
+
if (!p) {
|
|
75
|
+
p = { a, b, sessions: new Set() };
|
|
76
|
+
pairMap.set(pKey, p);
|
|
77
|
+
}
|
|
78
|
+
p.sessions.add(sKey);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (seq.length >= 2) {
|
|
84
|
+
for (let i = 0; i < seq.length - 1; i++) {
|
|
85
|
+
const from = seq[i].skill;
|
|
86
|
+
const to = seq[i + 1].skill;
|
|
87
|
+
const tKey = `${from}\0${to}`;
|
|
88
|
+
let t = transitionMap.get(tKey);
|
|
89
|
+
if (!t) {
|
|
90
|
+
t = { from, to, occurrences: 0, sessions: new Set(), totalDeltaMs: 0 };
|
|
91
|
+
transitionMap.set(tKey, t);
|
|
92
|
+
}
|
|
93
|
+
t.occurrences += 1;
|
|
94
|
+
t.sessions.add(sKey);
|
|
95
|
+
t.totalDeltaMs += Math.max(0, seq[i + 1].tsMs - seq[i].tsMs);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (seq.length >= 3) {
|
|
100
|
+
for (let i = 0; i < seq.length - 2; i++) {
|
|
101
|
+
const s1 = seq[i].skill;
|
|
102
|
+
const s2 = seq[i + 1].skill;
|
|
103
|
+
const s3 = seq[i + 2].skill;
|
|
104
|
+
const label = `${s1} -> ${s2} -> ${s3}`;
|
|
105
|
+
let seqEntry = sequenceMap.get(label);
|
|
106
|
+
if (!seqEntry) {
|
|
107
|
+
seqEntry = { sequence: [s1, s2, s3], label, sessions: new Set() };
|
|
108
|
+
sequenceMap.set(label, seqEntry);
|
|
109
|
+
}
|
|
110
|
+
seqEntry.sessions.add(sKey);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const cap = (arr) => (limit && limit > 0 ? arr.slice(0, limit) : arr);
|
|
116
|
+
|
|
117
|
+
const transitions = cap(
|
|
118
|
+
[...transitionMap.values()]
|
|
119
|
+
.map((t) => {
|
|
120
|
+
const sessCount = t.sessions.size;
|
|
121
|
+
const fromSessions = skillSessions.get(t.from) || 1;
|
|
122
|
+
return {
|
|
123
|
+
from: t.from,
|
|
124
|
+
to: t.to,
|
|
125
|
+
sessions: sessCount,
|
|
126
|
+
occurrences: t.occurrences,
|
|
127
|
+
probability: Number((sessCount / Math.max(1, fromSessions)).toFixed(2)),
|
|
128
|
+
avgGapSeconds: Math.round(t.totalDeltaMs / Math.max(1, t.occurrences) / 1000),
|
|
129
|
+
};
|
|
130
|
+
})
|
|
131
|
+
.sort(
|
|
132
|
+
(a, b) =>
|
|
133
|
+
b.sessions - a.sessions ||
|
|
134
|
+
b.occurrences - a.occurrences ||
|
|
135
|
+
a.from.localeCompare(b.from) ||
|
|
136
|
+
a.to.localeCompare(b.to)
|
|
137
|
+
)
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
const sequences = cap(
|
|
141
|
+
[...sequenceMap.values()]
|
|
142
|
+
.map((s) => ({
|
|
143
|
+
sequence: s.sequence,
|
|
144
|
+
label: s.label,
|
|
145
|
+
sessions: s.sessions.size,
|
|
146
|
+
}))
|
|
147
|
+
.sort((a, b) => b.sessions - a.sessions || a.label.localeCompare(b.label))
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
const pairs = cap(
|
|
151
|
+
[...pairMap.values()]
|
|
152
|
+
.map((p) => {
|
|
153
|
+
const pairSessions = p.sessions.size;
|
|
154
|
+
const sesA = skillSessions.get(p.a) || 0;
|
|
155
|
+
const sesB = skillSessions.get(p.b) || 0;
|
|
156
|
+
return {
|
|
157
|
+
skills: [p.a, p.b],
|
|
158
|
+
sessions: pairSessions,
|
|
159
|
+
jaccard: Number((pairSessions / Math.max(1, sesA + sesB - pairSessions)).toFixed(2)),
|
|
160
|
+
};
|
|
161
|
+
})
|
|
162
|
+
.sort(
|
|
163
|
+
(a, b) =>
|
|
164
|
+
b.sessions - a.sessions ||
|
|
165
|
+
b.jaccard - a.jaccard ||
|
|
166
|
+
a.skills[0].localeCompare(b.skills[0]) ||
|
|
167
|
+
a.skills[1].localeCompare(b.skills[1])
|
|
168
|
+
)
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
window: {
|
|
173
|
+
since: since ?? 'all',
|
|
174
|
+
from: sinceDate ? sinceDate.toISOString().slice(0, 10) : null,
|
|
175
|
+
to: now.toISOString().slice(0, 10),
|
|
176
|
+
},
|
|
177
|
+
totals: {
|
|
178
|
+
sessions: sessionMap.size,
|
|
179
|
+
multiSkillSessions,
|
|
180
|
+
transitions: transitions.length,
|
|
181
|
+
pairs: pairs.length,
|
|
182
|
+
},
|
|
183
|
+
transitions,
|
|
184
|
+
sequences,
|
|
185
|
+
pairs,
|
|
186
|
+
};
|
|
187
|
+
}
|