Skip to content

Commit 075f824

Browse files
committed
Handle zero drift purity narrative
1 parent 90fcdc4 commit 075f824

1 file changed

Lines changed: 27 additions & 8 deletions

File tree

web/app.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4318,9 +4318,27 @@ function buildPurityNarrative(report) {
43184318
: Math.abs(shareDriftPercent) < 0.15
43194319
? 'moderately off'
43204320
: 'significantly misaligned';
4321+
const reportedWorstRuns = Array.isArray(report.worstRuns) ? report.worstRuns : [];
4322+
const worstRuns = reportedWorstRuns.filter((run) => Number.isFinite(run?.driftMinutes));
4323+
const epsilonMinutes = 1;
4324+
const maxRunDrift = worstRuns.reduce((max, run) => {
4325+
const magnitude = Math.abs(Number(run?.driftMinutes) || 0);
4326+
return Math.max(max, magnitude);
4327+
}, 0);
4328+
const isZeroDriftBatch = Math.abs(shareDriftMinutes) <= epsilonMinutes && maxRunDrift <= epsilonMinutes;
43214329

43224330
if (totalRuns <= 0) {
43234331
paragraphs.push('No batch runs have been analyzed yet, so the purity checker does not have a verdict.');
4332+
} else if (isZeroDriftBatch) {
4333+
paragraphs.push(
4334+
`This batch of ${totalRuns} runs is passing the purity check, with ${pureRuns} marked pure and 0 flagged impure. On average, the Share view is in near-perfect agreement with the raw schedules; totals match to within rounding error.`
4335+
);
4336+
const alignedMinutes = avgRaw || avgShare || avgSequence || 0;
4337+
const alignedMinutesText = formatPurityMinutes(alignedMinutes);
4338+
paragraphs.push(
4339+
`Across the batch, raw, Share, and Sequence timelines all sit at roughly ${alignedMinutesText} minutes per run. There is no systematic shortfall or inflation in the aggregated view.`
4340+
);
4341+
paragraphs.push('No individual run stands out: the largest difference between raw and Share totals is effectively zero.');
43244342
} else {
43254343
const statusWord = impureRuns > 0 ? 'failing' : 'passing';
43264344
let driftSentence = 'matching the raw totals almost exactly.';
@@ -4334,7 +4352,7 @@ function buildPurityNarrative(report) {
43344352
);
43354353
}
43364354

4337-
if (avgRaw > 0 || avgShare > 0 || avgSequence > 0) {
4355+
if (!isZeroDriftBatch && (avgRaw > 0 || avgShare > 0 || avgSequence > 0)) {
43384356
const avgRawText = formatPurityMinutes(avgRaw);
43394357
const avgShareText = formatPurityMinutes(avgShare);
43404358
const avgSequenceText = formatPurityMinutes(avgSequence);
@@ -4368,11 +4386,8 @@ function buildPurityNarrative(report) {
43684386
paragraphs.push(`Distortion concentrates in a few activities. ${activitySentences.join(' ')}`);
43694387
}
43704388

4371-
const worstRuns = Array.isArray(report.worstRuns) ? report.worstRuns : [];
4372-
const notableRuns = worstRuns
4373-
.filter((run) => Number.isFinite(run?.driftMinutes))
4374-
.slice(0, 3);
4375-
if (notableRuns.length) {
4389+
const notableRuns = worstRuns.slice(0, 3);
4390+
if (!isZeroDriftBatch && notableRuns.length) {
43764391
const runText = notableRuns
43774392
.map((run) => {
43784393
const label = Number.isFinite(run?.runIndex) && run.runIndex > 0 ? `#${run.runIndex}` : 'one run';
@@ -4462,7 +4477,8 @@ function logBatchPurityReport(summary) {
44624477
.sort((a, b) => Math.abs(b.driftMinutes || 0) - Math.abs(a.driftMinutes || 0))
44634478
.slice(0, 3);
44644479

4465-
const worstRunSummaries = worstRuns.length
4480+
const hasNonZeroWorstRun = worstRuns.some((run) => Math.abs(run.driftMinutes || 0) > 0);
4481+
const worstRunSummaries = worstRuns.length && hasNonZeroWorstRun
44664482
? [
44674483
`Worst drift in runs ${worstRuns
44684484
.map((run) => `#${run.runIndex || 0}`)
@@ -4477,10 +4493,13 @@ function logBatchPurityReport(summary) {
44774493
const avgSequenceText = formatPurityMinutes(avgSequence);
44784494
const shareDriftText = formatPurityMinutes(shareDriftMinutes);
44794495
const shareDriftPercentText = formatPurityPercent(shareDriftPercentValue);
4496+
const averageDriftLine = shareDriftMinutes === 0
4497+
? 'Average drift of share vs raw: 0 minutes (0%).'
4498+
: `Average drift of share vs raw: ${shareDriftText} minutes (${shareDriftPercentText}).`;
44804499
const humanLines = [
44814500
`Purity status: ${pureRuns === totalRuns && totalRuns > 0 ? 'PASSED' : 'FAILED'}.`,
44824501
`Average totals per run (raw/share/sequence): ${avgRawText} / ${avgShareText} / ${avgSequenceText}.`,
4483-
`Average drift of share vs raw: ${shareDriftText} minutes (${shareDriftPercentText}).`,
4502+
averageDriftLine,
44844503
...activitySummaries,
44854504
...worstRunSummaries,
44864505
];

0 commit comments

Comments
 (0)