work on 1+11

This commit is contained in:
Paul Trowbridge 2021-07-09 16:14:29 -04:00
parent f3f7b7a177
commit 7f8ed574c5
2 changed files with 23 additions and 11 deletions

View File

@ -1,3 +1,13 @@
/*
baseline - selections from actual, plan, and forecast
incr - increment selection from baseline
incoming - baseline & incr stacked
negative - apply negative values to existing baseline to create a diff
diff - stack incoming and the negative
collapse_diff - group the diff to create single diff rows per item
*/
BEGIN;
--\timing
--CREATE TABLE IF NOT EXISTS rlarp.osmf_stage AS (SELECT * FROM rlarp.osmf_dev) WITH no data;
@ -17,10 +27,11 @@ CREATE TEMP TABLE tdr AS (
-----------baseline selection for increment--------------------------
,DATERANGE('2021-07-08','2021-07-08','[)') selection
-----------selection increment size----------------------------------
--need to specify the overlap, or derive it?
,'0 year'::interval AS incr
-----------iterations to merge with----------------------------------
,(SELECT jsonb_agg(x.v) FROM (VALUES('copy'),('actuals'),('actuals_plug')) AS x(v)) iter
-----------existing baseline overlap---------------------------------
,DATERANGE('2000-06-01','2021-07-08') overlap
);
--select * from tdr
@ -641,7 +652,7 @@ SELECT
,rg.ssyr rseas --incremented
,(o.sdate + (SELECT incr FROM tdr))::date sdate --incremented
,sg.ssyr sseas --incremented
,'b22' "version"
,'1+11' "version"
,'copy' iter
FROM
baseline o
@ -658,12 +669,12 @@ WHERE
(o.sdate + (SELECT incr FROM tdr))::date <@ (SELECT selection FROM tdr)
)
--SELECT count(*) FROM baseline
,stage AS (
,incoming AS (
SELECT * FROM incr
UNION ALL
SELECT * FROM baseline
)
,remove AS (
,negative AS (
SELECT
-----------documents-------------
null::int "ddord#"
@ -813,12 +824,12 @@ SELECT * FROM baseline
,o.version
,o.iter
)
,stack AS (
SELECT * FROM stage
,diff AS (
SELECT * FROM incoming
UNION ALL
SELECT * FROM remove
SELECT * FROM negative
)
,merge_diff AS (
,collapse_diff AS (
SELECT
-----------documents-------------
null::int "ddord#"
@ -929,7 +940,7 @@ SELECT * FROM baseline
,'actuals' AS version
,'copy' iter
FROM
stack o
diff o
WHERE
true
--collect all the rows in the base period and
@ -969,7 +980,7 @@ SELECT * FROM baseline
-- OR round(sum(o.fb_val_loc),2) <> 0
--OR round(sum(o.fb_cst_loc),2) <> 0
)
INSERT INTO rlarp.osmf_dev SELECT * FROM merge_diff;
INSERT INTO rlarp.osmf_dev SELECT * FROM collapse_diff;
UPDATE

View File

@ -1,5 +1,6 @@
#!/bin/bash
$PG -f ./build_stage.sql;
#$PG -f ./build_stage.sql;
$PG -f ./build_baseline.sql;
$PG -f ./snap_itemm.sql;
$PG -f ./snap_cost_current.sql;
$PG -f ./snap_customer.sql;