vault backup: 2023-11-09 08:07:03

This commit is contained in:
Paul Trowbridge 2023-11-09 08:07:03 -05:00
parent 63af8682e6
commit c0324bb227
2 changed files with 46 additions and 43 deletions

View File

@ -22,6 +22,7 @@ DECLARE
_rslt jsonb;
_targ jsonb;
_list jsonb;
_prem jsonb;
_iidx jsonb;
BEGIN
@ -125,11 +126,17 @@ BEGIN
GROUP BY
priority;
_rslt := _rslt||COALESCE(_iidx,'{}'::jsonb);
----------------list ppricing-------------------------------
SELECT coalesce(rlarp.get_list(_bill, _ship, _item, _qty),'{}'::jsonb) INTO _list;
_rslt := _rslt||_list;
--RAISE NOTICE 'list: %', jsonb_pretty(_list);
----------------list ppricing-------------------------------
SELECT coalesce(rlarp.get_premium(_stlc, _seas, (SELECT xchan FROM _chx WHERE chan = _chan),_v1ds, ((_rslt->'mostRelevantCustomerPriceInfo')->'source')->>'v1ds'),'{}'::jsonb) INTO _prem;
_rslt := _rslt||_prem;
--RAISE NOTICE 'list: %', jsonb_pretty(_list);
RETURN _rslt;
END;

View File

@ -1,68 +1,64 @@
DROP FUNCTION IF EXISTS rlarp.get_premium;
CREATE OR REPLACE FUNCTION rlarp.get_premium(_mold text, _season int, _chan text, _relevant text, _quoted text)
CREATE OR REPLACE FUNCTION rlarp.get_premium(
_mold text,
_season int,
_chan text,
_relevant text,
_quoted text
)
RETURNS jsonb
LANGUAGE plpgsql AS
--DO
$func$
BEGIN
LANGUAGE plpgsql
AS $func$
DECLARE
_factor jsonb;
BEGIN
WITH
--targte spreads--
--target spreads--
bridge AS (
SELECT
-- 'FHR14000' mold
--,2024 season
--,'DIRECT' chan
--,'v1:B..SLV..' relevant
--,'v1:S..SLV..' quoted
_mold mold
,_season season
,_chan chan
,_relevant relevant
,_quoted quoted
)
,ts AS (
_mold AS mold
,_season AS season
,_chan AS chan
,_relevant AS relevant
,_quoted AS quoted
),
ts AS (
SELECT
t.*
--, round(target_price/min(target_price) over (partition by mold, chan, season),5) spread
,t.target_price/min(t.target_price) over (partition by t.mold, t.chan, t.season) spread
,t.target_price / min(t.target_price) over (partition by t.mold, t.chan, t.season) AS spread
,b.quoted
,b.relevant
,CASE t.data_segment WHEN b.quoted THEN 'get to here' WHEN b.relevant THEN 'from here' END flag
,CASE
WHEN t.data_segment = b.quoted THEN 'get to here'
WHEN t.data_segment = b.relevant THEN 'from here'
END AS flag
FROM
pricequote.market_setavgprice t
INNER JOIN bridge b ON
t.mold = b.mold
and t.season = b.season
and t.chan = b.chan
and t.data_segment like 'v1%'
and t.geo = 'ALL'
and t.country = 'ALL'
and t.geo = 'ALL'
ORDER BY
target_price ASC
AND t.season = b.season
AND t.chan = b.chan
AND t.data_segment LIKE 'v1%'
AND t.geo = 'ALL'
AND t.country = 'ALL'
)
--SELECT * FROM ts
SELECT
--mold
--,chan
--,season
--,ROUND(max(spread) FILTER (WHERE flag = 'get to here'),5) quote
--,ROUND(max(spread) FILTER (WHERE flag = 'from here') ,5) relevant
jsonb_build_object('bridgePremium',ROUND(max(spread) FILTER (WHERE flag = 'get to here')
/max(spread) FILTER (WHERE flag = 'from here') ,5))
jsonb_build_object(
'bridgePremium',
ROUND(max(spread) FILTER (WHERE flag = 'get to here') / max(spread) FILTER (WHERE flag = 'from here'), 5)
)
INTO
_factor
FROM
ts
GROUP BY
mold
,chan
,season;
mold, chan, season;
RAISE NOTICE 'relevant: %' , _relevant;
RAISE NOTICE 'quoted: %' , _quoted;
RETURN _factor;
END
$func$
$func$;