Count adjustments as Forecast rather than their own banner

pf_bucket mirrored pf_segment for scale/recode/clone rows, so adjustments
showed as '(adjustment)' -- a banner of their own, sitting outside the
forecast they are adjustments to. Grouping by pf_bucket therefore split the
forecast in two.

An adjustment is always part of the forecast: exclude_iters keeps operations
off the reference segments, so there is no adjustment that is not. It falls
back to 'Forecast' now, and still yields to an explicit bucket on its own
log entry.

pf_segment keeps '(adjustment)', which is right there -- it answers which
segment a row came from, and an adjustment came from none.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Paul Trowbridge 2026-09-17 01:03:34 -04:00
parent 0049a391c0
commit 2689e95b2c
2 changed files with 10 additions and 7 deletions

View File

@ -154,7 +154,7 @@ SELECT
,COALESCE(NULLIF(l.bucket, ''), ,COALESCE(NULLIF(l.bucket, ''),
CASE WHEN l.operation IN ('baseline','reference') CASE WHEN l.operation IN ('baseline','reference')
THEN COALESCE(NULLIF(l.tag, ''), NULLIF(l.note, ''), '(unlabeled load)') THEN COALESCE(NULLIF(l.tag, ''), NULLIF(l.note, ''), '(unlabeled load)')
ELSE '(adjustment)' END) AS pf_bucket ELSE 'Forecast' END) AS pf_bucket
,CASE WHEN l.operation IN ('baseline','reference') ,CASE WHEN l.operation IN ('baseline','reference')
THEN NULL THEN NULL
ELSE COALESCE(NULLIF(l.tag, ''), NULLIF(l.note, '')) END AS pf_note ELSE COALESCE(NULLIF(l.tag, ''), NULLIF(l.note, '')) END AS pf_note

View File

@ -319,12 +319,15 @@ module.exports = function(pool) {
,CASE WHEN l.operation IN ('baseline','reference') ,CASE WHEN l.operation IN ('baseline','reference')
THEN COALESCE(NULLIF(l.tag, ''), NULLIF(l.note, ''), '(unlabeled load)') THEN COALESCE(NULLIF(l.tag, ''), NULLIF(l.note, ''), '(unlabeled load)')
ELSE '(adjustment)' END AS pf_segment ELSE '(adjustment)' END AS pf_segment
-- what the segment counts towards, falling back to the segment -- What the row counts towards. A load falls back to its own
-- itself so an unlabelled one still reads as something -- name until it is labelled; an adjustment falls back to
-- 'Forecast', because that is what an adjustment is -- exclude_iters
-- keeps operations off the reference segments, so there is no
-- adjustment that is not part of the forecast.
,COALESCE(NULLIF(l.bucket, ''), ,COALESCE(NULLIF(l.bucket, ''),
CASE WHEN l.operation IN ('baseline','reference') CASE WHEN l.operation IN ('baseline','reference')
THEN COALESCE(NULLIF(l.tag, ''), NULLIF(l.note, ''), '(unlabeled load)') THEN COALESCE(NULLIF(l.tag, ''), NULLIF(l.note, ''), '(unlabeled load)')
ELSE '(adjustment)' END) AS pf_bucket ELSE 'Forecast' END) AS pf_bucket
,CASE WHEN l.operation IN ('baseline','reference') ,CASE WHEN l.operation IN ('baseline','reference')
THEN NULL THEN NULL
ELSE COALESCE(NULLIF(l.tag, ''), NULLIF(l.note, '')) END AS pf_note ELSE COALESCE(NULLIF(l.tag, ''), NULLIF(l.note, '')) END AS pf_note
@ -643,7 +646,7 @@ module.exports = function(pool) {
await client.query('COMMIT'); await client.query('COMMIT');
committed = true; committed = true;
const opLabel = (req.body.tag || '').trim() || note || null; const opLabel = (req.body.tag || '').trim() || note || null;
const rows = allRows.map(r => ({ ...r, pf_segment: '(adjustment)', pf_bucket: '(adjustment)', pf_note: opLabel, pf_op: 'scale' })); const rows = allRows.map(r => ({ ...r, pf_segment: '(adjustment)', pf_bucket: 'Forecast', pf_note: opLabel, pf_op: 'scale' }));
res.json({ res.json({
rows, rows,
rows_affected: rows.length, rows_affected: rows.length,
@ -703,7 +706,7 @@ module.exports = function(pool) {
await client.query('COMMIT'); await client.query('COMMIT');
committed = true; committed = true;
const opLabel = (req.body.tag || '').trim() || note || null; const opLabel = (req.body.tag || '').trim() || note || null;
const rows = allRows.map(r => ({ ...r, pf_segment: '(adjustment)', pf_bucket: '(adjustment)', pf_note: opLabel, pf_op: 'recode' })); const rows = allRows.map(r => ({ ...r, pf_segment: '(adjustment)', pf_bucket: 'Forecast', pf_note: opLabel, pf_op: 'recode' }));
res.json({ rows, rows_affected: rows.length, slices_applied: units.length }); res.json({ rows, rows_affected: rows.length, slices_applied: units.length });
} finally { } finally {
if (!committed) try { await client.query('ROLLBACK'); } catch {} if (!committed) try { await client.query('ROLLBACK'); } catch {}
@ -760,7 +763,7 @@ module.exports = function(pool) {
await client.query('COMMIT'); await client.query('COMMIT');
committed = true; committed = true;
const opLabel = (req.body.tag || '').trim() || note || null; const opLabel = (req.body.tag || '').trim() || note || null;
const rows = allRows.map(r => ({ ...r, pf_segment: '(adjustment)', pf_bucket: '(adjustment)', pf_note: opLabel, pf_op: 'clone' })); const rows = allRows.map(r => ({ ...r, pf_segment: '(adjustment)', pf_bucket: 'Forecast', pf_note: opLabel, pf_op: 'clone' }));
res.json({ rows, rows_affected: rows.length, slices_applied: units.length }); res.json({ rows, rows_affected: rows.length, slices_applied: units.length });
} finally { } finally {
if (!committed) try { await client.query('ROLLBACK'); } catch {} if (!committed) try { await client.query('ROLLBACK'); } catch {}