@seikika/astro-report 0.0.0-stage → 0.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/LICENSE +9 -0
- package/README.md +32 -2
- package/integration.d.mts +13 -0
- package/integration.mjs +44 -0
- package/package.json +57 -3
- package/src/ReportApp.vue +220 -0
- package/src/ReportContent.vue +13 -0
- package/src/ReportView.vue +88 -0
- package/src/layouts/DefaultLayout.astro +17 -0
- package/src/lib/bars.ts +290 -0
- package/src/lib/basis.ts +157 -0
- package/src/lib/campaigns.ts +410 -0
- package/src/lib/compare.ts +204 -0
- package/src/lib/dom.ts +43 -0
- package/src/lib/kinds.ts +84 -0
- package/src/lib/levels.ts +61 -0
- package/src/lib/rings.ts +244 -0
- package/src/lib/routes.ts +118 -0
- package/src/lib/rules.ts +143 -0
- package/src/lib/status.ts +150 -0
- package/src/lib/summary.ts +231 -0
- package/src/lib/text.ts +57 -0
- package/src/lib/tracks.ts +264 -0
- package/src/lib/words.ts +72 -0
- package/src/report-view.ts +37 -0
- package/src/report.astro +27 -0
- package/src/report.css +359 -0
- package/src/types.ts +141 -0
- package/src/views/campaigns.ts +265 -0
- package/src/views/catalog.ts +456 -0
- package/src/views/compare.ts +676 -0
- package/src/views/entity.ts +443 -0
- package/src/views/overview.ts +639 -0
- package/src/views/rule.ts +153 -0
- package/src/views/scorecards.ts +947 -0
- package/src/views/tracks.ts +294 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type { ReportData } from "../types";
|
|
2
|
+
import { levelName } from "./campaigns";
|
|
3
|
+
import { el, enc } from "./dom";
|
|
4
|
+
import { ring, title } from "./rings";
|
|
5
|
+
import { floorOf } from "./rules";
|
|
6
|
+
import { RAMP } from "./tracks";
|
|
7
|
+
import { andList, fmt } from "./words";
|
|
8
|
+
|
|
9
|
+
export function daysLeft(end) {
|
|
10
|
+
if (!end) return null;
|
|
11
|
+
var ms = Date.parse(end + "T23:59:59Z") - Date.now();
|
|
12
|
+
return isNaN(ms) ? null : Math.ceil(ms / 86400000);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function isPassing(o) {
|
|
16
|
+
return o === "pass" || o === "waived";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// A check that was not run ("unknown") is not a failure: the scorer lets it hold a level provisionally.
|
|
20
|
+
export function isFailing(o) {
|
|
21
|
+
return o != null && !isPassing(o) && o !== "skipped" && o !== "unknown";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// The rules an entity still fails at or below `level` (what stands between it and that level).
|
|
25
|
+
export function blockers(sc, score, level) {
|
|
26
|
+
var order = sc.levels || [];
|
|
27
|
+
var cap = order.indexOf(level);
|
|
28
|
+
return Object.keys(score.rules || {})
|
|
29
|
+
.filter(function (n) {
|
|
30
|
+
var rl = ((sc.rules || {})[n] || {}).level;
|
|
31
|
+
return isFailing(score.rules[n]) && order.indexOf(rl) <= cap;
|
|
32
|
+
})
|
|
33
|
+
.sort();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// One bar per scorecard on a track, filled to its share at the top level; the dashed line is their
|
|
37
|
+
// average, which is the track's ring.
|
|
38
|
+
export function ringWords(t) {
|
|
39
|
+
return "average share at the top level, across its " + fmt(t.averaged) + " scorecards";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// A scorecard whose ladder stops below gold: its share is at its own top level, which a reader would
|
|
43
|
+
// otherwise take for gold.
|
|
44
|
+
export function shortWhy(D: ReportData, t) {
|
|
45
|
+
if (!(t.short || []).length) return "";
|
|
46
|
+
return andList(
|
|
47
|
+
t.short.map(function (n) {
|
|
48
|
+
var lv = ((D.scorecards || {})[n] || {}).levels || [];
|
|
49
|
+
return title(D, n) + " (top level " + lv[lv.length - 1] + ")";
|
|
50
|
+
}),
|
|
51
|
+
) + (t.short.length === 1 ? " stops below gold, so the ring counts its share at that top level" : " stop below gold, so the ring counts each one's share at its own top level");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function ringWhy(D: ReportData, t) {
|
|
55
|
+
if (!t.capped.length) return "";
|
|
56
|
+
var lv = levelName(floorOf(D, t.capped[0]));
|
|
57
|
+
return (
|
|
58
|
+
andList(
|
|
59
|
+
t.capped.map(function (n) {
|
|
60
|
+
return title(D, n);
|
|
61
|
+
}),
|
|
62
|
+
) +
|
|
63
|
+
(t.capped.length === 1 ? " holds the repository level at " + lv + " until it gains a higher level" : " hold the repository level until they gain a higher level")
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function trackSlots(D: ReportData, t) {
|
|
68
|
+
var cards = t.cards.filter(function (c) {
|
|
69
|
+
return !c.row.compare && c.row.scored;
|
|
70
|
+
});
|
|
71
|
+
if (!cards.length || t.pct == null) return null;
|
|
72
|
+
var said = cards.map(function (c) {
|
|
73
|
+
return title(D, c.row.name) + ": " + c.row.topShare + "% at the top level (" + levelName(c.row.top || "top") + ")";
|
|
74
|
+
});
|
|
75
|
+
var named = function (c) {
|
|
76
|
+
var top = c.row.top || "top";
|
|
77
|
+
return title(D, c.row.name) + ": " + c.row.topShare + "%" + (top === "gold" ? "" : " at " + levelName(top));
|
|
78
|
+
};
|
|
79
|
+
var low = cards.reduce(function (a, c, i) {
|
|
80
|
+
return a >= 0 && cards[a].row.topShare <= c.row.topShare ? a : i;
|
|
81
|
+
}, -1);
|
|
82
|
+
var high = cards.reduce(function (a, c, i) {
|
|
83
|
+
return a >= 0 && cards[a].row.topShare >= c.row.topShare ? a : i;
|
|
84
|
+
}, -1);
|
|
85
|
+
var rest =
|
|
86
|
+
(low >= 0 ? "Lowest share at the top level, " + named(cards[low]) : "Each bar is one scorecard") +
|
|
87
|
+
(high >= 0 && high !== low && cards[high].row.topShare > cards[low].row.topShare ? " · highest, " + named(cards[high]) : "") +
|
|
88
|
+
" · dashed line: their average, " + t.pct + "%";
|
|
89
|
+
var cap = el("div", { className: "slotcap", ariaHidden: "true", textContent: rest });
|
|
90
|
+
var bars = cards.map(function (c, i) {
|
|
91
|
+
return el("span", {
|
|
92
|
+
className: "slot",
|
|
93
|
+
style: "--h:" + c.row.topShare + "%;--c:" + RAMP,
|
|
94
|
+
onpointerenter: function () {
|
|
95
|
+
show(i);
|
|
96
|
+
},
|
|
97
|
+
onclick: function () {
|
|
98
|
+
if (on === i) location.hash = "scorecard/" + enc(c.row.name);
|
|
99
|
+
else show(i);
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
var on = -1;
|
|
104
|
+
var show = function (i) {
|
|
105
|
+
if (on >= 0) bars[on].classList.remove("on");
|
|
106
|
+
on = i;
|
|
107
|
+
if (i < 0) {
|
|
108
|
+
cap.textContent = rest;
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
bars[i].classList.add("on");
|
|
112
|
+
cap.textContent = named(cards[i]) + " · bar " + (i + 1) + " of " + cards.length + " · click or Enter to open it";
|
|
113
|
+
};
|
|
114
|
+
var wrap = el(
|
|
115
|
+
"div",
|
|
116
|
+
{ className: "mix" },
|
|
117
|
+
el(
|
|
118
|
+
"div",
|
|
119
|
+
{
|
|
120
|
+
className: "slots",
|
|
121
|
+
role: "img",
|
|
122
|
+
tabIndex: 0,
|
|
123
|
+
ariaLabel: "Share at the top level, per scorecard: " + said.join("; ") + ". Average " + t.pct + "%.",
|
|
124
|
+
style: "--avg:" + t.pct + "%",
|
|
125
|
+
onpointerleave: function () {
|
|
126
|
+
show(-1);
|
|
127
|
+
},
|
|
128
|
+
onfocus: function () {
|
|
129
|
+
if (on < 0) show(low >= 0 ? low : 0);
|
|
130
|
+
},
|
|
131
|
+
onblur: function () {
|
|
132
|
+
show(-1);
|
|
133
|
+
},
|
|
134
|
+
onkeydown: function (e) {
|
|
135
|
+
if (e.key === "Enter" && on >= 0) {
|
|
136
|
+
location.hash = "scorecard/" + enc(cards[on].row.name);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (e.key !== "ArrowRight" && e.key !== "ArrowLeft") return;
|
|
140
|
+
e.preventDefault();
|
|
141
|
+
show(on < 0 ? (e.key === "ArrowRight" ? 0 : bars.length - 1) : (on + (e.key === "ArrowRight" ? 1 : bars.length - 1)) % bars.length);
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
...bars,
|
|
145
|
+
el("span", { className: "avg", ariaHidden: "true" }),
|
|
146
|
+
),
|
|
147
|
+
cap,
|
|
148
|
+
);
|
|
149
|
+
return wrap;
|
|
150
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import type { ReportData } from "../types";
|
|
2
|
+
import { levelOrder, tallyLevels, unrunIn } from "./bars";
|
|
3
|
+
import { basisOf } from "./basis";
|
|
4
|
+
import { campaignStanding } from "./campaigns";
|
|
5
|
+
import { known } from "./levels";
|
|
6
|
+
import { floorOf, isComparative } from "./rules";
|
|
7
|
+
import { isPassing } from "./status";
|
|
8
|
+
import { furthestTrack, trackTitle } from "./tracks";
|
|
9
|
+
import { title } from "./rings";
|
|
10
|
+
import { andList, plural } from "./words";
|
|
11
|
+
|
|
12
|
+
// A share never rounds to 100% while one entity is short of it, nor to 0% while one is there.
|
|
13
|
+
export function share(n, of) {
|
|
14
|
+
if (!of) return 0;
|
|
15
|
+
var p = Math.round((100 * n) / of);
|
|
16
|
+
return n === of ? 100 : n === 0 ? 0 : Math.min(99, Math.max(1, p));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function scorecardRows(D: ReportData) {
|
|
20
|
+
return Object.keys(D.scorecards || {})
|
|
21
|
+
.map(function (name) {
|
|
22
|
+
var sc = D.scorecards[name];
|
|
23
|
+
var ents = Object.entries((D.scores || {})[name] || {});
|
|
24
|
+
var parts = tallyLevels(ents, levelOrder(sc.levels));
|
|
25
|
+
var count = function (l) {
|
|
26
|
+
var p = parts.find(function (x) {
|
|
27
|
+
return x.level === l;
|
|
28
|
+
});
|
|
29
|
+
return p ? p.n : 0;
|
|
30
|
+
};
|
|
31
|
+
var top = (sc.levels || [])[(sc.levels || []).length - 1];
|
|
32
|
+
var scored = ents.filter(function (p) {
|
|
33
|
+
return p[1].level !== "skipped";
|
|
34
|
+
}).length;
|
|
35
|
+
return {
|
|
36
|
+
name: name,
|
|
37
|
+
sc: sc,
|
|
38
|
+
compare: isComparative(D, name),
|
|
39
|
+
parts: parts,
|
|
40
|
+
none: count("none"),
|
|
41
|
+
bronze: top === "bronze" ? 0 : count("bronze"),
|
|
42
|
+
top: top,
|
|
43
|
+
topShare: share(count(top), scored),
|
|
44
|
+
scored: scored,
|
|
45
|
+
total: ents.length,
|
|
46
|
+
weight: isComparative(D, name) ? -1 : count("none") * 1000 + (top === "bronze" ? 0 : count("bronze")),
|
|
47
|
+
};
|
|
48
|
+
})
|
|
49
|
+
.sort(function (a, b) {
|
|
50
|
+
return b.weight - a.weight || a.name.localeCompare(b.name);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function campaignNamesSorted(D: ReportData) {
|
|
55
|
+
var campaigns = D.campaigns || {};
|
|
56
|
+
var rank = { off: 0, empty: 1, on: 2 };
|
|
57
|
+
return Object.keys(campaigns)
|
|
58
|
+
.filter(function (n) {
|
|
59
|
+
var st = campaigns[n].status;
|
|
60
|
+
return st === "active" || st === "scheduled" || st === "ended";
|
|
61
|
+
})
|
|
62
|
+
.sort(function (a, b) {
|
|
63
|
+
var ca = campaigns[a];
|
|
64
|
+
var cb = campaigns[b];
|
|
65
|
+
return rank[campaignStanding(D, ca)] - rank[campaignStanding(D, cb)] || (ca.percent || 0) - (cb.percent || 0) || a.localeCompare(b);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function scoredKinds(D: ReportData) {
|
|
70
|
+
var set = {};
|
|
71
|
+
Object.keys(D.scorecards || {}).forEach(function (name) {
|
|
72
|
+
var k = D.scorecards[name].kind;
|
|
73
|
+
if (k && !isComparative(D, name)) set[k] = true;
|
|
74
|
+
});
|
|
75
|
+
return set;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function catalogKindsSorted(D: ReportData) {
|
|
79
|
+
var catalog = D.catalog || {};
|
|
80
|
+
var scored = scoredKinds(D);
|
|
81
|
+
return Object.keys(catalog).sort(function (a, b) {
|
|
82
|
+
var as = scored[a] ? 0 : 1;
|
|
83
|
+
var bs = scored[b] ? 0 : 1;
|
|
84
|
+
if (as !== bs) return as - bs;
|
|
85
|
+
return catalog[b].length - catalog[a].length || a.localeCompare(b);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Facts every view shares, computed once per load.
|
|
90
|
+
export function summarize(D: ReportData) {
|
|
91
|
+
var rows = scorecardRows(D);
|
|
92
|
+
var byEntity = {};
|
|
93
|
+
var shortOfTop = new Set();
|
|
94
|
+
var marks = new Map();
|
|
95
|
+
var checks = { pass: 0, fail: 0, unknown: 0, vacuous: 0 };
|
|
96
|
+
rows.forEach(function (r) {
|
|
97
|
+
if (r.compare) return;
|
|
98
|
+
var order = levelOrder(r.sc.levels);
|
|
99
|
+
var unassessed = new Set((D.unassessed || {})[r.name] || []);
|
|
100
|
+
Object.entries((D.scores || {})[r.name] || {}).forEach(function (pair) {
|
|
101
|
+
var id = pair[0];
|
|
102
|
+
var s = pair[1];
|
|
103
|
+
if (s.level === "skipped") return;
|
|
104
|
+
var cur = byEntity[id];
|
|
105
|
+
var rank = order.indexOf(s.level);
|
|
106
|
+
var norm = ["none", "bronze", "silver", "gold"].indexOf(s.level) >= 0 ? s.level : rank <= 0 ? "none" : "gold";
|
|
107
|
+
if (!cur || ["none", "bronze", "silver", "gold"].indexOf(norm) < ["none", "bronze", "silver", "gold"].indexOf(cur)) byEntity[id] = norm;
|
|
108
|
+
if (s.level !== (r.sc.levels || []).slice(-1)[0]) shortOfTop.add(id);
|
|
109
|
+
var st = unassessed.has(id) ? "hollow" : unrunIn(r.sc, s).length ? "unrun" : "";
|
|
110
|
+
if (st) (marks.get(id) || marks.set(id, []).get(id)).push([norm, st]);
|
|
111
|
+
Object.keys(s.rules || {}).forEach(function (rule) {
|
|
112
|
+
var o = s.rules[rule];
|
|
113
|
+
if (isPassing(o) && unassessed.has(id) && basisOf((r.sc.rules || {})[rule]) === "judged") checks.vacuous++;
|
|
114
|
+
else if (isPassing(o)) checks.pass++;
|
|
115
|
+
else if (o === "fail") checks.fail++;
|
|
116
|
+
else if (o === "unknown") checks.unknown++;
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
var catalog = D.catalog || {};
|
|
121
|
+
var entityCount = Object.keys(catalog).reduce(function (n, k) {
|
|
122
|
+
return n + catalog[k].length;
|
|
123
|
+
}, 0);
|
|
124
|
+
var kindOf = {};
|
|
125
|
+
Object.keys(catalog).forEach(function (k) {
|
|
126
|
+
catalog[k].forEach(function (id) {
|
|
127
|
+
kindOf[id] = k;
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
// Whether an entity's weakest level rests on a scorecard no agent has assessed it on, or on checks not run.
|
|
131
|
+
var worstState = new Map();
|
|
132
|
+
marks.forEach(function (list, id) {
|
|
133
|
+
var at = list.filter(function (m) {
|
|
134
|
+
return m[0] === byEntity[id];
|
|
135
|
+
});
|
|
136
|
+
var st = at.some(function (m) {
|
|
137
|
+
return m[1] === "hollow";
|
|
138
|
+
})
|
|
139
|
+
? "hollow"
|
|
140
|
+
: at.length
|
|
141
|
+
? "unrun"
|
|
142
|
+
: "";
|
|
143
|
+
if (st) worstState.set(id, st);
|
|
144
|
+
});
|
|
145
|
+
// At the top level of every scorecard that rates it, whatever that scorecard calls its top.
|
|
146
|
+
var atTop = Object.keys(byEntity).filter(function (id) {
|
|
147
|
+
return !shortOfTop.has(id);
|
|
148
|
+
});
|
|
149
|
+
return { rows: rows, worst: byEntity, atTop: atTop, worstState: worstState, checks: checks, entityCount: entityCount, kindOf: kindOf, repo: repoLevel(D) };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function repoLevel(D: ReportData) {
|
|
153
|
+
var rollup = Array.isArray(D.repoRollup) ? D.repoRollup : [];
|
|
154
|
+
if (!rollup.length) return null;
|
|
155
|
+
var ladder = ["none", "bronze", "silver", "gold"];
|
|
156
|
+
var constituents = rollup
|
|
157
|
+
.filter(function (name) {
|
|
158
|
+
return (D.scorecards || {})[name];
|
|
159
|
+
})
|
|
160
|
+
.map(function (name) {
|
|
161
|
+
return { name: name, level: floorOf(D, name) || "none", top: "" };
|
|
162
|
+
});
|
|
163
|
+
if (!constituents.length) return null;
|
|
164
|
+
constituents.forEach(function (c) {
|
|
165
|
+
var lv = (D.scorecards[c.name].levels || []).slice(-1)[0];
|
|
166
|
+
c.top = known(lv) || lv;
|
|
167
|
+
});
|
|
168
|
+
var ceiling = constituents.reduce(function (m, c) {
|
|
169
|
+
return ladder.indexOf(c.top) >= 0 && ladder.indexOf(c.top) < ladder.indexOf(m) ? c.top : m;
|
|
170
|
+
}, "gold");
|
|
171
|
+
var floor = constituents.reduce(function (m, c) {
|
|
172
|
+
return ladder.indexOf(c.level) < ladder.indexOf(m) ? c.level : m;
|
|
173
|
+
}, "gold");
|
|
174
|
+
var next = ladder[ladder.indexOf(floor) + 1] || null;
|
|
175
|
+
return {
|
|
176
|
+
ladder: ladder,
|
|
177
|
+
floor: floor,
|
|
178
|
+
ceiling: ceiling,
|
|
179
|
+
next: next,
|
|
180
|
+
constituents: constituents,
|
|
181
|
+
holding: constituents.filter(function (c) {
|
|
182
|
+
return c.level === floor;
|
|
183
|
+
}),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Before any connector has run, no entity has a level: an empty denominator is never a pass.
|
|
188
|
+
export var NO_FACTS = "Not scored yet: no connector has delivered facts, so no entity has a level.";
|
|
189
|
+
export function noFacts(S: Summary) {
|
|
190
|
+
return S.rows.length > 0 && !Object.keys(S.worst).length;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function healthVerdict(D: ReportData, S: Summary, campaignNames) {
|
|
194
|
+
var campaigns = D.campaigns || {};
|
|
195
|
+
var off = campaignNames.filter(function (n) {
|
|
196
|
+
return campaignStanding(D, campaigns[n]) === "off";
|
|
197
|
+
});
|
|
198
|
+
var debt = S.rows.filter(function (r) {
|
|
199
|
+
return r.none > 0 && !r.compare;
|
|
200
|
+
});
|
|
201
|
+
var blind = campaignNames.filter(function (n) {
|
|
202
|
+
return campaignStanding(D, campaigns[n]) === "empty";
|
|
203
|
+
});
|
|
204
|
+
if (!campaignNames.length && !S.rows.length) return "No campaigns or scorecards in this snapshot.";
|
|
205
|
+
if (noFacts(S)) return NO_FACTS;
|
|
206
|
+
if (!off.length && !debt.length && !blind.length) return "On track: every active campaign meets its target, and no scorecard has entities at none.";
|
|
207
|
+
var bits: string[] = [];
|
|
208
|
+
var far = furthestTrack(D, S);
|
|
209
|
+
if (far) bits.push("the " + trackTitle(D, far) + " track is furthest from its goal");
|
|
210
|
+
var scored = S.rows.filter(function (r) {
|
|
211
|
+
return !r.compare;
|
|
212
|
+
}).length;
|
|
213
|
+
if (debt.length) bits.push(debt.length + " of " + plural(scored, "scorecard") + " " + (debt.length === 1 ? "has" : "have") + " entities at none");
|
|
214
|
+
if (off.length) bits.push(plural(off.length, "campaign") + " " + (off.length === 1 ? "is" : "are") + " behind target");
|
|
215
|
+
if (blind.length) bits.push(plural(blind.length, "campaign") + " " + (blind.length === 1 ? "has" : "have") + " no single score");
|
|
216
|
+
var atNone = debt.reduce(function (n, r) {
|
|
217
|
+
return n + r.none;
|
|
218
|
+
}, 0);
|
|
219
|
+
// A handful of entities short, with every campaign on target, is not the alarm a broad gap is.
|
|
220
|
+
if (!off.length && !blind.length && atNone <= 2)
|
|
221
|
+
return "Almost there: " + plural(atNone, "entity is", "entities are") + " at none, in " + andList(debt.map(function (r) {
|
|
222
|
+
return title(D, r.name);
|
|
223
|
+
})) + "; every other scored entity holds a medal.";
|
|
224
|
+
// One claim. A sentence that also counts scorecards and campaigns reads as three facts, and the next box carries the count.
|
|
225
|
+
if (far) return "Needs attention: the " + trackTitle(D, far) + " track is furthest from its goal.";
|
|
226
|
+
var lead = "Needs attention: ";
|
|
227
|
+
return lead + (bits.length > 1 ? bits.slice(0, -1).join(", ") + " and " + bits[bits.length - 1] : bits[0]) + ".";
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export type Summary = ReturnType<typeof summarize>;
|
|
231
|
+
export type Row = ReturnType<typeof scorecardRows>[number];
|
package/src/lib/text.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ReportData } from "../types";
|
|
2
|
+
import { el, enc, link } from "./dom";
|
|
3
|
+
import { title } from "./rings";
|
|
4
|
+
|
|
5
|
+
// Manifest prose (a rule's fix) marks code with backticks.
|
|
6
|
+
// Decision ids belong in a standard's links, not in the sentence a reader is reading.
|
|
7
|
+
// A parenthetical made only of citations a reader can't resolve here: decision, question and
|
|
8
|
+
// lesson ids, doc paths and plan sections. The standard's links carry the sources.
|
|
9
|
+
export var CITATION = "(?:D\\d+|D0[0-9A-Z]{20,}|Q\\d+|lessons? L\\d+(?: and L\\d+)?|plan §[\\d.]+|[\\w./-]+\\.md(?:#[\\w-]+| §[\\d.]+)?(?: for [a-z ]+)?|step \\d+)";
|
|
10
|
+
export var DECISION_REFS = new RegExp("\\s*\\(" + CITATION + "(?:[,;] ?" + CITATION + ")*\\)", "g");
|
|
11
|
+
export function prose(s) {
|
|
12
|
+
return String(s || "").replace(DECISION_REFS, "");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Words a standard's own prose uses that a reader outside the project would have to look up.
|
|
16
|
+
export var GLOSSARY = {
|
|
17
|
+
ratchet: "The CI gate that compares each build with the committed results and fails when any score falls.",
|
|
18
|
+
cel: "Common Expression Language: the small expression language a rule's check is written in.",
|
|
19
|
+
fixture: "A sample input in the scorecard's tests, built to pass or to fail a rule, so the rule is shown to decide both ways.",
|
|
20
|
+
harness: "The program that runs something: an agent harness (such as Claude Code, Cursor or Codex) runs an agent, and a benchmark harness runs and times the products it compares.",
|
|
21
|
+
};
|
|
22
|
+
export var GLOSS_RE = /\b(ratchet|CEL|fixtures?|harness)\b/i;
|
|
23
|
+
|
|
24
|
+
export function glossed(text) {
|
|
25
|
+
var m = GLOSS_RE.exec(text);
|
|
26
|
+
if (!m) return [text];
|
|
27
|
+
var word = m[1].toLowerCase();
|
|
28
|
+
var def = GLOSSARY[word] || GLOSSARY[word.replace(/s$/, "")];
|
|
29
|
+
if (!def || (word === "cel" && m[1] !== "CEL")) return [text];
|
|
30
|
+
// Focusable, with the definition in the accessible name, so keyboard and touch readers reach it too.
|
|
31
|
+
var term = el("abbr", { className: "gloss", tabIndex: 0 }, m[1], el("span", { className: "sr", textContent: " (" + def + ")" }));
|
|
32
|
+
term.dataset.tip = def;
|
|
33
|
+
return [text.slice(0, m.index), term, text.slice(m.index + m[1].length)];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function rich(s) {
|
|
37
|
+
var first = true;
|
|
38
|
+
return prose(s)
|
|
39
|
+
.split("`")
|
|
40
|
+
.flatMap(function (part, i) {
|
|
41
|
+
if (i % 2) return [el("code", { textContent: part })];
|
|
42
|
+
if (!first) return [part];
|
|
43
|
+
var out = glossed(part);
|
|
44
|
+
if (out.length > 1) first = false;
|
|
45
|
+
return out;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Prose that names another scorecard by id links to it under its title, so the reader needn't decode ids.
|
|
50
|
+
export function richCards(D: ReportData, s, self) {
|
|
51
|
+
return rich(s).flatMap(function (part) {
|
|
52
|
+
if (typeof part !== "string") return [part];
|
|
53
|
+
return part.split(/([a-z0-9]+(?:-[a-z0-9]+)+)/).map(function (bit, i) {
|
|
54
|
+
return i % 2 && bit !== self && (D.scorecards || {})[bit] ? link("scorecard/" + enc(bit), "", title(D, bit)) : bit;
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|