setup from dcard to test with

This commit is contained in:
Paul Trowbridge 2022-04-09 02:29:51 -04:00
parent 342e0824c5
commit 959d858b10
7 changed files with 164 additions and 326 deletions

View File

@ -0,0 +1,86 @@
DELETE FROM tpsv.dcard WHERE app_version = 'app_forecast_name';
WITH
baseline AS (
SELECT
o.id
,o.logid
,o."Trans. Date"
,o."Post Date"
,o."Description"
,o."Amount"
,o."Category"
,o."Party"
,o."Reason"
,'app_forecast_name' "version"
,'actuals' iter
,null::bigint app_logid
FROM
tpsv.dcard o
WHERE
(
--base period orders booked....
"Trans. Date" BETWEEN 'app_baseline_from_date'::date AND 'app_baseline_to_date'::date
--...or any open orders currently booked before cutoff....
OR ("Category" IN (app_openstatus_code) and "Trans. Date" <= 'app_openorder_cutoff'::date)
--...or anything that shipped in that period
OR ("Post Date" BETWEEN 'app_baseline_from_date'::date AND 'app_baseline_to_date'::date)
)
--be sure to pre-exclude unwanted items, like canceled orders, non-gross sales, and short-ships
UNION ALL
SELECT
o.id
,o.logid
,o."Trans. Date" + interval '1 year' AS "Trans. Date"
,o."Post Date" + interval '1 year' AS "Post Date"
,o."Description"
,o."Amount"
,o."Category"
,o."Party"
,o."Reason"
,'app_forecast_name' "version"
,'plug' iter
,null::bigint app_logid
FROM
tpsv.dcard o
LEFT OUTER JOIN fc.perd tdate ON
(o."Trans. Date" + interval '1 year' )::date <@ tdate.drange
LEFT OUTER JOIN fc.perd pdate ON
(o."Post Date" + interval '1 year' )::date <@ pdate.drange
WHERE
"Trans. Date" BETWEEN 'app_plug_fromdate'::date AND 'app_plug_todate'::date
--be sure to pre-exclude unwanted items, like canceled orders, non-gross sales, and short-ships
)
,incr AS (
SELECT
o.id
,o.logid
,o."Trans. Date" + interval '1 year' AS "Trans. Date"
,o."Post Date" + interval '1 year' AS "Post Date"
,o."Description"
,o."Amount"
,o."Category"
,o."Party"
,o."Reason"
,'app_forecast_name' "version"
,'baseline' iter
,null::bigint app_logid
FROM
baseline o
LEFT OUTER JOIN fc.perd tdate ON
(o."Trans. Date" + interval '1 year' )::date <@ tdate.drange
LEFT OUTER JOIN fc.perd pdate ON
(o."Post Date" + interval '1 year' )::date <@ pdate.drange
)
,ins AS (
INSERT INTO
tpsv.dcard
SELECT
*
FROM
incr i
WHERE
i."Trans. Date" >= 'app_first_forecast_date'::date
OR i."Post Date" >= 'app_first_forecast_date'::date
RETURNING *
)
SELECT COUNT(*) num_rows FROM ins

View File

@ -1,4 +1,4 @@
# execure the sql for baseline which builds the sql and inserts into a table # execure the sql for baseline which builds the sql and inserts into a table
$PGD -f routes/baseline/gen_baseline.sql $PG -f routes/baseline/gen_baseline.sql
# pull the sql out of the table and write it to route directory # pull the sql out of the table and write it to route directory
$PGD -c "SELECT t FROM fc.sql WHERE cmd = 'baseline'" -t -A -o routes/baseline/baseline.sql $PG -c "SELECT t FROM fc.sql WHERE cmd = 'baseline'" -t -A -o routes/baseline/baseline.sql

View File

@ -1 +1 @@
curl -H "Content-Type: application/json" -X GET -d@req.json https://localhost:8082/scale --insecure > scale_temp.sql curl -H "Content-Type: application/json" -X GET -d@req_dcard.json https://localhost:8082/scale --insecure > scale_temp.sql

View File

