update closest to use neighbor lag times but target sequence month

This commit is contained in:
Trowbridge 2019-03-06 07:40:43 -05:00
parent 69766c6f42
commit caa287b631
3 changed files with 75 additions and 54 deletions

View File

@ -438,6 +438,7 @@ server.get('/addmonth_v', bodyParser.json(), function (req, res) {
--,requestdate-orderdate
--,shipdate - requestdate
)
,targm AS (select s from mseq where m = '` + req.body.month + `' )
,mmixp AS (
SELECT
_month
@ -453,11 +454,12 @@ server.get('/addmonth_v', bodyParser.json(), function (req, res) {
)
,closest AS (
SELECT
_month
_month, targm.s
FROM
mmixp
CROSS JOIN targm
ORDER BY
abs(seq - (select s from mseq where m = '` + req.body.month + `' )) ASC
abs(seq - targm.s) ASC
LIMIT 1
)
--SELECT * FROM mmixp order by seq asc, vperc desc
@ -716,23 +718,23 @@ server.get('/addmonth_v', bodyParser.json(), function (req, res) {
,b.fb_val_loc_pl*s.factor*m.momix fb_val_loc_pl
,b.calc_status --0
,b.flag --0
,make_date(mseq.yr + 2020,mseq.cal,m.odom) orderdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag requestdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag shipdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) adj_orderdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag adj_requestdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag adj_shipdate
,make_date(mseq.yr + 2020,closest.s,m.odom) orderdate
,make_date(mseq.yr + 2020,closest.s,m.odom) + rlag requestdate
,make_date(mseq.yr + 2020,closest.s,m.odom) + rlag + slag shipdate
,make_date(mseq.yr + 2020,closest.s,m.odom) adj_orderdate
,make_date(mseq.yr + 2020,closest.s,m.odom) + rlag adj_requestdate
,make_date(mseq.yr + 2020,closest.s,m.odom) + rlag + slag adj_shipdate
,b.version --calculated
,b.iter --calculated
-----------------------ui columns--------------------------------
,'adjust volume' iterdet
,null::jsonb iterdef
,od.ssyr order_season
,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom),'Mon') order_month
,to_char(make_date(mseq.yr + 2020,closest.s,m.odom),'Mon') order_month
,sd.ssyr ship_season
,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag,'Mon') ship_month
,to_char(make_date(mseq.yr + 2020,closest.s,m.odom) + rlag + slag,'Mon') ship_month
,rd.ssyr request_season
,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag,'Mon') request_month
,to_char(make_date(mseq.yr + 2020,closest.s,m.odom) + rlag,'Mon') request_month
,b.part_descr
,b.part_family
,b.part_group
@ -760,14 +762,15 @@ server.get('/addmonth_v', bodyParser.json(), function (req, res) {
basemix b
CROSS JOIN scale s
CROSS JOIN mmixp m
CROSS JOIN closest
LEFT OUTER JOIN mseq ON
mseq.m = m._month
LEFT OUTER JOIN gld od ON
make_date(mseq.yr + 2020,mseq.cal,m.odom) BETWEEN od.sdat AND od.edat
make_date(mseq.yr + 2020,closest.s,m.odom) BETWEEN od.sdat AND od.edat
LEFT OUTER JOIN gld rd ON
make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag BETWEEN rd.sdat AND rd.edat
make_date(mseq.yr + 2020,closest.s,m.odom) + rlag BETWEEN rd.sdat AND rd.edat
LEFT OUTER JOIN gld sd ON
make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat
make_date(mseq.yr + 2020,closest.s,m.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat
WHERE
m._month = (SELECT _month FROM closest)
)
@ -991,6 +994,7 @@ server.get('/addmonth_vp', bodyParser.json(), function (req, res) {
--,requestdate-orderdate
--,shipdate - requestdate
)
,targm AS (select s from mseq where m = '` + req.body.month + `' )
,mmixp AS (
SELECT
_month
@ -1006,11 +1010,12 @@ server.get('/addmonth_vp', bodyParser.json(), function (req, res) {
)
,closest AS (
SELECT
_month
_month, targm.s
FROM
mmixp
CROSS JOIN targm
ORDER BY
abs(seq - (select s from mseq where m = '` + req.body.month + `' )) ASC
abs(seq - targm.s) ASC
LIMIT 1
)
--SELECT * FROM mmixp order by seq asc, vperc desc
@ -1269,23 +1274,23 @@ server.get('/addmonth_vp', bodyParser.json(), function (req, res) {
,b.fb_val_loc_pl*s.factor*m.momix fb_val_loc_pl
,b.calc_status --0
,b.flag --0
,make_date(mseq.yr + 2020,mseq.cal,m.odom) orderdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag requestdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag shipdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) adj_orderdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag adj_requestdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag adj_shipdate
,make_date(mseq.yr + 2020,closest.s,m.odom) orderdate
,make_date(mseq.yr + 2020,closest.s,m.odom) + rlag requestdate
,make_date(mseq.yr + 2020,closest.s,m.odom) + rlag + slag shipdate
,make_date(mseq.yr + 2020,closest.s,m.odom) adj_orderdate
,make_date(mseq.yr + 2020,closest.s,m.odom) + rlag adj_requestdate
,make_date(mseq.yr + 2020,closest.s,m.odom) + rlag + slag adj_shipdate
,b.version --calculated
,b.iter --calculated
-----------------------ui columns--------------------------------
,'adjust volume' iterdet
,null::jsonb iterdef
,od.ssyr order_season
,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom),'Mon') order_month
,to_char(make_date(mseq.yr + 2020,closest.s,m.odom),'Mon') order_month
,sd.ssyr ship_season
,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag,'Mon') ship_month
,to_char(make_date(mseq.yr + 2020,closest.s,m.odom) + rlag + slag,'Mon') ship_month
,rd.ssyr request_season
,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag,'Mon') request_month
,to_char(make_date(mseq.yr + 2020,closest.s,m.odom) + rlag,'Mon') request_month
,b.part_descr
,b.part_family
,b.part_group
@ -1313,14 +1318,15 @@ server.get('/addmonth_vp', bodyParser.json(), function (req, res) {
basemix b
CROSS JOIN vscale s
CROSS JOIN mmixp m
CROSS JOIN closest
LEFT OUTER JOIN mseq ON
mseq.m = m._month
LEFT OUTER JOIN gld od ON
make_date(mseq.yr + 2020,mseq.cal,m.odom) BETWEEN od.sdat AND od.edat
make_date(mseq.yr + 2020,closest.s,m.odom) BETWEEN od.sdat AND od.edat
LEFT OUTER JOIN gld rd ON
make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag BETWEEN rd.sdat AND rd.edat
make_date(mseq.yr + 2020,closest.s,m.odom) + rlag BETWEEN rd.sdat AND rd.edat
LEFT OUTER JOIN gld sd ON
make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat
make_date(mseq.yr + 2020,closest.s,m.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat
WHERE
m._month = (SELECT _month FROM closest)
)

View File

@ -108,6 +108,7 @@ target AS (select 50000 incr)
--,requestdate-orderdate
--,shipdate - requestdate
)
,targm AS (select s from mseq where m = 'Jul' )
,mmixp AS (
SELECT
_month
@ -121,6 +122,16 @@ target AS (select 50000 incr)
FROM
mmix
)
,closest AS (
SELECT
_month, targm.s
FROM
mmixp
CROSS JOIN targm
ORDER BY
abs(seq - targm.s) ASC
LIMIT 1
)
--SELECT * FROM mmixp order by seq asc, vperc desc
,basemix AS (
SELECT
@ -380,23 +391,23 @@ SELECT
,b.fb_val_loc_pl*s.factor*m.momix fb_val_loc_pl
,b.calc_status --0
,b.flag --0
,make_date(mseq.yr + 2020,mseq.cal,m.odom) orderdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag requestdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag shipdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) adj_orderdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag adj_requestdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag adj_shipdate
,make_date(mseq.yr + 2020,closest.s,m.odom) orderdate
,make_date(mseq.yr + 2020,closest.s,m.odom) + rlag requestdate
,make_date(mseq.yr + 2020,closest.s,m.odom) + rlag + slag shipdate
,make_date(mseq.yr + 2020,closest.s,m.odom) adj_orderdate
,make_date(mseq.yr + 2020,closest.s,m.odom) + rlag adj_requestdate
,make_date(mseq.yr + 2020,closest.s,m.odom) + rlag + slag adj_shipdate
,b.version --calculated
,b.iter --calculated
-----------------------ui columns--------------------------------
,'adjust volume' iterdet
,null::jsonb iterdef
,od.ssyr order_season
,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom),'Mon') order_month
,to_char(make_date(mseq.yr + 2020,closest.s,m.odom),'Mon') order_month
,sd.ssyr ship_season
,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag,'Mon') ship_month
,to_char(make_date(mseq.yr + 2020,closest.s,m.odom) + rlag + slag,'Mon') ship_month
,rd.ssyr request_season
,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag,'Mon') request_month
,to_char(make_date(mseq.yr + 2020,closest.s,m.odom) + rlag,'Mon') request_month
,b.part_descr
,b.part_family
,b.part_group
@ -424,14 +435,15 @@ FROM
basemix b
CROSS JOIN scale s
CROSS JOIN mmixp m
CROSS JOIN closest
LEFT OUTER JOIN mseq ON
mseq.m = m._month
LEFT OUTER JOIN gld od ON
make_date(mseq.yr + 2020,mseq.cal,m.odom) BETWEEN od.sdat AND od.edat
make_date(mseq.yr + 2020,closest.s,m.odom) BETWEEN od.sdat AND od.edat
LEFT OUTER JOIN gld rd ON
make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag BETWEEN rd.sdat AND rd.edat
make_date(mseq.yr + 2020,closest.s,m.odom) + rlag BETWEEN rd.sdat AND rd.edat
LEFT OUTER JOIN gld sd ON
make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat
make_date(mseq.yr + 2020,closest.s,m.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat
WHERE
m._month = 'Jul'
)

