work on a new forecast approach

This commit is contained in:
Paul Trowbridge 2021-07-09 00:54:44 -04:00
parent f8a96d6df2
commit f3f7b7a177
3 changed files with 1024 additions and 5 deletions

1012
build/build_baseline.sql Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
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;
--will not match actuals exactly due to short-ships
TRUNCATE TABLE rlarp.osmf_dev; TRUNCATE TABLE rlarp.osmf_dev;
DROP TABLE IF EXISTS tdr; DROP TABLE IF EXISTS tdr;
@ -8,12 +9,12 @@ DROP TABLE IF EXISTS tdr;
CREATE TEMP TABLE tdr AS ( CREATE TEMP TABLE tdr AS (
SELECT SELECT
-----------actuals--------------------------------------------------- -----------actuals---------------------------------------------------
DATERANGE('2020-06-01','2021-07-01','[)') adrange DATERANGE('2020-06-01','2021-07-07','[]') adrange
-----------actuals to target for incremnt---------------------------- -----------actuals to target for incremnt----------------------------
,DATERANGE('2021-08-01','2022-06-01','[)') arepl ,DATERANGE('2022-06-01','2022-06-01','[)') arepl
,'0 year'::interval AS aincr ,'0 year'::interval AS aincr
-----------budget to target for increment---------------------------- -----------budget to target for increment----------------------------
,DATERANGE('2021-07-01','2022-06-01','[)') prepl ,DATERANGE('2021-07-08','2022-06-01','[)') prepl
,'0 year'::interval AS pincr ,'0 year'::interval AS pincr
-----------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
@ -173,8 +174,11 @@ gld AS (
--...or anything that shipped in that period --...or anything that shipped in that period
OR (o.sdate <@ (SELECT adrange FROM tdr) AND sseas IS NOT NULL) OR (o.sdate <@ (SELECT adrange FROM tdr) AND sseas IS NOT NULL)
) )
---exclude R&A's
AND fs_line = '41010' AND fs_line = '41010'
---exclude canceled orders
AND calc_status <> 'CANCELED' AND calc_status <> 'CANCELED'
---exclude short ships
AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER') AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER')
---exclude integrated quotes---- ---exclude integrated quotes----
AND version = 'ACTUALS' AND version = 'ACTUALS'

View File

@ -3,9 +3,12 @@ SELECT
to_char(CASE WHEN extract(month FROM o.odate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.odate),'FM00')||' - '||to_char(o.odate,'TMMon') order_month, to_char(CASE WHEN extract(month FROM o.odate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.odate),'FM00')||' - '||to_char(o.odate,'TMMon') order_month,
version, version,
iter, iter,
sum(fb_val_loc) value_loc sum(fb_val_loc * r_rate) value_loc
FROM FROM
rlarp.osmf_dev o rlarp.osmf_dev o
WHERE
fs_line = '41010'
and calc_status <> 'CANCELED'
GROUP BY GROUP BY
oseas, oseas,
to_char(CASE WHEN extract(month FROM o.odate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.odate),'FM00')||' - '||to_char(o.odate,'TMMon'), to_char(CASE WHEN extract(month FROM o.odate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.odate),'FM00')||' - '||to_char(o.odate,'TMMon'),
@ -28,7 +31,7 @@ WHERE
--oseas = 2020 --oseas = 2020
fs_line = '41010' fs_line = '41010'
--AND odate < '2020-04-01' --AND odate < '2020-04-01'
AND CALC_STATUS <> 'CANCELED' --AND CALC_STATUS <> 'CANCELED'
AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER') AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER')
GROUP BY GROUP BY
version, version,