pi-evals 0.2.0 → 0.3.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/CHANGELOG.md +6 -0
- package/README.md +17 -7
- package/dist/build.js +4 -3
- package/dist/cli.js +2 -2
- package/dist/coverage.js +8 -1
- package/dist/findings.js +50 -0
- package/dist/index.js +14 -7
- package/dist/model.js +21 -10
- package/dist/ops.js +52 -22
- package/dist/query.js +32 -13
- package/dist/ranges.js +14 -0
- package/dist/render.js +14 -5
- package/dist/report/findings.js +12 -1
- package/dist/report/sections.js +3 -3
- package/dist/report/strip.js +42 -0
- package/dist/report/style.js +9 -1
- package/dist/report/timeline.js +5 -14
- package/dist/report/week.js +21 -13
- package/dist/trends.js +58 -0
- package/docs/design.md +15 -0
- package/package.json +5 -2
- package/scripts/change-impact.mjs +18 -0
- package/scripts/package-errors.mjs +10 -0
- package/scripts/query-lib.mjs +36 -0
- package/scripts/skill-days.mjs +9 -0
- package/skills/analyzing-evals/SKILL.md +21 -0
- package/src/aggregate.ts +3 -0
- package/src/build.ts +4 -3
- package/src/cli.ts +2 -2
- package/src/coverage.ts +8 -1
- package/src/findings.ts +49 -0
- package/src/index.ts +14 -9
- package/src/model.ts +22 -10
- package/src/ops.ts +49 -22
- package/src/query.ts +29 -13
- package/src/ranges.ts +15 -0
- package/src/render.ts +14 -5
- package/src/report/findings.ts +19 -1
- package/src/report/sections.ts +3 -5
- package/src/report/strip.ts +40 -0
- package/src/report/style.ts +9 -1
- package/src/report/timeline.ts +6 -22
- package/src/report/week.ts +21 -17
- package/src/trends.ts +61 -0
package/src/report/week.ts
CHANGED
|
@@ -1,28 +1,34 @@
|
|
|
1
1
|
import type { ReportModel } from "../model.ts";
|
|
2
2
|
import { esc, num, type Words } from "./format.ts";
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
export function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
4
|
+
/** Workload over the selected dates with records; the extraction day is partial. */
|
|
5
|
+
export function periodRows(m: ReportModel) {
|
|
6
|
+
if (!m.series.days.length || !m.window.until || !m.window.since) return [];
|
|
7
|
+
const end = Math.min(Date.parse(m.freshness.lastExtract?.slice(0, 10) ?? m.window.until), Date.parse(m.window.until));
|
|
8
|
+
const positions = new Map(m.series.days.map((d, i) => [d, i]));
|
|
9
|
+
const changes = new Map<string, Set<string>>(), totals = new Map<string, number>();
|
|
10
|
+
for (const c of m.changes) {
|
|
11
|
+
const day = c.at.slice(0, 10), kinds = changes.get(day) ?? new Set<string>();
|
|
12
|
+
kinds.add(c.kind); changes.set(day, kinds); totals.set(day, (totals.get(day) ?? 0) + 1);
|
|
13
|
+
}
|
|
9
14
|
const rows = [];
|
|
10
|
-
for (let t = Math.max(
|
|
11
|
-
const day = new Date(t).toISOString().slice(0, 10), i =
|
|
15
|
+
for (let t = Math.max(Date.parse(m.series.days[0]), Date.parse(m.window.since)); t <= end; t += 86400000) {
|
|
16
|
+
const day = new Date(t).toISOString().slice(0, 10), i = positions.get(day) ?? -1;
|
|
12
17
|
rows.push({
|
|
13
18
|
day,
|
|
14
19
|
sessions: m.series.sessions[i] ?? 0,
|
|
15
20
|
calls: m.series.toolCalls[i] ?? 0,
|
|
16
21
|
loads: m.series.skillLoads[i] ?? 0,
|
|
17
|
-
changes:
|
|
22
|
+
changes: totals.get(day) ?? 0,
|
|
23
|
+
kinds: [...(changes.get(day) ?? [])],
|
|
18
24
|
});
|
|
19
25
|
}
|
|
20
26
|
return rows;
|
|
21
27
|
}
|
|
22
|
-
export type Week = ReturnType<typeof
|
|
28
|
+
export type Week = ReturnType<typeof periodRows>;
|
|
23
29
|
export function workload(rows: Week, L: Words) {
|
|
24
|
-
const heading = `<h2>${L("
|
|
25
|
-
if (!rows.length) return `<div class="panel">${heading}<p>${L("No
|
|
30
|
+
const heading = `<h2>${L("Workload in this period", "這段期間的工作量")}</h2>`;
|
|
31
|
+
if (!rows.length) return `<div class="panel">${heading}<p>${L("No records in this period.", "這段期間沒有紀錄。")}</p></div>`;
|
|
26
32
|
const total = (key: "sessions" | "calls" | "loads") => num(rows.reduce((n, r) => n + r[key], 0));
|
|
27
33
|
const max = Math.max(1, ...rows.map((r) => r.sessions));
|
|
28
34
|
const points = rows.map((r, i) => [5 + i * 348 / Math.max(1, rows.length - 1), 89 - 64 * r.sessions / max]);
|
|
@@ -32,18 +38,16 @@ export function workload(rows: Week, L: Words) {
|
|
|
32
38
|
"; ",
|
|
33
39
|
);
|
|
34
40
|
return `<div class="panel workload">${heading}<p class="muted">${md(rows[0].day)}–${md(rows.at(-1)!.day)} / ${
|
|
35
|
-
L("
|
|
41
|
+
L("Through the last extract", "統計至上次抽取")
|
|
36
42
|
}</p><h3>${total("sessions")} ${L("sessions", "段工作")}</h3><p class="muted">${
|
|
37
|
-
L("Sessions per day ·
|
|
43
|
+
L("Sessions per day · colored dots mark changes", "每日工作段數 · 彩點表示當日調整類別")
|
|
38
44
|
}</p>
|
|
39
45
|
<svg role="img" aria-label="${esc(desc)}" viewBox="0 0 358 96"><polygon points="5,89 ${line} ${
|
|
40
46
|
points.at(-1)![0]
|
|
41
47
|
},89" class="area"/><polyline points="${line}" class="trend"/>${
|
|
42
|
-
points.map(([x
|
|
48
|
+
points.map(([x], i) =>
|
|
43
49
|
rows[i].changes
|
|
44
|
-
? `<
|
|
45
|
-
rows[i].changes
|
|
46
|
-
} ${L("changes", "筆調整")}</title></circle>`
|
|
50
|
+
? `<g><title>${esc(rows[i].day)}: ${num(rows[i].changes)} ${L("changes", "筆調整")}</title>${rows[i].kinds.map((k,j) => `<circle class="work-mark kind-${esc(k)}" cx="${x}" cy="${5 + 4*j}" r="1.9"/>`).join("")}</g>`
|
|
47
51
|
: ""
|
|
48
52
|
).join("")
|
|
49
53
|
}</svg>
|
package/src/trends.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { DayAgg } from "./aggregate.ts";
|
|
2
|
+
import type { DaysIndex } from "./build.ts";
|
|
3
|
+
import { ownerFor, sumDays } from "./model.ts";
|
|
4
|
+
|
|
5
|
+
const DAY = 86_400_000;
|
|
6
|
+
|
|
7
|
+
/** Counts by event date; session counts by skill in the index use session start date. */
|
|
8
|
+
export function recentDays(index: DaysIndex, project?: string) {
|
|
9
|
+
if (!index.lastExtract || !index.range.start) return [];
|
|
10
|
+
const end = Date.parse(index.lastExtract.slice(0, 10));
|
|
11
|
+
const dates = Array.from({ length: 14 }, (_, i) => new Date(end - (14 - i) * DAY).toISOString().slice(0, 10));
|
|
12
|
+
const rows = new Map(sumDays(index, { project, since: dates[0], until: dates[13] }).perDay);
|
|
13
|
+
return dates.filter(d => d >= index.range.start.slice(0, 10)).map(day => ({ day, agg: rows.get(day) }));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface Count { errors: number; calls: number }
|
|
17
|
+
export function trendPair(r: { before: Count; after: Count }) {
|
|
18
|
+
const side = (c: Count) => `${c.errors}/${c.calls} (${(100 * c.errors / c.calls).toFixed(1)}%)`;
|
|
19
|
+
return `${side(r.before)} → ${side(r.after)}`;
|
|
20
|
+
}
|
|
21
|
+
const zero = (): Count => ({ errors: 0, calls: 0 });
|
|
22
|
+
function add(into: Count, from: Count) { into.errors += from.errors; into.calls += from.calls; }
|
|
23
|
+
export function packageCounts(index: DaysIndex, day?: DayAgg) {
|
|
24
|
+
const by = new Map<string, Count>();
|
|
25
|
+
for (const [tool, count] of Object.entries(day?.tools ?? {})) {
|
|
26
|
+
const owner = ownerFor(index, tool), total = by.get(owner) ?? zero();
|
|
27
|
+
add(total, count);
|
|
28
|
+
by.set(owner, total);
|
|
29
|
+
}
|
|
30
|
+
return by;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function week(index: DaysIndex, rows: ReturnType<typeof recentDays>) {
|
|
34
|
+
const packages = new Map<string, Count>(), monitors = zero();
|
|
35
|
+
for (const { agg } of rows) {
|
|
36
|
+
for (const [owner, count] of packageCounts(index, agg)) {
|
|
37
|
+
const total = packages.get(owner) ?? zero();
|
|
38
|
+
add(total, count);
|
|
39
|
+
packages.set(owner, total);
|
|
40
|
+
}
|
|
41
|
+
if (agg) add(monitors, { errors: agg.monitors.statuses.error ?? 0, calls: agg.monitors.finished });
|
|
42
|
+
}
|
|
43
|
+
return { packages, monitors };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function rise(before: Count | undefined, after: Count) {
|
|
47
|
+
if (!before || Math.min(before.calls, after.calls) < 20) return;
|
|
48
|
+
// Compare integer counts before rounding the displayed rates (threshold: five percentage points).
|
|
49
|
+
const diff = after.errors * before.calls - before.errors * after.calls;
|
|
50
|
+
if (20 * diff >= before.calls * after.calls) return { before, after, delta: diff / before.calls / after.calls };
|
|
51
|
+
}
|
|
52
|
+
export function weeklyRises(index: DaysIndex, since?: string, project?: string) {
|
|
53
|
+
const rows = recentDays(index, project);
|
|
54
|
+
if (rows.length !== 14 || (since && Date.parse(rows[0].day) < Date.parse(since) - 86400000)) return;
|
|
55
|
+
const prev = week(index, rows.slice(0, 7)), curr = week(index, rows.slice(7));
|
|
56
|
+
const packages = [...curr.packages].flatMap(([name, count]) => {
|
|
57
|
+
const r = rise(prev.packages.get(name), count);
|
|
58
|
+
return r ? [{ name, ...r }] : [];
|
|
59
|
+
}).sort((a, b) => b.delta - a.delta || b.after.calls - a.after.calls || a.name.localeCompare(b.name));
|
|
60
|
+
return { start: rows[0].day, end: rows[13].day, packages, monitors: rise(prev.monitors, curr.monitors) };
|
|
61
|
+
}
|