View File

@ -111,6 +111,7 @@ target AS (select -50000 vincr, 20000 pincr)
--,requestdate-orderdate
--,shipdate - requestdate
)
,targm AS (select s from mseq where m = 'Jul' )
,mmixp AS (
SELECT
_month
@ -126,11 +127,12 @@ target AS (select -50000 vincr, 20000 pincr)
)
,closest AS (
SELECT
_month
_month, targm.s
FROM
mmixp
CROSS JOIN targm
ORDER BY
abs(seq - (select s from mseq where m = 'Jul' )) ASC
abs(seq - targm.s) ASC
LIMIT 1
)
--SELECT * FROM mmixp order by seq asc, vperc desc
@ -393,23 +395,23 @@ SELECT
,b.fb_val_loc_pl*s.factor*m.momix fb_val_loc_pl
,b.calc_status --0
,b.flag --0
,make_date(mseq.yr + 2020,mseq.cal,m.odom) orderdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag requestdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag shipdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) adj_orderdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag adj_requestdate
,make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag adj_shipdate
,make_date(mseq.yr + 2020,closest.s,m.odom) orderdate
,make_date(mseq.yr + 2020,closest.s,m.odom) + rlag requestdate
,make_date(mseq.yr + 2020,closest.s,m.odom) + rlag + slag shipdate
,make_date(mseq.yr + 2020,closest.s,m.odom) adj_orderdate
,make_date(mseq.yr + 2020,closest.s,m.odom) + rlag adj_requestdate
,make_date(mseq.yr + 2020,closest.s,m.odom) + rlag + slag adj_shipdate
,b.version --calculated
,b.iter --calculated
-----------------------ui columns--------------------------------
,'adjust volume' iterdet
,null::jsonb iterdef
,od.ssyr order_season
,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom),'Mon') order_month
,to_char(make_date(mseq.yr + 2020,closest.s,m.odom),'Mon') order_month
,sd.ssyr ship_season
,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag,'Mon') ship_month
,to_char(make_date(mseq.yr + 2020,closest.s,m.odom) + rlag + slag,'Mon') ship_month
,rd.ssyr request_season
,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag,'Mon') request_month
,to_char(make_date(mseq.yr + 2020,closest.s,m.odom) + rlag,'Mon') request_month
,b.part_descr
,b.part_family
,b.part_group
@ -437,14 +439,15 @@ FROM
basemix b
CROSS JOIN vscale s
CROSS JOIN mmixp m
CROSS JOIN closest
LEFT OUTER JOIN mseq ON
mseq.m = m._month
LEFT OUTER JOIN gld od ON
make_date(mseq.yr + 2020,mseq.cal,m.odom) BETWEEN od.sdat AND od.edat
make_date(mseq.yr + 2020,closest.s,m.odom) BETWEEN od.sdat AND od.edat
LEFT OUTER JOIN gld rd ON
make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag BETWEEN rd.sdat AND rd.edat
make_date(mseq.yr + 2020,closest.s,m.odom) + rlag BETWEEN rd.sdat AND rd.edat
LEFT OUTER JOIN gld sd ON
make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat
make_date(mseq.yr + 2020,closest.s,m.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat
WHERE
m._month = (SELECT _month FROM closest)
)