pi-evals 0.4.0 → 0.4.1
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 +4 -0
- package/dist/report/concepts.js +2 -2
- package/dist/report/work.js +2 -14
- package/dist/work/query.js +8 -16
- package/dist/work/wording.js +27 -0
- package/package.json +1 -1
- package/src/report/concepts.ts +2 -2
- package/src/report/work.ts +3 -14
- package/src/work/query.ts +9 -14
- package/src/work/wording.ts +26 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.1
|
|
4
|
+
|
|
5
|
+
- Work comparisons in `items`, `findings`, and the HTML report now give separate costs per item and per 100 changed lines, with the number of items behind each comparison. When the measures disagree, the report explains why neither group is necessarily cheaper overall.
|
|
6
|
+
|
|
3
7
|
## 0.4.0
|
|
4
8
|
|
|
5
9
|
- The report has a 「工作」 section: every todo item with its cost (subagents exact, main agent split evenly among items in progress at the same time), minutes in progress, how it closed (reviewer approval, a landed car, a wrap, evidence) and where it stalled, by what woke the main agent. A comparison of like with like says whether one model, role or anchorloop version costs less per item and per 100 changed lines, or that there are too few items to tell. Open items show where they stopped, on whom they wait, and for how long. Two concept cards explain cost attribution and fair comparison with this report's numbers.
|
package/dist/report/concepts.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { esc, num, usd } from "./format.js";
|
|
2
|
-
import {
|
|
2
|
+
import { comparisonText } from "../work/wording.js";
|
|
3
3
|
/** The two work-item ideas, with this report's own numbers. */
|
|
4
4
|
function workCards(m, L) {
|
|
5
5
|
const w = m.work;
|
|
@@ -8,7 +8,7 @@ function workCards(m, L) {
|
|
|
8
8
|
return { attribution: [L("Who a cost belongs to", "花費歸屬"), none], cheaper: [L("When is one way cheaper?", "怎麼比才算比較省"), none] };
|
|
9
9
|
}
|
|
10
10
|
const first = w.compare.find((c) => c.kind === "delegated") ?? w.compare[0];
|
|
11
|
-
const now = first ?
|
|
11
|
+
const now = first ? comparisonText(first, L) : L("No finished items to compare yet.", "還沒有完成的工作可以比。");
|
|
12
12
|
return {
|
|
13
13
|
attribution: [
|
|
14
14
|
L("Who a cost belongs to", "花費歸屬"),
|
package/dist/report/work.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { comparisonText } from "../work/wording.js";
|
|
1
2
|
import { esc, num, usd, words } from "./format.js";
|
|
2
3
|
const SHOWN = 15;
|
|
3
4
|
export function span(minutes, L) {
|
|
@@ -7,19 +8,6 @@ export function span(minutes, L) {
|
|
|
7
8
|
return L(`${(minutes / 60).toFixed(1)} h`, `${(minutes / 60).toFixed(1)} 小時`);
|
|
8
9
|
return L(`${(minutes / 1440).toFixed(1)} days`, `${(minutes / 1440).toFixed(1)} 天`);
|
|
9
10
|
}
|
|
10
|
-
const pct = (v) => `${Math.round(v * 100)}%`;
|
|
11
|
-
export function verdictText(c, v, L, lines = false) {
|
|
12
|
-
const g = (value) => c.groups.find((x) => x.value === value);
|
|
13
|
-
const n = (value) => (lines ? g(value)?.nLines : g(value)?.n) ?? 0;
|
|
14
|
-
const what = lines ? L("per 100 changed lines", "每百行") : L("per item", "每件");
|
|
15
|
-
if (v.kind === "single")
|
|
16
|
-
return v.a ? L(`Only one group (${v.a}): nothing to compare it with.`, `只有一組(${v.a}),沒有可比的對象。`) : L("No items with a line count.", "沒有算得出行數的工作。");
|
|
17
|
-
if (v.kind === "few")
|
|
18
|
-
return L(`Too few items to tell yet (${v.a} ${n(v.a)}, ${v.b} ${n(v.b)}; each group needs 5).`, `件數太少,還看不出來(${v.a} ${n(v.a)} 件、${v.b} ${n(v.b)} 件,每組至少要 5 件)。`);
|
|
19
|
-
if (v.kind === "same")
|
|
20
|
-
return L(`${v.a} and ${v.b} cost about the same ${what} (less than 20% apart).`, `${v.a} 和 ${v.b} ${what}花費差不到兩成,看不出差別。`);
|
|
21
|
-
return L(`${v.a} costs ${pct(v.by ?? 0)} less ${what} than ${v.b} (median of ${n(v.a)} and ${n(v.b)} items of the same kind). This is a difference, not its cause.`, `${v.a} ${what}比 ${v.b} 便宜 ${pct(v.by ?? 0)}(同類工作的中位數,各 ${n(v.a)}、${n(v.b)} 件)。這是差異,不是原因。`);
|
|
22
|
-
}
|
|
23
11
|
function stallText(stalls, m, lang) {
|
|
24
12
|
const L = words(lang);
|
|
25
13
|
const parts = Object.entries(stalls)
|
|
@@ -45,7 +33,7 @@ export function workSection(m, lang, cards, lesson) {
|
|
|
45
33
|
: `<p class="muted">${L("No item closed in this period.", "這段期間沒有收尾的工作。")}</p>`;
|
|
46
34
|
const compare = w.compare.length
|
|
47
35
|
? w.compare
|
|
48
|
-
.map((c) => `<article class="panel"><h3>${esc(kinds[c.kind])} / ${L("by", "依")}${esc(dims[c.dimension])}</h3><div class="scroll"><table><thead><tr><th scope="col">${esc(dims[c.dimension])}</th><th scope="col">${L("Items", "件數")}</th><th scope="col">${L("Median per item", "每件中位數")}</th><th scope="col">${L("Per 100 lines (items)", "每百行(件數)")}</th></tr></thead><tbody>${c.groups.map((g) => `<tr><td>${esc(g.value)}</td><td>${num(g.n)}</td><td>${usd(g.median)}</td><td>${g.per100 === null ? "—" : `${usd(g.per100)}(${num(g.nLines)})`}</td></tr>`).join("")}</tbody></table></div><p class="verdict">${esc(
|
|
36
|
+
.map((c) => `<article class="panel"><h3>${esc(kinds[c.kind])} / ${L("by", "依")}${esc(dims[c.dimension])}</h3><div class="scroll"><table><thead><tr><th scope="col">${esc(dims[c.dimension])}</th><th scope="col">${L("Items", "件數")}</th><th scope="col">${L("Median per item", "每件中位數")}</th><th scope="col">${L("Per 100 lines (items)", "每百行(件數)")}</th></tr></thead><tbody>${c.groups.map((g) => `<tr><td>${esc(g.value)}</td><td>${num(g.n)}</td><td>${usd(g.median)}</td><td>${g.per100 === null ? "—" : `${usd(g.per100)}(${num(g.nLines)})`}</td></tr>`).join("")}</tbody></table></div><p class="verdict">${esc(comparisonText(c, L))} ${L("This is a difference, not its cause.", "這是差異,不是原因。")}</p></article>`)
|
|
49
37
|
.join("")
|
|
50
38
|
: `<p class="muted">${L("No finished items to compare.", "沒有可比較的已完成工作。")}</p>`;
|
|
51
39
|
const open = w.open.length
|
package/dist/work/query.js
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
|
+
import { comparisonText } from "./wording.js";
|
|
1
2
|
const usd = (v) => (v === null ? "n/a" : `$${v.toFixed(2)}`);
|
|
2
3
|
const mins = (m) => (m < 90 ? `${Math.round(m)}m` : m < 2880 ? `${(m / 60).toFixed(1)}h` : `${(m / 1440).toFixed(1)}d`);
|
|
3
4
|
/** A title for agent output: quoted, inner quotes swapped, at most 50 characters. */
|
|
4
5
|
const quote = (title) => `"${Array.from(title.replace(/"/g, "'")).slice(0, 50).join("")}"`;
|
|
5
|
-
function
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
return (lines ? g?.nLines : g?.n) ?? 0;
|
|
9
|
-
};
|
|
10
|
-
if (v.kind === "single")
|
|
11
|
-
return "one group only";
|
|
12
|
-
if (v.kind === "few")
|
|
13
|
-
return `too few items to tell (${n(v.a)}/${n(v.b)}, need 5 each)`;
|
|
14
|
-
if (v.kind === "same")
|
|
15
|
-
return "no clear difference (<20%)";
|
|
16
|
-
return `${v.a} ${Math.round((v.by ?? 0) * 100)}% less than ${v.b} (n ${n(v.a)}/${n(v.b)})`;
|
|
6
|
+
function summary(c) {
|
|
7
|
+
const kind = c.kind === "delegated" ? "Work handed to subagents" : "Work done by the main agent";
|
|
8
|
+
return `${kind} by ${c.dimension}: ${comparisonText(c, en => en)}`;
|
|
17
9
|
}
|
|
18
10
|
export function itemsView(w) {
|
|
19
11
|
if (!w)
|
|
@@ -27,10 +19,10 @@ export function itemsView(w) {
|
|
|
27
19
|
`median item ${usd(w.cost.median)}, ${w.cost.medianMinutes ?? "n/a"} min in progress`,
|
|
28
20
|
`closed by: ${kinds || "none"}`,
|
|
29
21
|
`stall time in finished items, by what woke the main: ${stalls || "none"}`,
|
|
30
|
-
"
|
|
22
|
+
"Median costs for similar work (differences, not causes):",
|
|
31
23
|
];
|
|
32
24
|
for (const c of w.compare)
|
|
33
|
-
out.push(
|
|
25
|
+
out.push(summary(c));
|
|
34
26
|
if (w.open.length)
|
|
35
27
|
out.push("open, stopped where / waiting on / how long:");
|
|
36
28
|
for (const o of w.open.slice(0, 4))
|
|
@@ -48,11 +40,11 @@ export function itemsFinding(w) {
|
|
|
48
40
|
return undefined;
|
|
49
41
|
// Model first: a role split mixes kinds of work (planning vs building), and versions overlap other changes.
|
|
50
42
|
const order = ["model", "anchorloop", "role"];
|
|
51
|
-
const cheaper = w.compare.filter((c) => c.verdict.kind === "cheaper").sort((a, b) => (a.kind === b.kind ? 0 : a.kind === "delegated" ? -1 : 1) || order.indexOf(a.dimension) - order.indexOf(b.dimension))[0];
|
|
43
|
+
const cheaper = w.compare.filter((c) => c.verdict.kind === "cheaper" || c.verdictLines.kind === "cheaper").sort((a, b) => (a.kind === b.kind ? 0 : a.kind === "delegated" ? -1 : 1) || order.indexOf(a.dimension) - order.indexOf(b.dimension))[0];
|
|
52
44
|
const waits = w.open.filter((o) => o.kind !== "human" && o.kind !== "working" && o.waitMinutes >= 60);
|
|
53
45
|
const parts = [];
|
|
54
46
|
if (cheaper)
|
|
55
|
-
parts.push(`${cheaper
|
|
47
|
+
parts.push(`${summary(cheaper)} This is a difference, not its cause.`);
|
|
56
48
|
if (waits.length)
|
|
57
49
|
parts.push(`${waits.length} open item(s) waiting over 1h, longest ${mins(Math.max(...waits.map((o) => o.waitMinutes)))} on ${waits.sort((a, b) => b.waitMinutes - a.waitMinutes)[0].on ?? waits[0].kind}`);
|
|
58
50
|
return parts.length ? `Work items: ${parts.join("; ")} → items` : undefined;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function verdictText(c, v, L, lines = false) {
|
|
2
|
+
const n = (name) => {
|
|
3
|
+
const g = c.groups.find(x => x.value === name);
|
|
4
|
+
return (lines ? g?.nLines : g?.n) ?? 0;
|
|
5
|
+
};
|
|
6
|
+
const what = lines ? L("per 100 changed lines", "每改 100 行") : L("per item", "每件");
|
|
7
|
+
if (v.kind === "single")
|
|
8
|
+
return `${what}: ` + (v.a ? L(`only ${v.a} (${n(v.a)} items)`, `只有 ${v.a}(${n(v.a)} 件)`) : L("no items with line counts", "沒有可計算行數的工作"));
|
|
9
|
+
const counts = L(`${n(v.a)} vs ${n(v.b)} items`, `${n(v.a)} 件 vs ${n(v.b)} 件`);
|
|
10
|
+
if (v.kind === "few")
|
|
11
|
+
return L(`${what}: too few to tell (${v.a} vs ${v.b}: ${counts}; need 5 each)`, `件數太少,還看不出來${what}誰比較省(${v.a} vs ${v.b}:${counts},每組至少 5 件)`);
|
|
12
|
+
if (v.kind === "same")
|
|
13
|
+
return L(`${what}, ${v.a} and ${v.b} cost about the same (under 20% apart; ${counts})`, `${what},${v.a} 和 ${v.b} 花費差不到兩成(${counts})`);
|
|
14
|
+
const pct = Math.round((v.by ?? 0) * 100);
|
|
15
|
+
return L(`${what}, ${v.a} costs ${pct}% less than ${v.b} (${counts})`, `${v.a} ${what}比 ${v.b} 便宜 ${pct}%(${counts})`);
|
|
16
|
+
}
|
|
17
|
+
export function comparisonText(c, L) {
|
|
18
|
+
const a = c.verdict, b = c.verdictLines;
|
|
19
|
+
let text = verdictText(c, a, L) + L("; ", ";") + verdictText(c, b, L, true) + L(".", "。");
|
|
20
|
+
if ([a, b].every(v => v.kind === "same" || v.kind === "cheaper")) {
|
|
21
|
+
if (![a.a, a.b].includes(b.a) || ![a.a, a.b].includes(b.b))
|
|
22
|
+
text += L(" The two measures compare different groups.", "兩種量法比較的不是同一對組別。");
|
|
23
|
+
else if (a.kind !== b.kind || (a.kind === "cheaper" && a.a !== b.a))
|
|
24
|
+
text += L(" Item sizes may differ, so we can't say which is cheaper overall.", "兩種量法不一致,可能是工作大小不同,不能說誰比較省。");
|
|
25
|
+
}
|
|
26
|
+
return text;
|
|
27
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-evals",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Usage and process records for pi: how skills, packages, ask-user, monitors and subagents are used, back-filled from past sessions, with a static report and an evals_query tool",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/src/report/concepts.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ReportModel } from "../model.ts";
|
|
2
2
|
import { type Change, esc, num, usd, type Words } from "./format.ts";
|
|
3
3
|
import type { Week } from "./week.ts";
|
|
4
|
-
import {
|
|
4
|
+
import { comparisonText } from "../work/wording.ts";
|
|
5
5
|
|
|
6
6
|
/** The two work-item ideas, with this report's own numbers. */
|
|
7
7
|
function workCards(m: ReportModel, L: Words) {
|
|
@@ -11,7 +11,7 @@ function workCards(m: ReportModel, L: Words) {
|
|
|
11
11
|
return { attribution: [L("Who a cost belongs to", "花費歸屬"), none], cheaper: [L("When is one way cheaper?", "怎麼比才算比較省"), none] };
|
|
12
12
|
}
|
|
13
13
|
const first = w.compare.find((c) => c.kind === "delegated") ?? w.compare[0];
|
|
14
|
-
const now = first ?
|
|
14
|
+
const now = first ? comparisonText(first, L) : L("No finished items to compare yet.", "還沒有完成的工作可以比。");
|
|
15
15
|
return {
|
|
16
16
|
attribution: [
|
|
17
17
|
L("Who a cost belongs to", "花費歸屬"),
|
package/src/report/work.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { comparisonText } from "../work/wording.ts";
|
|
1
2
|
/** The 「工作」 section: one row per work item, a like-with-like comparison, and the items still open. */
|
|
2
3
|
import type { ReportModel } from "../model.ts";
|
|
3
|
-
import type {
|
|
4
|
+
import type { WorkModel } from "../work/model.ts";
|
|
4
5
|
import { esc, type Lang, num, usd, type Words, words } from "./format.ts";
|
|
5
6
|
|
|
6
7
|
const SHOWN = 15;
|
|
@@ -11,18 +12,6 @@ export function span(minutes: number, L: Words) {
|
|
|
11
12
|
return L(`${(minutes / 1440).toFixed(1)} days`, `${(minutes / 1440).toFixed(1)} 天`);
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
const pct = (v: number) => `${Math.round(v * 100)}%`;
|
|
15
|
-
|
|
16
|
-
export function verdictText(c: Comparison, v: Verdict, L: Words, lines = false) {
|
|
17
|
-
const g = (value?: string) => c.groups.find((x) => x.value === value);
|
|
18
|
-
const n = (value?: string) => (lines ? g(value)?.nLines : g(value)?.n) ?? 0;
|
|
19
|
-
const what = lines ? L("per 100 changed lines", "每百行") : L("per item", "每件");
|
|
20
|
-
if (v.kind === "single") return v.a ? L(`Only one group (${v.a}): nothing to compare it with.`, `只有一組(${v.a}),沒有可比的對象。`) : L("No items with a line count.", "沒有算得出行數的工作。");
|
|
21
|
-
if (v.kind === "few") return L(`Too few items to tell yet (${v.a} ${n(v.a)}, ${v.b} ${n(v.b)}; each group needs 5).`, `件數太少,還看不出來(${v.a} ${n(v.a)} 件、${v.b} ${n(v.b)} 件,每組至少要 5 件)。`);
|
|
22
|
-
if (v.kind === "same") return L(`${v.a} and ${v.b} cost about the same ${what} (less than 20% apart).`, `${v.a} 和 ${v.b} ${what}花費差不到兩成,看不出差別。`);
|
|
23
|
-
return L(`${v.a} costs ${pct(v.by ?? 0)} less ${what} than ${v.b} (median of ${n(v.a)} and ${n(v.b)} items of the same kind). This is a difference, not its cause.`, `${v.a} ${what}比 ${v.b} 便宜 ${pct(v.by ?? 0)}(同類工作的中位數,各 ${n(v.a)}、${n(v.b)} 件)。這是差異,不是原因。`);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
15
|
function stallText(stalls: Record<string, number>, m: ReportModel, lang: Lang) {
|
|
27
16
|
const L = words(lang);
|
|
28
17
|
const parts = Object.entries(stalls)
|
|
@@ -55,7 +44,7 @@ export function workSection(m: ReportModel, lang: Lang, cards: { attribution: st
|
|
|
55
44
|
(c) =>
|
|
56
45
|
`<article class="panel"><h3>${esc(kinds[c.kind])} / ${L("by", "依")}${esc(dims[c.dimension])}</h3><div class="scroll"><table><thead><tr><th scope="col">${esc(dims[c.dimension])}</th><th scope="col">${L("Items", "件數")}</th><th scope="col">${L("Median per item", "每件中位數")}</th><th scope="col">${L("Per 100 lines (items)", "每百行(件數)")}</th></tr></thead><tbody>${
|
|
57
46
|
c.groups.map((g) => `<tr><td>${esc(g.value)}</td><td>${num(g.n)}</td><td>${usd(g.median)}</td><td>${g.per100 === null ? "—" : `${usd(g.per100)}(${num(g.nLines)})`}</td></tr>`).join("")
|
|
58
|
-
}</tbody></table></div><p class="verdict">${esc(
|
|
47
|
+
}</tbody></table></div><p class="verdict">${esc(comparisonText(c, L))} ${L("This is a difference, not its cause.", "這是差異,不是原因。")}</p></article>`,
|
|
59
48
|
)
|
|
60
49
|
.join("")
|
|
61
50
|
: `<p class="muted">${L("No finished items to compare.", "沒有可比較的已完成工作。")}</p>`;
|
package/src/work/query.ts
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
|
+
import { comparisonText } from "./wording.ts";
|
|
1
2
|
/** The `items` view of `evals_query` and its line in `findings`: numbers, names, and titles in double quotes. */
|
|
2
|
-
import type { Comparison,
|
|
3
|
+
import type { Comparison, WorkModel } from "./model.ts";
|
|
3
4
|
|
|
4
5
|
const usd = (v: number | null) => (v === null ? "n/a" : `$${v.toFixed(2)}`);
|
|
5
6
|
const mins = (m: number) => (m < 90 ? `${Math.round(m)}m` : m < 2880 ? `${(m / 60).toFixed(1)}h` : `${(m / 1440).toFixed(1)}d`);
|
|
6
7
|
/** A title for agent output: quoted, inner quotes swapped, at most 50 characters. */
|
|
7
8
|
const quote = (title: string) => `"${Array.from(title.replace(/"/g, "'")).slice(0, 50).join("")}"`;
|
|
8
9
|
|
|
9
|
-
function
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
return (lines ? g?.nLines : g?.n) ?? 0;
|
|
13
|
-
};
|
|
14
|
-
if (v.kind === "single") return "one group only";
|
|
15
|
-
if (v.kind === "few") return `too few items to tell (${n(v.a)}/${n(v.b)}, need 5 each)`;
|
|
16
|
-
if (v.kind === "same") return "no clear difference (<20%)";
|
|
17
|
-
return `${v.a} ${Math.round((v.by ?? 0) * 100)}% less than ${v.b} (n ${n(v.a)}/${n(v.b)})`;
|
|
10
|
+
function summary(c: Comparison) {
|
|
11
|
+
const kind = c.kind === "delegated" ? "Work handed to subagents" : "Work done by the main agent";
|
|
12
|
+
return `${kind} by ${c.dimension}: ${comparisonText(c, en => en)}`;
|
|
18
13
|
}
|
|
19
14
|
|
|
20
15
|
export function itemsView(w: WorkModel | null): string[] {
|
|
@@ -28,9 +23,9 @@ export function itemsView(w: WorkModel | null): string[] {
|
|
|
28
23
|
`median item ${usd(w.cost.median)}, ${w.cost.medianMinutes ?? "n/a"} min in progress`,
|
|
29
24
|
`closed by: ${kinds || "none"}`,
|
|
30
25
|
`stall time in finished items, by what woke the main: ${stalls || "none"}`,
|
|
31
|
-
"
|
|
26
|
+
"Median costs for similar work (differences, not causes):",
|
|
32
27
|
];
|
|
33
|
-
for (const c of w.compare) out.push(
|
|
28
|
+
for (const c of w.compare) out.push(summary(c));
|
|
34
29
|
if (w.open.length) out.push("open, stopped where / waiting on / how long:");
|
|
35
30
|
for (const o of w.open.slice(0, 4)) out.push(`- ${quote(o.title || o.key)} ${o.kind}${o.on ? ` on ${o.on}` : ""}, ${mins(o.waitMinutes)}`);
|
|
36
31
|
const costly = [...w.list].sort((a, b) => b.main + b.child - (a.main + a.child)).slice(0, 3);
|
|
@@ -44,10 +39,10 @@ export function itemsFinding(w: WorkModel | null): string | undefined {
|
|
|
44
39
|
if (!w) return undefined;
|
|
45
40
|
// Model first: a role split mixes kinds of work (planning vs building), and versions overlap other changes.
|
|
46
41
|
const order = ["model", "anchorloop", "role"];
|
|
47
|
-
const cheaper = w.compare.filter((c) => c.verdict.kind === "cheaper").sort((a, b) => (a.kind === b.kind ? 0 : a.kind === "delegated" ? -1 : 1) || order.indexOf(a.dimension) - order.indexOf(b.dimension))[0];
|
|
42
|
+
const cheaper = w.compare.filter((c) => c.verdict.kind === "cheaper" || c.verdictLines.kind === "cheaper").sort((a, b) => (a.kind === b.kind ? 0 : a.kind === "delegated" ? -1 : 1) || order.indexOf(a.dimension) - order.indexOf(b.dimension))[0];
|
|
48
43
|
const waits = w.open.filter((o) => o.kind !== "human" && o.kind !== "working" && o.waitMinutes >= 60);
|
|
49
44
|
const parts: string[] = [];
|
|
50
|
-
if (cheaper) parts.push(`${cheaper
|
|
45
|
+
if (cheaper) parts.push(`${summary(cheaper)} This is a difference, not its cause.`);
|
|
51
46
|
if (waits.length) parts.push(`${waits.length} open item(s) waiting over 1h, longest ${mins(Math.max(...waits.map((o) => o.waitMinutes)))} on ${waits.sort((a, b) => b.waitMinutes - a.waitMinutes)[0].on ?? waits[0].kind}`);
|
|
52
47
|
return parts.length ? `Work items: ${parts.join("; ")} → items` : undefined;
|
|
53
48
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Comparison, Verdict } from "./model.ts";
|
|
2
|
+
import type { Words } from "../report/format.ts";
|
|
3
|
+
|
|
4
|
+
export function verdictText(c: Comparison, v: Verdict, L: Words, lines = false) {
|
|
5
|
+
const n = (name?: string) => {
|
|
6
|
+
const g = c.groups.find(x => x.value === name);
|
|
7
|
+
return (lines ? g?.nLines : g?.n) ?? 0;
|
|
8
|
+
};
|
|
9
|
+
const what = lines ? L("per 100 changed lines", "每改 100 行") : L("per item", "每件");
|
|
10
|
+
if (v.kind === "single") return `${what}: ` + (v.a ? L(`only ${v.a} (${n(v.a)} items)`, `只有 ${v.a}(${n(v.a)} 件)`) : L("no items with line counts", "沒有可計算行數的工作"));
|
|
11
|
+
const counts = L(`${n(v.a)} vs ${n(v.b)} items`, `${n(v.a)} 件 vs ${n(v.b)} 件`);
|
|
12
|
+
if (v.kind === "few") return L(`${what}: too few to tell (${v.a} vs ${v.b}: ${counts}; need 5 each)`, `件數太少,還看不出來${what}誰比較省(${v.a} vs ${v.b}:${counts},每組至少 5 件)`);
|
|
13
|
+
if (v.kind === "same") return L(`${what}, ${v.a} and ${v.b} cost about the same (under 20% apart; ${counts})`, `${what},${v.a} 和 ${v.b} 花費差不到兩成(${counts})`);
|
|
14
|
+
const pct = Math.round((v.by ?? 0) * 100);
|
|
15
|
+
return L(`${what}, ${v.a} costs ${pct}% less than ${v.b} (${counts})`, `${v.a} ${what}比 ${v.b} 便宜 ${pct}%(${counts})`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function comparisonText(c: Comparison, L: Words) {
|
|
19
|
+
const a = c.verdict, b = c.verdictLines;
|
|
20
|
+
let text = verdictText(c, a, L) + L("; ", ";") + verdictText(c, b, L, true) + L(".", "。");
|
|
21
|
+
if ([a, b].every(v => v.kind === "same" || v.kind === "cheaper")) {
|
|
22
|
+
if (![a.a, a.b].includes(b.a) || ![a.a, a.b].includes(b.b)) text += L(" The two measures compare different groups.", "兩種量法比較的不是同一對組別。");
|
|
23
|
+
else if (a.kind !== b.kind || (a.kind === "cheaper" && a.a !== b.a)) text += L(" Item sizes may differ, so we can't say which is cheaper overall.", "兩種量法不一致,可能是工作大小不同,不能說誰比較省。");
|
|
24
|
+
}
|
|
25
|
+
return text;
|
|
26
|
+
}
|