@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.
@@ -0,0 +1,265 @@
1
+ import type { ReportViews } from "../report-view";
2
+ import type { Summary } from "../lib/summary";
3
+ import type { ReportData, RuleDef } from "../types";
4
+ import { badge, grow } from "../lib/bars";
5
+ import { basisBadge, basisOf } from "../lib/basis";
6
+ import { campaignState, goalBar, goalWords, includeProgress, kpiBar } from "../lib/campaigns";
7
+ import { gapText } from "../lib/compare";
8
+ import { el, enc, link } from "../lib/dom";
9
+ import { kindCount } from "../lib/kinds";
10
+ import { shortId, title } from "../lib/rings";
11
+ import { trackPath } from "../lib/routes";
12
+ import { ruleLink } from "../lib/rules";
13
+ import { blockers, daysLeft } from "../lib/status";
14
+ import { campaignNamesSorted } from "../lib/summary";
15
+ import { rich } from "../lib/text";
16
+ import { fmt, plural } from "../lib/words";
17
+
18
+ // How far the campaign has come since the start the baseline saved; without one, the bar is only where it stands.
19
+ function sinceLine(c) {
20
+ var s = c.sinceStart;
21
+ if (!s) return el("p", { className: "sub", style: "margin:0 0 6px", textContent: "This report was built without a baseline (seikika report --baseline <file>), so the bar shows where the campaign stands today, not how far it has come since its starting point." });
22
+ var keys = [["entitiesShort", "entities short"], ["measure", "total shortfall"]].filter(function (k) {
23
+ return s[k[0]];
24
+ });
25
+ var still = keys.length > 0 && keys.every(function (k) {
26
+ return s[k[0]].from === s[k[0]].now;
27
+ });
28
+ // "0% of the way" on the day the baseline is saved reads as a stalled campaign.
29
+ if (still) return el("p", { className: "sub", style: "margin:0 0 6px" }, el("b", { textContent: "Since the start" + (s.recorded ? ", " + s.recorded : "") + ": " }), "no change yet (" + keys.map(function (k) {
30
+ return k[1] + " " + fmt(s[k[0]].now);
31
+ }).join("; ") + "). Progress appears here once a later build moves these numbers.");
32
+ var parts = keys
33
+ .map(function (k) {
34
+ var x = s[k[0]];
35
+ return k[1] + " " + fmt(x.from) + " → " + fmt(x.now) + (x.percentDone != null ? " (" + x.percentDone + "% of the way)" : "");
36
+ });
37
+ return el("p", { className: "sub", style: "margin:0 0 6px" }, el("b", { textContent: "Since the start" + (s.recorded ? ", " + s.recorded : "") + ": " }), parts.join("; ") || "nothing to compare yet", ".");
38
+ }
39
+
40
+ export const campaignsViews = {
41
+ campaigns(D: ReportData, S: Summary, name) {
42
+ var all = D.campaigns || {};
43
+ var names = campaignNamesSorted(D);
44
+ if (!names.length) names = Object.keys(all).sort();
45
+ if (!names.length) return el("section", {}, el("div", { className: "empty", textContent: "No campaigns in this portal." }));
46
+ var self = this;
47
+ var selected = name && all[name] ? name : names[0];
48
+ var c = all[selected];
49
+ var state = campaignState(c);
50
+ var pct = c.percent == null ? 0 : c.percent;
51
+ var target = c.targetPercent == null ? 100 : c.targetPercent;
52
+ var days = daysLeft(c.end);
53
+ var includes = el("ul", { style: "margin:4px 0 0;padding-left:18px" });
54
+ (c.includes || []).forEach(function (i) {
55
+ includes.append(
56
+ el(
57
+ "li",
58
+ {},
59
+ link("scorecard/" + enc(i.scorecard), "", title(D, i.scorecard)),
60
+ i.atLeast ? el("span", {}, " at ", badge(i.atLeast), " or above") : "",
61
+ i.rules && i.rules.length
62
+ ? el("span", {}, i.rules.length === 1 ? ": passes " : ": passes each of ", ...i.rules.map(function (r, k) {
63
+ return el("span", {}, k ? ", " : "", ruleLink(i.scorecard, r));
64
+ }))
65
+ : "",
66
+ ),
67
+ );
68
+ });
69
+ var bar = el("div", { className: "bar lg" });
70
+ var fillSpan = el("span", { style: "flex-grow:0;flex-basis:0;background:" + (state === "on" ? "var(--pass)" : "var(--muted)") });
71
+ bar.append(fillSpan, el("span", { style: "flex-grow:" + Math.max(0, 100 - pct) + ";background:transparent" }));
72
+ grow([fillSpan], [pct]);
73
+ var marks = el("div", { className: "milestones" });
74
+ (c.milestones || []).forEach(function (m) {
75
+ marks.append(el("span", { className: m.met ? "met" : "", style: "left:" + m.targetPercent + "%", title: "Milestone “" + m.name + "”: " + m.targetPercent + "% of entities meeting the campaign" + (m.met ? ", reached" : ", not reached yet"), textContent: (m.met ? "✓ " : "") + m.name + " " + m.targetPercent + "%" + (m.met ? " reached" : "") }));
76
+ });
77
+ if (target < 100) marks.append(el("span", { style: "left:" + target + "%", textContent: "target " + target + "%" }));
78
+ var size: Record<string, number> = {};
79
+ var gaps = Object.entries(c.entities || {})
80
+ .filter(function (pair) {
81
+ return !pair[1].meeting;
82
+ })
83
+ .sort(function (a, b) {
84
+ return a[0].localeCompare(b[0]);
85
+ });
86
+ var gapList = el("div");
87
+ if (state === "empty") {
88
+ var kinds = (c.includes || []).map(function (i) {
89
+ return ((D.scorecards || {})[i.scorecard] || {}).kind;
90
+ });
91
+ var openRows = includeProgress(D, c).map(function (p) {
92
+ var kind = ((D.scorecards || {})[p.name] || {}).kind;
93
+ var evPct = p.rated ? Math.floor((100 * (p.rated - p.below - p.hollow)) / p.rated) : 0;
94
+ return el(
95
+ "div",
96
+ { className: "gap" },
97
+ link("scorecard/" + enc(p.name), "", p.title),
98
+ el(
99
+ "div",
100
+ { className: "why incl" },
101
+ p.known ? kpiBar(p.pct, p.pct + "% at " + p.goal + " or above" + (p.hollow ? ", " + evPct + "% on an agent's assessment" : "") + "; target " + target + "%", !p.met, p.pct - evPct) : null,
102
+ el("span", { textContent: p.known ? (p.hollow ? evPct + "% at " + p.goal + " or above on an agent's assessment; " + p.pct + "% counting those not assessed yet" : p.pct + "% at " + p.goal + " or above") + " · " + (p.met ? "✓ at target" : fmt(p.below) + " of " + (kind ? kindCount(D, kind, p.rated) : fmt(p.rated)) + " to lift") : "not in this report" }),
103
+ p.hollow ? el("span", { className: "unjudged-n", style: "flex-basis:100%;font-size:13px" }, el("span", { className: "vhatch", ariaHidden: "true", style: "margin:0 5px 0 0" }), fmt(p.hollow) + " pass only because no agent has assessed them yet (hatched)") : null,
104
+ ),
105
+ );
106
+ });
107
+ gapList.append(
108
+ el("p", { className: "next", style: "margin:0 0 10px" }, el("b", { textContent: "Progress, per scorecard. " }), "The scorecards in this campaign rate different things, so each is measured against the target of " + target + "% on its own" + (c.end ? ", by " + c.end + (days != null && days >= 0 ? " (" + plural(days, "day") + " left)" : "") : "") + "."),
109
+ ...openRows,
110
+ el(
111
+ "details",
112
+ { className: "sub", style: "margin-top:8px" },
113
+ el("summary", { style: "padding:3px 0", textContent: "Why each scorecard is measured on its own" }),
114
+ el("p", { textContent: "A campaign's scope is the entities rated by every scorecard it includes, and no entity is rated by all of these" + (kinds.length > 1 && kinds.some(function (k) { return k !== kinds[0]; }) ? " (they rate " + kinds.filter(Boolean).join(" and ") + ")" : "") + ". Include scorecards that rate the same kind to give it one." }),
115
+ ),
116
+ );
117
+ } else if (!gaps.length) {
118
+ gapList.append(el("div", { className: "empty good", textContent: "✓ Every in-scope entity meets the goal." }));
119
+ } else {
120
+ var needCounts: Record<string, number> = {};
121
+ var needFix: Record<string, { sc: string; def: Partial<RuleDef> }> = {};
122
+ gaps.forEach(function (pair) {
123
+ (pair[1].gaps || []).forEach(function (g) {
124
+ const m = /^(.+?):atLeast (\S+) \((\S+)\)$/.exec(g);
125
+ const gsc = m && (D.scorecards || {})[m[1]];
126
+ const score = m && ((D.scores || {})[m[1]] || {})[pair[0]];
127
+ if (gsc && score)
128
+ blockers(gsc, score, m[2]).forEach(function (r) {
129
+ needCounts[r] = (needCounts[r] || 0) + 1;
130
+ needFix[r] = { sc: m[1], def: (gsc.rules || {})[r] || {} };
131
+ });
132
+ });
133
+ });
134
+ var common = Object.entries(needCounts).sort(function (a, b) {
135
+ return b[1] - a[1] || a[0].localeCompare(b[0]);
136
+ })[0];
137
+ if (common)
138
+ gapList.append(
139
+ el(
140
+ "div",
141
+ { className: "next", style: "margin:0 0 10px" },
142
+ el("b", { textContent: "Biggest lever: " }),
143
+ ruleLink(needFix[common[0]].sc, common[0]),
144
+ " ",
145
+ basisBadge(basisOf(needFix[common[0]].def)),
146
+ " blocks " + common[1] + " of " + gaps.length + (gaps.length === 1 ? " entity" : " entities") + ". ",
147
+ ...rich(needFix[common[0]].def.fix || ""),
148
+ needFix[common[0]].def.rationale ? el("span", { className: "why", style: "display:block;margin-top:4px" }, el("b", { textContent: "Why: " }), ...rich(needFix[common[0]].def.rationale)) : null,
149
+ ),
150
+ );
151
+ // How far off each entity is, from its blocking rules' measures and evidence, so the furthest lead.
152
+ var said: Record<string, string> = {};
153
+ gaps.forEach(function (pair) {
154
+ (pair[1].gaps || []).forEach(function (g) {
155
+ const m = /^(.+?):atLeast (\S+) \((\S+)\)$/.exec(g);
156
+ const one = !m && /^(.+?):rule (.+) \((\S+)\)$/.exec(g);
157
+ const on = m || one;
158
+ const gsc = on && (D.scorecards || {})[on[1]];
159
+ const score = on && ((D.scores || {})[on[1]] || {})[pair[0]];
160
+ if (gsc && score)
161
+ (m ? blockers(gsc, score, m[2]) : [(one as RegExpExecArray)[2]]).forEach(function (r) {
162
+ var v = (score.measures || {})[r];
163
+ if (typeof v === "number") size[pair[0]] = (size[pair[0]] || 0) + v;
164
+ var ev = (score.evidence || {})[r];
165
+ if (!said[pair[0]] && ev) said[pair[0]] = String(Array.isArray(ev) ? ev[0] : ev).split("\n")[0];
166
+ });
167
+ });
168
+ });
169
+ if (Object.keys(size).length)
170
+ gaps.sort(function (a, b) {
171
+ return (size[b[0]] || 0) - (size[a[0]] || 0) || a[0].localeCompare(b[0]);
172
+ });
173
+ gaps.forEach(function (pair) {
174
+ var bases = {};
175
+ (pair[1].gaps || []).forEach(function (g) {
176
+ const m = /^(.+?):atLeast (\S+) \((\S+)\)$/.exec(g);
177
+ const gsc = m && (D.scorecards || {})[m[1]];
178
+ const score = m && ((D.scores || {})[m[1]] || {})[pair[0]];
179
+ if (gsc && score)
180
+ blockers(gsc, score, m[2]).forEach(function (r) {
181
+ bases[basisOf((gsc.rules || {})[r] || {})] = true;
182
+ });
183
+ });
184
+ gapList.append(
185
+ el(
186
+ "div",
187
+ { className: "gap" },
188
+ el("div", {}, link("entity/" + enc(pair[0]), "", shortId(pair[0])), el("div", { className: "sub", style: "font-size:12px", textContent: pair[0] })),
189
+ el(
190
+ "div",
191
+ { className: "why" },
192
+ ...Object.keys(bases)
193
+ .sort()
194
+ .map(function (b) {
195
+ return basisBadge(b, true);
196
+ }),
197
+ Object.keys(bases).length ? " " : "",
198
+ (pair[1].gaps || []).map(function (g) { return gapText(D, g, pair[0]); }).join("; "),
199
+ said[pair[0]] ? el("div", { className: "sub", style: "font-size:12px", textContent: "Found: " + said[pair[0]] }) : null,
200
+ ),
201
+ ),
202
+ );
203
+ });
204
+ }
205
+ var track = c.track && D.tracks && D.tracks[c.track] ? D.tracks[c.track].title || c.track : c.track;
206
+ var picker = el(
207
+ "select",
208
+ {
209
+ ariaLabel: "Campaign",
210
+ onchange: function () {
211
+ location.hash = "campaign/" + enc(picker.value);
212
+ },
213
+ },
214
+ ...names.map(function (n) {
215
+ var cn = all[n];
216
+ return el("option", { value: n, selected: n === selected, textContent: (cn.title || n) + " (" + (campaignState(cn) === "empty" ? goalWords(includeProgress(D, cn)) : (cn.percent || 0) + "%") + ")" });
217
+ }),
218
+ );
219
+ return el(
220
+ "div",
221
+ { className: "split" },
222
+ el(
223
+ "section",
224
+ {},
225
+ el("div", { className: "head" }, el("h2", { textContent: "Campaigns" })),
226
+ el("p", { className: "sub", style: "margin-top:0", textContent: "Behind target first" }),
227
+ el(
228
+ "div",
229
+ { className: "cards", style: "grid-template-columns:1fr" },
230
+ ...names.map(function (n) {
231
+ return self.campaignCard(D, n, n === selected);
232
+ }),
233
+ ),
234
+ ),
235
+ el(
236
+ "section",
237
+ {},
238
+ el("label", { className: "picker" }, el("span", { className: "sub", textContent: "Campaign" }), picker),
239
+ el(
240
+ "div",
241
+ { className: "ehead" },
242
+ el("div", {}, el("h2", { textContent: c.title || selected }), el("div", { className: "sub" }, c.status || "", track ? el("span", {}, " · track ", link(trackPath(D, c.track), "", track)) : null, c.owner ? " · owned by " + c.owner.replace(/^group:/, "") : null)),
243
+ goalBar(state, pct, target, true, includeProgress(D, c)),
244
+ ),
245
+ c.description ? el("p", { className: "lede" }, ...rich(c.description)) : null,
246
+ state === "empty"
247
+ ? null
248
+ : el(
249
+ "p",
250
+ { style: "margin:8px 0 6px" },
251
+ el("b", { textContent: (c.meeting || 0) + " of " + (c.inScope || 0) }),
252
+ " entities meet the goal · target " + target + "%" + (c.end ? " by " + c.end : "") + (days != null && days >= 0 ? " (" + plural(days, "day") + " left)" : "") + ". The bar turns green once it reaches the target.",
253
+ ),
254
+ state === "empty" ? null : sinceLine(c),
255
+ // The header already draws the percentage; a second bar earns its place only to carry milestones.
256
+ state === "empty" || !marks.childElementCount ? null : bar,
257
+ state === "empty" || !marks.childElementCount ? null : marks,
258
+ el("h3", { textContent: "Goal" }),
259
+ includes,
260
+ el("h3", { textContent: state === "empty" ? "Progress" : "Not meeting yet" + (gaps.length ? " (" + gaps.length + ")" : "") + (Object.keys(size).length ? ", furthest first" : "") }),
261
+ gapList,
262
+ ),
263
+ );
264
+ },
265
+ } satisfies ThisType<ReportViews>;