From 3557d5c3b6f6f6ddac7f43907b13f4aa4be78ec3 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Wed, 8 Nov 2023 12:47:06 -0500 Subject: [PATCH] vault backup: 2023-11-08 12:47:06 --- sql/guidance.pg.sql | 42 ------------------------------------------ 1 file changed, 42 deletions(-) delete mode 100644 sql/guidance.pg.sql diff --git a/sql/guidance.pg.sql b/sql/guidance.pg.sql deleted file mode 100644 index d67e528..0000000 --- a/sql/guidance.pg.sql +++ /dev/null @@ -1,42 +0,0 @@ -CREATE OR REPLACE FUNCTION rlarp.apply_guid(data jsonb) -RETURNS jsonb -LANGUAGE plv8 -AS $function$ - - -function findMostRecentPrice(data) { - let mostRecentPrice = null; - let mostRecentYear = null; - - // Iterate through each product - data.forEach( data.hist => { - // Check if the product matches the customer channel and version - if (product.chan === cust && (product.v1ds === prod || product.v0ds === prod)) { - // Iterate through the seasons for the product - for (let year in product.season) { - // Convert year to number for comparison - let yearNum = parseInt(year); - // Check if this year is more recent than the current most recent year - if (mostRecentYear === null || yearNum > mostRecentYear) { - mostRecentYear = yearNum; - // Update the most recent price - mostRecentPrice = product.season[year].price_usd; - } - } - } - }); - - return mostRecentPrice; -} - -// Example usage: -const jsonData = data; - -const cust = 'W'; // or 'D', depending on the customer -const prod = 'TUH10000'; // the product version you're interested in - -const price = findMostRecentPrice(jsonData.data, cust, prod); -console.log(`The most recent price for the customer is: ${price}`); -return price; - -$function$;