Compare commits
5 Commits
6bb0172c2d
...
37fead59ff
Author | SHA1 | Date | |
---|---|---|---|
37fead59ff | |||
42c5900efe | |||
c61729e017 | |||
ce77ad7de3 | |||
9a410b82d1 |
@ -66,6 +66,7 @@ BEGIN
|
||||
-- 1) Seed queue from matrix
|
||||
--------------------------------------------------------------------
|
||||
DELETE FROM pricequote.queue;
|
||||
-- 1:30
|
||||
|
||||
INSERT INTO pricequote.queue (bill, ship, part, stlc, v1ds, vol, expl, ui_json)
|
||||
SELECT DISTINCT
|
||||
@ -84,7 +85,7 @@ BEGIN
|
||||
AND o.version IN ('Actual', 'Forecast', 'Quotes')
|
||||
AND o.part IS NOT NULL
|
||||
AND SUBSTRING(o.glec, 1, 1) <= '2';
|
||||
-- 46 seconds
|
||||
-- 2:12
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- 2) Enrich: chan, tier, cust, pltq, plevel, partgroup (+stlc fix)
|
||||
@ -126,7 +127,7 @@ BEGIN
|
||||
plevel = s.plevel,
|
||||
partgroup = s.partgroup,
|
||||
stlc = COALESCE(q.stlc, s.stlc_fix);
|
||||
-- 16 seconds
|
||||
-- 4:51
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- 3) Scenario fields from item master: part_v1ds, v0ds, orig costs
|
||||
@ -146,7 +147,7 @@ BEGIN
|
||||
END
|
||||
FROM "CMS.CUSLG".itemm i0
|
||||
WHERE i0.item = q.part;
|
||||
-- 16 seconds
|
||||
-- 3:21
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- 4) History: store hist, extract last_* with precedence helper
|
||||
@ -184,7 +185,7 @@ BEGIN
|
||||
AND lp2.partgroup = q2.partgroup
|
||||
) AS x
|
||||
WHERE q.ctid = x.ctid;
|
||||
-- 2 min 3 sec
|
||||
-- 7:32
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- 5) Target (requested v1ds): tprice, tmath, volume_range
|
||||
@ -201,7 +202,7 @@ BEGIN
|
||||
AND tp.chan = q.chan
|
||||
AND tp.tier = q.tier
|
||||
AND FLOOR(q.vol / NULLIF(q.pltq, 0))::INT <@ tp.vol;
|
||||
-- 22 seconds
|
||||
-- 2:51
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- 6) Target for last_dataseg (tprice_last)
|
||||
@ -217,7 +218,7 @@ BEGIN
|
||||
AND tp2.chan = q.chan
|
||||
AND tp2.tier = q.tier
|
||||
AND FLOOR(q.last_qty / NULLIF(q.pltq, 0))::INT <@ tp2.vol;
|
||||
-- 17 sec
|
||||
-- 1:26
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- 7) Cost data for requested v1ds and last_dataseg
|
||||
@ -250,7 +251,7 @@ BEGIN
|
||||
ON v0l.stlc = q2.stlc AND v0l.v0ds = q2.last_v0ds
|
||||
) AS s
|
||||
WHERE q.ctid = s.ctid;
|
||||
-- 28 seconds
|
||||
-- 4:15
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- 8) List price (lowest valid); allow open-ended ranges (vb_to IS NULL)
|
||||
@ -280,7 +281,7 @@ BEGIN
|
||||
listcode = p.jcplcd
|
||||
FROM best_price p
|
||||
WHERE q.ctid = p.ctid;
|
||||
-- 18 seconds
|
||||
-- 2:48
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- 9) Normalize last (when last_dataseg != v1ds) + effective list flags
|
||||
@ -328,7 +329,7 @@ BEGIN
|
||||
END,
|
||||
listprice_eff = CASE WHEN q.customized <> '' THEN NULL ELSE q.listprice END,
|
||||
list_relevance = CASE WHEN q.customized <> '' THEN 'Ignore - Customized' ELSE '' END;
|
||||
-- 21 seconds
|
||||
-- 2:22
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- 10) Guidance using normalized last + effective list
|
||||
@ -352,7 +353,7 @@ BEGIN
|
||||
) g ON TRUE
|
||||
) s
|
||||
WHERE q.ctid = s.ctid;
|
||||
-- 31 seconds
|
||||
-- 4:33
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- 11) Build expl and ui_json identical to single_price_call
|
||||
@ -498,7 +499,7 @@ BEGIN
|
||||
),
|
||||
'data', q.expl
|
||||
);
|
||||
-- 2 minutes 33 seconds
|
||||
-- 7:59
|
||||
|
||||
--------------------------------------------------------------------
|
||||
-- 12) Merge back into matrix (store both expl and ui)
|
||||
@ -522,7 +523,7 @@ BEGIN
|
||||
AND o.version IN ('Actual', 'Forecast', 'Quotes')
|
||||
AND o.part IS NOT NULL
|
||||
AND SUBSTRING(o.glec, 1, 1) <= '2';
|
||||
-- 9 minutes 35 seconds
|
||||
-- 14:13
|
||||
|
||||
RAISE NOTICE 'Queue processing complete.';
|
||||
END;
|
||||
|
@ -466,8 +466,8 @@ BEGIN
|
||||
CASE ISNULL(q.last_source, '')
|
||||
WHEN 'mrq' THEN 'Similar Quote'
|
||||
WHEN 'mrs' THEN 'Similar Sale'
|
||||
WHEN 'dsq' THEN 'Last Sale'
|
||||
WHEN 'dss' THEN 'Last Quote'
|
||||
WHEN 'dsq' THEN 'Last Quote'
|
||||
WHEN 'dss' THEN 'Last Sale'
|
||||
ELSE ''
|
||||
END
|
||||
ELSE 'No Recent'
|
||||
@ -601,5 +601,5 @@ BEGIN
|
||||
--------------------------------------------------------------------------------
|
||||
-- Final: Return all calculated fields and JSON payloads.
|
||||
--------------------------------------------------------------------------------
|
||||
SELECT guidance_price, ui_json FROM @queue;
|
||||
SELECT guidance_price, ui_json FROM @queue;
|
||||
END;
|
||||
|
@ -14,28 +14,3 @@ GRANT SELECT, INSERT, UPDATE, DELETE ON pricequote.target_prices TO PUBLIC;
|
||||
DROP TABLE IF EXISTS import.core_target;
|
||||
|
||||
CREATE TABLE import.core_target AS (SELECT * FROM pricequote.core_target);
|
||||
|
||||
WITH
|
||||
expand AS (
|
||||
SELECT
|
||||
c.compset,
|
||||
c.stlc,
|
||||
c.floor,
|
||||
b.ds,
|
||||
b.chan,
|
||||
b.tier,
|
||||
b.vol,
|
||||
b.val,
|
||||
b.price,
|
||||
json_pretty(to_json(b.math)) math
|
||||
FROM
|
||||
pricequote.core_target c
|
||||
LEFT JOIN LATERAL pricequote.build_pricing_path_base (options||jsonb_build_object('entity','Anchor','attr',c.stlc,'val',c.floor,'func','Price')) b ON b.lastflag
|
||||
)
|
||||
-- select count(*) from expand
|
||||
INSERT INTO
|
||||
pricequote.target_prices_base
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
expand
|
||||
|
27
tables/rebuild_targets.pg.sql
Normal file
27
tables/rebuild_targets.pg.sql
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
DELETE FROM pricequote.target_prices_base;
|
||||
|
||||
WITH
|
||||
expand AS (
|
||||
SELECT
|
||||
c.compset,
|
||||
c.stlc,
|
||||
c.floor,
|
||||
b.ds,
|
||||
b.chan,
|
||||
b.tier,
|
||||
b.vol,
|
||||
b.val,
|
||||
b.price,
|
||||
b.math math
|
||||
FROM
|
||||
pricequote.core_target c
|
||||
LEFT JOIN LATERAL pricequote.build_pricing_path_base (options||jsonb_build_object('entity','Anchor','attr',c.stlc,'val',c.floor,'func','Price')) b ON b.lastflag
|
||||
)
|
||||
-- select count(*) from expand
|
||||
INSERT INTO
|
||||
pricequote.target_prices_base
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
expand;
|
17
tables/target_prices_base.pg.sql
Normal file
17
tables/target_prices_base.pg.sql
Normal file
@ -0,0 +1,17 @@
|
||||
DROP TABLE pricequote.target_prices_base CASCADE;
|
||||
|
||||
CREATE TABLE pricequote.target_prices_base (
|
||||
compset TEXT NOT NULL,
|
||||
stlc TEXT NOT NULL,
|
||||
floor NUMERIC NOT NULL,
|
||||
ds TEXT NOT NULL,
|
||||
chan TEXT NOT NULL,
|
||||
tier TEXT NOT NULL,
|
||||
vol INT4RANGE NOT NULL,
|
||||
val NUMERIC NOT NULL,
|
||||
price NUMERIC,
|
||||
math TEXT[],
|
||||
PRIMARY KEY (stlc, ds, chan, tier, vol)
|
||||
);
|
||||
|
||||
GRANT SELECT, INSERT, UPDATE, DELETE ON pricequote.target_prices_base TO PUBLIC;
|
Loading…
Reference in New Issue
Block a user