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; BEGIN;
--\timing --\timing
--CREATE TABLE IF NOT EXISTS rlarp.osmf_stage AS (SELECT * FROM rlarp.osmf_dev) WITH no data; --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-------------------------- -----------baseline selection for increment--------------------------
,DATERANGE('2021-07-08','2021-07-08','[)') selection ,DATERANGE('2021-07-08','2021-07-08','[)') selection
-----------selection increment size---------------------------------- -----------selection increment size----------------------------------
--need to specify the overlap, or derive it?
,'0 year'::interval AS incr ,'0 year'::interval AS incr
-----------iterations to merge with---------------------------------- -----------iterations to merge with----------------------------------
,(SELECT jsonb_agg(x.v) FROM (VALUES('copy'),('actuals'),('actuals_plug')) AS x(v)) iter ,(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 --select * from tdr
@ -641,7 +652,7 @@ SELECT
,rg.ssyr rseas --incremented ,rg.ssyr rseas --incremented
,(o.sdate + (SELECT incr FROM tdr))::date sdate --incremented ,(o.sdate + (SELECT incr FROM tdr))::date sdate --incremented
,sg.ssyr sseas --incremented ,sg.ssyr sseas --incremented
,'b22' "version" ,'1+11' "version"
,'copy' iter ,'copy' iter
FROM FROM
baseline o baseline o
@ -658,12 +669,12 @@ WHERE
(o.sdate + (SELECT incr FROM tdr))::date <@ (SELECT selection FROM tdr) (o.sdate + (SELECT incr FROM tdr))::date <@ (SELECT selection FROM tdr)
) )
--SELECT count(*) FROM baseline --SELECT count(*) FROM baseline
,stage AS ( ,incoming AS (
SELECT * FROM incr SELECT * FROM incr
UNION ALL UNION ALL
SELECT * FROM baseline SELECT * FROM baseline
) )
,remove AS ( ,negative AS (
SELECT SELECT
-----------documents------------- -----------documents-------------
null::int "ddord#" null::int "ddord#"
@ -813,12 +824,12 @@ SELECT * FROM baseline
,o.version ,o.version
,o.iter ,o.iter
) )
,stack AS ( ,diff AS (
SELECT * FROM stage SELECT * FROM incoming
UNION ALL UNION ALL
SELECT * FROM remove SELECT * FROM negative
) )
,merge_diff AS ( ,collapse_diff AS (
SELECT SELECT
-----------documents------------- -----------documents-------------
null::int "ddord#" null::int "ddord#"
@ -929,7 +940,7 @@ SELECT * FROM baseline
,'actuals' AS version ,'actuals' AS version
,'copy' iter ,'copy' iter
FROM FROM
stack o diff o
WHERE WHERE
true true
--collect all the rows in the base period and --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_val_loc),2) <> 0
--OR round(sum(o.fb_cst_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 UPDATE

View File

@ -1,5 +1,6 @@
#!/bin/bash #!/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_itemm.sql;
$PG -f ./snap_cost_current.sql; $PG -f ./snap_cost_current.sql;
$PG -f ./snap_customer.sql; $PG -f ./snap_customer.sql;