Compare commits

...

1 Commits

Author SHA1 Message Date
8ab61b7199 change structure of returned history 2023-11-15 15:27:09 -05:00
3 changed files with 37 additions and 46 deletions

View File

@ -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;

View File

@ -123,8 +123,6 @@ 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
@ -141,11 +139,8 @@ FROM
,'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;

View File

@ -117,8 +117,6 @@ 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
@ -135,11 +133,8 @@ FROM
,'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;