diff --git a/generate_sql/baseline_old.sql b/generate_sql/baseline_old.sql deleted file mode 100644 index 339316d..0000000 --- a/generate_sql/baseline_old.sql +++ /dev/null @@ -1,84 +0,0 @@ ---a baseline period will have to be identified -WITH -baseline AS ( - -----------------------copy YTD sales--------------------------------------------------------------------- - SELECT - [nonversion] - ,'baseline' "version" - ,'actuals' iter - FROM - rlarp.osm_dev o - WHERE - ( - --base period orders booked.... - [order_field_name] BETWEEN [target_odate_from] AND [target_odate_to] - --...or any open orders currently booked before cutoff.... - OR ([status_flag] IN ([status_list]) and [target_date] <= [target_date_from]) - --...or anything that shipped in that period - OR ([target_sdate] BETWEEN [target_sdate_from] AND [target_sdate_to]) - ) - --be sure to pre-exclude unwanted items, like canceled orders, non-gross sales, and short-ships - UNION ALL - ---------option 1: fill in the rest of the year, with the prior years sales-sales---------------------------- - SELECT - [nonversion] - ,'baseline' "version" - ,'plug' iter - FROM - rlarp.osm_dev o - LEFT OUTER JOIN gld ON - gld.fspr = o.fspr - LEFT OUTER JOIN gld ss ON - greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' BETWEEN ss.sdat AND ss.edat - WHERE - [target_odate] BETWEEN [target_odate_plug_from] AND [target_odate_plug_to] - --be sure to pre-exclude unwanted items, like canceled orders, non-gross sales, and short-ships - UNION ALL - --------option 2: fill in the remainder of the current year with current forecase----------------------------- - SELECT - [nonversion] - ,'baseline' "version" - ,'plug' iter - FROM - rlarp.osmp_dev o - LEFT OUTER JOIN gld ON - gld.fspr = o.fspr - LEFT OUTER JOIN gld ss ON - greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat - WHERE - [target_odate] BETWEEN [target_odate_plug_from] AND [target_odate_plug_to] - AND false -) --------------------copy the baseline just generated and increment all the dates by one year------------------------------------ -,incr AS ( -SELECT - [nondate_columns] - ,o.dcodat + interval '1 year' --incremented - ,o.ddqdat + interval '1 year' --incremented - ,o.dhidat + interval '1 year' --incremented - ,o.odate + interval '1 year' --incremented - ,o.oseas + 1 --incremented - ,o.rdate + interval '1 year' --incremented - ,o.rseas + 1 --incremented - ,o.sdate + interval '1 year' --incremented - ,o.sseas + 1 --incremented - ,'baseline' "version" - ,'copy' iter -FROM - baseline o - LEFT OUTER JOIN gld ON - o.sdate + interval '1 year' BETWEEN gld.sdat and gld.edat -WHERE - o.odate + interval '1 year' >= '2020-06-01' -) --------------insert the baseline actuals + x months of forecast in addtion to 12 months of forecase---------------------------- -INSERT INTO rlarp.osmf_dev -SELECT * FROM incr -UNION ALL -SELECT * FROM baseline; - ----identify short ships: causes disconnect with actual sales------------------------------------------------------------------- ---UPDATE rlarp.osmfs SET iter = 'short ship' WHERE calc_status = 'CLOSED' AND flag = 'REMAINDER'; - ----identify goofy ship dates: causes disconnect with sales when splicing in a forecast that has this problem------------------- ---UPDATE rlarp.osmfs SET iter = 'bad date' WHERE adj_shipdate < adj_orderdate; diff --git a/generate_sql/col_interval.sql b/generate_sql/col_interval.sql deleted file mode 100644 index e9294f6..0000000 --- a/generate_sql/col_interval.sql +++ /dev/null @@ -1,27 +0,0 @@ -DO -$$ -DECLARE - clist text; - -BEGIN --------------------------------build a column list---------------------------------------- -SELECT - string_agg( - format('%I',cname) || CASE WHEN func IN ('odate','sdate') AND dtype = 'date' THEN ' + interval ''1 year''' ELSE '' END,E'\n,' ORDER BY opos ASC) -INTO - clist -FROM - fc.target_meta -WHERE - func NOT IN ('version'); - -RAISE NOTICE 'build list: %',clist; - -CREATE TEMP TABLE sql(t text); - -INSERT INTO sql SELECT clist; - -END -$$; - -select * from sql; diff --git a/readme.md b/readme.md index 1e6bf21..315daba 100644 --- a/readme.md +++ b/readme.md @@ -34,8 +34,9 @@ TO-DO: running problem list ---------------------------------------------------------------------------------------------------------------------------------------------------- * baseline route - * problem: how will the incremented order season get updated, adding an interval won't work - - [ ] a table fc.odate, has been built, but it is incomplete, a setup function filling in these date-keyed tables could be setup - - [ ] if a table is date-keyed, fc.perd could be targeted to fill in the gaps - * problem: the target sales data has to map have concepts like order_date, and the application needs to know which col is order date - - [x] add column called application hook + - [ ] problem: how will the incremented order season get updated, adding an interval won't work + * a table fc.odate, has been built, but it is incomplete, a setup function filling in these date-keyed tables could be setup + * if a table is date-keyed, fc.perd could be targeted to fill in the gaps by mapping the associated column names + - [ ] problem: the target sales data has to map have concepts like order_date, and the application needs to know which col is order date + * add column called application hook + - [ ] there is not currently any initial grouping to limit excess data from all the document# scenarios