change structure of returned history
This commit is contained in:
parent
32217d52c4
commit
8ab61b7199
@ -25,8 +25,8 @@ export function apply_guidance(doc: any) {
|
||||
|
||||
const targetPrice = doc.pricing?.v1tp ?? doc.pricing?.v0tp;
|
||||
const priceBand = doc.pricing?.v1stdv ?? doc.pricing?.v0stdv;
|
||||
const earlyPrice = doc.hist?.cust?.early_price;
|
||||
const earlySeason = doc.hist?.cust?.early_season;
|
||||
const earlyPrice = doc.hist?.cust?.[0]?.early_price;
|
||||
const earlySeason = doc.hist?.cust?.[0]?.early_season;
|
||||
const bridgePremium = doc.pricing?.bridgePremium ?? 1.00000;
|
||||
const altHist = doc.hist?.cust?.ds;
|
||||
const iidx = doc.pricing?.iidx;
|
||||
|
@ -123,29 +123,24 @@ FROM
|
||||
--,flag.source
|
||||
--,rel.prefer
|
||||
--,row_number() OVER (PARTITION BY flag.source ORDER BY rel.prefer ASC) best
|
||||
jsonb_strip_nulls(
|
||||
jsonb_build_object(
|
||||
flag.source
|
||||
,jsonb_build_object(
|
||||
'relevance' ,relevance
|
||||
,'avgunits' ,avgunits
|
||||
,'avgordcount' ,avgordcount
|
||||
,'avgcustcount' ,avgcustcount
|
||||
,'avgtargetprice' ,avgtargetprice
|
||||
,'early_season' ,early_season
|
||||
,'early_price' ,early_price
|
||||
,'recent_season' ,recent_season
|
||||
,'recent_price' ,recent_price
|
||||
,'last_season' ,last_season
|
||||
,'last_price' ,last_price
|
||||
,'ds' ,COALESCE(v1ds,v0ds)
|
||||
,'rank' ,row_number() OVER (PARTITION BY flag.source ORDER BY rel.prefer ASC)
|
||||
,'pricinghistory' ,season
|
||||
)
|
||||
)
|
||||
flag.source
|
||||
,jsonb_build_object(
|
||||
'relevance' ,relevance
|
||||
,'avgunits' ,avgunits
|
||||
,'avgordcount' ,avgordcount
|
||||
,'avgcustcount' ,avgcustcount
|
||||
,'avgtargetprice' ,avgtargetprice
|
||||
,'early_season' ,early_season
|
||||
,'early_price' ,early_price
|
||||
,'recent_season' ,recent_season
|
||||
,'recent_price' ,recent_price
|
||||
,'last_season' ,last_season
|
||||
,'last_price' ,last_price
|
||||
,'ds' ,COALESCE(v1ds,v0ds)
|
||||
,'rank' ,row_number() OVER (PARTITION BY flag.source ORDER BY rel.prefer ASC)
|
||||
,'pricinghistory' ,season
|
||||
) doc
|
||||
,row_number() OVER (PARTITION BY flag.source ORDER BY rel.prefer ASC) rnk
|
||||
,season
|
||||
FROM
|
||||
flag
|
||||
LEFT OUTER JOIN rel ON
|
||||
@ -154,7 +149,8 @@ FROM
|
||||
relevance ~ 'vol|exact'
|
||||
)
|
||||
--SELECT jsonb_pretty(jsonb_agg(doc)) FROM rel_sort
|
||||
SELECT jsonb_obj_aggc(doc) INTO _result FROM rel_sort WHERE rnk = 1;
|
||||
SELECT jsonb_obj_aggc(doc) INTO _result FROM (SELECT jsonb_build_object(source, jsonb_agg(doc ORDER BY doc->>'rank' ASC)) doc FROM rel_sort GROUP BY source) x;
|
||||
--SELECT jsonb_obj_aggc(doc) INTO _result FROM rel_sort WHERE rnk = 1;
|
||||
|
||||
RETURN _result;
|
||||
|
||||
|
@ -117,29 +117,24 @@ FROM
|
||||
--,flag.source
|
||||
--,rel.prefer
|
||||
--,row_number() OVER (PARTITION BY flag.source ORDER BY rel.prefer ASC) best
|
||||
jsonb_strip_nulls(
|
||||
jsonb_build_object(
|
||||
flag.source
|
||||
,jsonb_build_object(
|
||||
'relevance' ,relevance
|
||||
,'avgunits' ,avgunits
|
||||
,'avgordcount' ,avgordcount
|
||||
,'avgcustcount' ,avgcustcount
|
||||
,'avgtargetprice' ,avgtargetprice
|
||||
,'early_season' ,early_season
|
||||
,'early_price' ,early_price
|
||||
,'recent_season' ,recent_season
|
||||
,'recent_price' ,recent_price
|
||||
,'last_season' ,last_season
|
||||
,'last_price' ,last_price
|
||||
,'ds' ,COALESCE(v1ds,v0ds)
|
||||
,'rank' ,row_number() OVER (PARTITION BY flag.source ORDER BY rel.prefer ASC)
|
||||
,'pricinghistory' ,season
|
||||
)
|
||||
)
|
||||
flag.source
|
||||
,jsonb_build_object(
|
||||
'relevance' ,relevance
|
||||
,'avgunits' ,avgunits
|
||||
,'avgordcount' ,avgordcount
|
||||
,'avgcustcount' ,avgcustcount
|
||||
,'avgtargetprice' ,avgtargetprice
|
||||
,'early_season' ,early_season
|
||||
,'early_price' ,early_price
|
||||
,'recent_season' ,recent_season
|
||||
,'recent_price' ,recent_price
|
||||
,'last_season' ,last_season
|
||||
,'last_price' ,last_price
|
||||
,'ds' ,COALESCE(v1ds,v0ds)
|
||||
,'rank' ,row_number() OVER (PARTITION BY flag.source ORDER BY rel.prefer ASC)
|
||||
,'pricinghistory' ,season
|
||||
) doc
|
||||
,row_number() OVER (PARTITION BY flag.source ORDER BY rel.prefer ASC) rnk
|
||||
,season
|
||||
FROM
|
||||
flag
|
||||
LEFT OUTER JOIN rel ON
|
||||
@ -150,4 +145,4 @@ FROM
|
||||
--SELECT rnk, jsonb_pretty(doc) doc, jsonb_pretty(season) season FROM rel_sort
|
||||
--SELECT jsonb_pretty(jsonb_agg(doc)) FROM rel_sort
|
||||
--SELECT jsonb_pretty(jsonb_obj_aggc(doc)) FROM rel_sort--INTO _result FROM rel_sort WHERE rnk = 1;
|
||||
SELECT * FROM rel_sort;
|
||||
SELECT jsonb_build_object(source, jsonb_agg(doc ORDER BY doc->>'rank' ASC)) FROM rel_sort GROUP BY source;
|
||||
|
Loading…
Reference in New Issue
Block a user