From 7f8ed574c5b4bcee6865d120c48054fc58b27d50 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Fri, 9 Jul 2021 16:14:29 -0400 Subject: [PATCH] work on 1+11 --- build/build_baseline.sql | 31 +++++++++++++++++++++---------- build/rebuild_forecast.sh | 3 ++- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/build/build_baseline.sql b/build/build_baseline.sql index c93c252..71a7d84 100644 --- a/build/build_baseline.sql +++ b/build/build_baseline.sql @@ -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 diff --git a/build/rebuild_forecast.sh b/build/rebuild_forecast.sh index 1164536..db73cb4 100644 --- a/build/rebuild_forecast.sh +++ b/build/rebuild_forecast.sh @@ -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;