vault backup: 2023-11-09 08:07:03
This commit is contained in:
parent
63af8682e6
commit
c0324bb227
@ -22,6 +22,7 @@ DECLARE
|
|||||||
_rslt jsonb;
|
_rslt jsonb;
|
||||||
_targ jsonb;
|
_targ jsonb;
|
||||||
_list jsonb;
|
_list jsonb;
|
||||||
|
_prem jsonb;
|
||||||
_iidx jsonb;
|
_iidx jsonb;
|
||||||
|
|
||||||
BEGIN
|
BEGIN
|
||||||
@ -125,11 +126,17 @@ BEGIN
|
|||||||
GROUP BY
|
GROUP BY
|
||||||
priority;
|
priority;
|
||||||
_rslt := _rslt||COALESCE(_iidx,'{}'::jsonb);
|
_rslt := _rslt||COALESCE(_iidx,'{}'::jsonb);
|
||||||
|
|
||||||
----------------list ppricing-------------------------------
|
----------------list ppricing-------------------------------
|
||||||
SELECT coalesce(rlarp.get_list(_bill, _ship, _item, _qty),'{}'::jsonb) INTO _list;
|
SELECT coalesce(rlarp.get_list(_bill, _ship, _item, _qty),'{}'::jsonb) INTO _list;
|
||||||
_rslt := _rslt||_list;
|
_rslt := _rslt||_list;
|
||||||
--RAISE NOTICE 'list: %', jsonb_pretty(_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;
|
RETURN _rslt;
|
||||||
|
|
||||||
END;
|
END;
|
||||||
|
@ -1,68 +1,64 @@
|
|||||||
DROP FUNCTION IF EXISTS rlarp.get_premium;
|
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
|
RETURNS jsonb
|
||||||
LANGUAGE plpgsql AS
|
LANGUAGE plpgsql
|
||||||
--DO
|
AS $func$
|
||||||
$func$
|
|
||||||
BEGIN
|
|
||||||
|
|
||||||
DECLARE
|
DECLARE
|
||||||
_factor jsonb;
|
_factor jsonb;
|
||||||
|
|
||||||
|
BEGIN
|
||||||
WITH
|
WITH
|
||||||
--targte spreads--
|
--target spreads--
|
||||||
bridge AS (
|
bridge AS (
|
||||||
SELECT
|
SELECT
|
||||||
-- 'FHR14000' mold
|
_mold AS mold
|
||||||
--,2024 season
|
,_season AS season
|
||||||
--,'DIRECT' chan
|
,_chan AS chan
|
||||||
--,'v1:B..SLV..' relevant
|
,_relevant AS relevant
|
||||||
--,'v1:S..SLV..' quoted
|
,_quoted AS quoted
|
||||||
_mold mold
|
),
|
||||||
,_season season
|
ts AS (
|
||||||
,_chan chan
|
|
||||||
,_relevant relevant
|
|
||||||
,_quoted quoted
|
|
||||||
)
|
|
||||||
,ts AS (
|
|
||||||
SELECT
|
SELECT
|
||||||
t.*
|
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) AS spread
|
||||||
,t.target_price/min(t.target_price) over (partition by t.mold, t.chan, t.season) spread
|
|
||||||
,b.quoted
|
,b.quoted
|
||||||
,b.relevant
|
,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
|
FROM
|
||||||
pricequote.market_setavgprice t
|
pricequote.market_setavgprice t
|
||||||
INNER JOIN bridge b ON
|
INNER JOIN bridge b ON
|
||||||
t.mold = b.mold
|
t.mold = b.mold
|
||||||
and t.season = b.season
|
AND t.season = b.season
|
||||||
and t.chan = b.chan
|
AND t.chan = b.chan
|
||||||
and t.data_segment like 'v1%'
|
AND t.data_segment LIKE 'v1%'
|
||||||
and t.geo = 'ALL'
|
AND t.geo = 'ALL'
|
||||||
and t.country = 'ALL'
|
AND t.country = 'ALL'
|
||||||
and t.geo = 'ALL'
|
|
||||||
ORDER BY
|
|
||||||
target_price ASC
|
|
||||||
)
|
)
|
||||||
--SELECT * FROM ts
|
|
||||||
SELECT
|
SELECT
|
||||||
--mold
|
jsonb_build_object(
|
||||||
--,chan
|
'bridgePremium',
|
||||||
--,season
|
ROUND(max(spread) FILTER (WHERE flag = 'get to here') / max(spread) FILTER (WHERE flag = 'from here'), 5)
|
||||||
--,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))
|
|
||||||
INTO
|
INTO
|
||||||
_factor
|
_factor
|
||||||
FROM
|
FROM
|
||||||
ts
|
ts
|
||||||
GROUP BY
|
GROUP BY
|
||||||
mold
|
mold, chan, season;
|
||||||
,chan
|
|
||||||
,season;
|
RAISE NOTICE 'relevant: %' , _relevant;
|
||||||
|
RAISE NOTICE 'quoted: %' , _quoted;
|
||||||
|
|
||||||
RETURN _factor;
|
RETURN _factor;
|
||||||
END
|
END
|
||||||
$func$
|
$func$;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user