@ -1,4 +1,4 @@
# execure the sql for scale which builds the sql and inserts into a table # execure the sql for scale which builds the sql and inserts into a table
$PG -f gen_scale.sql $PG -f ./routes/scale/gen_scale.sql
# pull the sql out of the table and write it to route directory # pull the sql out of the table and write it to route directory
$PG -c "SELECT t FROM fc.sql WHERE cmd = 'scale'" -t -A -o scale.sql $PG -c "SELECT t FROM fc.sql WHERE cmd = 'scale'" -t -A -o ./routes/scale/scale.sql

View File

@ -0,0 +1,17 @@
{
"app_scenario": {
"\"Description\"": "TARGET STOW OH",
"app_iter": [
"baseline"
]
},
"stamp": "2020-02-19 17:03:38",
"user": "Trowbridge, Paul",
"source": "adj",
"message": "test json",
"tag": "standard price",
"version": "dev",
"type": "scale_vp",
"app_vincr": 0,
"app_pincr": 2000
}

View File

@ -2,241 +2,67 @@ WITH
req AS (SELECT $$app_req$$::jsonb j) req AS (SELECT $$app_req$$::jsonb j)
,target AS ( ,target AS (
SELECT SELECT
(req.j->>'vincr')::numeric vincr --volume (req.j->>'app_vincr')::numeric vincr --volume
,(req.j->>'pincr')::numeric pincr --price ,(req.j->>'app_pincr')::numeric pincr --price
FROM FROM
req req
) )
-----this block is supposed to test for new products that might not be in baseline etc------- -----this block is supposed to test for new products that might not be in baseline etc-------
,test AS ( ,test AS (
SELECT SELECT
sum(fb_qty) FILTER (WHERE version <> 'ACTUALS') total sum(app_units) FILTER (WHERE version <> 'ACTUALS') total
,sum(fb_qty) FILTER (WHERE iter = 'baseline') base ,sum(app_units) FILTER (WHERE iter = 'baseline') base
FROM FROM
fc.live tpsv.dcard o
WHERE WHERE
app_where app_where
) )
,basemix AS ( ,basemix AS (
SELECT SELECT
o."ddord#" o.id
,o."dditm#" ,o.logid
,o."fgbol#" ,o."Trans. Date"
,o."fgent#" ,o."Post Date"
,o."diinv#" ,o."Description"
,o."dilin#" ,o."Amount"
,o.quoten ,o."Category"
,o.quotel ,o."Party"
,o.dcodat ,o."Reason"
,o.ddqdat ,o.app_units
,o.dcmdat
,o.fesdat
,o.dhidat
,o.fesind
,o.dhpost
,o.fspr
,o.ddqtoi
,o.ddqtsi
,o.fgqshp
,o.diqtsh
,o.diext
,o.ditdis
,o.discj
,o.dhincr
,o.plnt
,o.promo
,o.return_reas
,o.terms
,o.custpo
,o.remit_to
,o.bill_class
,o.bill_cust
,o.bill_rep
,o.bill_terr
,o.ship_class
,o.ship_cust
,o.ship_rep
,o.ship_terr
,o.dsm
,o.account
,o.shipgrp
,o.geo
,o.chan
,o.chansub
,o.orig_ctry
,o.orig_prov
,o.orig_post
,o.bill_ctry
,o.bill_prov
,o.bill_post
,o.dest_ctry
,o.dest_prov
,o.dest_post
,o.part
,o.styc
,o.colc
,o.colgrp
,o.coltier
,o.colstat
,o.sizc
,o.pckg
,o.kit
,o.brnd
,o.majg
,o.ming
,o.majs
,o.mins
,o.gldco
,o.gldc
,o.glec
,o.harm
,o.clss
,o.brand
,o.assc
,o.ddunit
,o.unti
,o.lbs
,o.plt
,o.plcd
,o.fs_line
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,o.fb_qty
,o.fb_val_loc
,o.fb_val_loc_dis
,o.fb_val_loc_qt
,o.fb_val_loc_pl
,o.fb_val_loc_tar
,o.fb_cst_loc
,o.fb_cst_loc_cur
,o.fb_cst_loc_fut
,o.calc_status
,o.flag
,o.odate
,o.oseas
,o.rdate
,o.rseas
,o.sdate
,o.sseas
FROM FROM
fc.live o tpsv.dcard o
WHERE WHERE
app_where app_where
), ),
vscale AS ( vscale AS (
SELECT SELECT
(SELECT vincr FROM target) AS target_increment (SELECT vincr FROM target) AS target_increment
,sum(fb_qty) AS units ,sum(app_units) AS units
,(SELECT vincr FROM target)/sum(fb_qty) AS factor ,CASE WHEN sum(app_units) = 0 THEN 0 ELSE (SELECT vincr FROM target)/sum(app_units) END AS factor
FROM FROM
basemix basemix
) )
,ilog AS (
INSERT INTO
fc.log (doc)
SELECT
req.j
FROM
req
)
,volume AS ( ,volume AS (
SELECT SELECT
o."ddord#" o.id
,o."dditm#" ,o.logid
,o."fgbol#" ,o."Trans. Date"
,o."fgent#" ,o."Post Date"
,o."diinv#" ,o."Description"
,o."dilin#" ,o."Amount" * vscale.factor AS "Amount"
,o.quoten ,o."Category"
,o.quotel ,o."Party"
,o.dcodat ,o."Reason"
,o.ddqdat ,o.app_units * vscale.factor AS app_units
,o.dcmdat ,'app_forecast_name' AS version
,o.fesdat
,o.dhidat
,o.fesind
,o.dhpost
,o.fspr
,o.ddqtoi
,o.ddqtsi
,o.fgqshp
,o.diqtsh
,o.diext
,o.ditdis
,o.discj
,o.dhincr
,o.plnt
,o.promo
,o.return_reas
,o.terms
,o.custpo
,o.remit_to
,o.bill_class
,o.bill_cust
,o.bill_rep
,o.bill_terr
,o.ship_class
,o.ship_cust
,o.ship_rep
,o.ship_terr
,o.dsm
,o.account
,o.shipgrp
,o.geo
,o.chan
,o.chansub
,o.orig_ctry
,o.orig_prov
,o.orig_post
,o.bill_ctry
,o.bill_prov
,o.bill_post
,o.dest_ctry
,o.dest_prov
,o.dest_post
,o.part
,o.styc
,o.colc
,o.colgrp
,o.coltier
,o.colstat
,o.sizc
,o.pckg
,o.kit
,o.brnd
,o.majg
,o.ming
,o.majs
,o.mins
,o.gldco
,o.gldc
,o.glec
,o.harm
,o.clss
,o.brand
,o.assc
,o.ddunit
,o.unti
,o.lbs
,o.plt
,o.plcd
,o.fs_line
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,o.fb_qty * vscale.factor AS fb_qty
,o.fb_val_loc * vscale.factor AS fb_val_loc
,o.fb_val_loc_dis
,o.fb_val_loc_qt
,o.fb_val_loc_pl
,o.fb_val_loc_tar
,o.fb_cst_loc * vscale.factor AS fb_cst_loc
,o.fb_cst_loc_cur
,o.fb_cst_loc_fut
,o.calc_status
,o.flag
,o.odate
,o.oseas
,o.rdate
,o.rseas
,o.sdate
,o.sseas
,'forecast name' AS version
,'scale vol' AS iter ,'scale vol' AS iter
FROM FROM
basemix o basemix o
@ -245,18 +71,18 @@ FROM
,pscale AS ( ,pscale AS (
SELECT SELECT
(SELECT pincr FROM target) AS target_increment (SELECT pincr FROM target) AS target_increment
,sum(fb_val_loc) AS value ,sum("Amount") AS value
,CASE WHEN (SELECT sum(fb_val_loc) FROM volume) = 0 THEN ,CASE WHEN (SELECT sum("Amount") FROM volume) = 0 THEN
--if the base value is -0- scaling will not work, need to generate price, factor goes to -0- --if the base value is -0- scaling will not work, need to generate price, factor goes to -0-
0 0
ELSE ELSE
--if the target dollar value still does not match the target increment, make this adjustment --if the target dollar value still does not match the target increment, make this adjustment
((SELECT pincr FROM target)-(SELECT sum(fb_val_loc) FROM volume))/(SELECT sum(fb_val_loc) FROM volume) ((SELECT pincr FROM target)-(SELECT sum("Amount") FROM volume))/(SELECT sum("Amount") FROM volume)
END factor END factor
,CASE WHEN (SELECT sum(fb_val_loc) FROM volume) = 0 THEN ,CASE WHEN (SELECT sum("Amount") FROM volume) = 0 THEN
CASE WHEN ((SELECT pincr::numeric FROM target) - (SELECT sum(fb_val_loc) FROM volume)) <> 0 THEN CASE WHEN ((SELECT pincr::numeric FROM target) - (SELECT sum("Amount") FROM volume)) <> 0 THEN
--if the base value is -0- but the target value hasn't been achieved, derive a price to apply --if the base value is -0- but the target value hasn't been achieved, derive a price to apply
((SELECT pincr::numeric FROM target) - (SELECT sum(fb_val_loc) FROM volume))/(SELECT sum(fb_qty) FROM volume) ((SELECT pincr::numeric FROM target) - (SELECT sum("Amount") FROM volume))/(SELECT sum(app_units) FROM volume)
ELSE ELSE
0 0
END END
@ -268,108 +94,17 @@ FROM
) )
,pricing AS ( ,pricing AS (
SELECT SELECT
o."ddord#" o.id
,o."dditm#" ,o.logid
,o."fgbol#" ,o."Trans. Date"
,o."fgent#" ,o."Post Date"
,o."diinv#" ,o."Description"
,o."dilin#" ,(CASE WHEN pscale.factor = 0 THEN o.app_units * pscale.mod_price ELSE o."Amount" * pscale.factor END)::numeric AS Amount
,o.quoten ,o."Category"
,o.quotel ,o."Party"
,o.dcodat ,o."Reason"
,o.ddqdat
,o.dcmdat
,o.fesdat
,o.dhidat
,o.fesind
,o.dhpost
,o.fspr
,o.ddqtoi
,o.ddqtsi
,o.fgqshp
,o.diqtsh
,o.diext
,o.ditdis
,o.discj
,o.dhincr
,o.plnt
,o.promo
,o.return_reas
,o.terms
,o.custpo
,o.remit_to
,o.bill_class
,o.bill_cust
,o.bill_rep
,o.bill_terr
,o.ship_class
,o.ship_cust
,o.ship_rep
,o.ship_terr
,o.dsm
,o.account
,o.shipgrp
,o.geo
,o.chan
,o.chansub
,o.orig_ctry
,o.orig_prov
,o.orig_post
,o.bill_ctry
,o.bill_prov
,o.bill_post
,o.dest_ctry
,o.dest_prov
,o.dest_post
,o.part
,o.styc
,o.colc
,o.colgrp
,o.coltier
,o.colstat
,o.sizc
,o.pckg
,o.kit
,o.brnd
,o.majg
,o.ming
,o.majs
,o.mins
,o.gldco
,o.gldc
,o.glec
,o.harm
,o.clss
,o.brand
,o.assc
,o.ddunit
,o.unti
,o.lbs
,o.plt
,o.plcd
,o.fs_line
,o.r_currency
,o.r_rate
,o.c_currency
,o.c_rate
,0::numeric ,0::numeric
,(CASE WHEN pscale.factor = 0 THEN o.fb_qty * pscale.mod_price ELSE o.fb_val_loc * pscale.factor END)::numeric AS fb_val_loc ,'app_forecast_name' AS version
,o.fb_val_loc_dis
,o.fb_val_loc_qt
,o.fb_val_loc_pl
,o.fb_val_loc_tar
,0::numeric
,o.fb_cst_loc_cur
,o.fb_cst_loc_fut
,o.calc_status
,o.flag
,o.odate
,o.oseas
,o.rdate
,o.rseas
,o.sdate
,o.sseas
,'forecast name' AS version
,'scale price' AS iter ,'scale price' AS iter
FROM FROM
volume o volume o
@ -378,7 +113,7 @@ WHERE
pscale.factor <> 0 or pscale.mod_price <> 0 pscale.factor <> 0 or pscale.mod_price <> 0
) )
INSERT INTO INSERT INTO
fc.live tpsv.dcard o
SELECT SELECT
* *
FROM FROM

View File

@ -16,8 +16,8 @@ SELECT
FROM FROM
information_schema.columns information_schema.columns
WHERE WHERE
table_name = 'dcard_mapped' table_name = 'dcard'
AND table_schema = 'fc' AND table_schema = 'tpsv'
ON CONFLICT ON CONSTRAINT target_meta_pk DO UPDATE SET ON CONFLICT ON CONSTRAINT target_meta_pk DO UPDATE SET
opos = EXCLUDED.opos opos = EXCLUDED.opos
,dtype = EXCLUDED.dtype; ,dtype = EXCLUDED.dtype;