From ca730bb9bda59086f9408edd73558e5f7c793091 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Mon, 6 Nov 2023 15:31:06 -0500 Subject: [PATCH] vault backup: 2023-11-06 15:31:06 --- api.ts | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/api.ts b/api.ts index 1960f6b..1435701 100644 --- a/api.ts +++ b/api.ts @@ -34,10 +34,12 @@ const query = await Deno.readTextFile("sql/get.pg.sql"); function apply_guidance(doc: any) { let mostRelevantMarketPrice = null; let mostRelevantMarketKey = null; + let mostRelevantMarketSeason = null; let highestMarketRelevanceLevel = -1; let mostRelevantCustomerPrice = null; let mostRelevantCustomerKey = null; + let mostRelevantCustomerSeason = null; let highestCustomerRelevanceLevel = -1; // Function to update price and assign relevance indicator @@ -49,6 +51,7 @@ function apply_guidance(doc: any) { const recentYear = Math.max(...years.map(Number)); const lastPrice = item.season[recentYear].price_usd; item.last_price = lastPrice; + item.last_season = recentYear; } else { item.last_price = null; // or some default value as appropriate } @@ -77,17 +80,19 @@ function apply_guidance(doc: any) { item.customerRelevance = customerRelevance; // Update the most relevant market price if this item's relevance is higher and it doesn't have a 'cust' key - if (marketRelevance > highestMarketRelevanceLevel && !('cust' in item)) { + if (marketRelevance > highestMarketRelevanceLevel) { highestMarketRelevanceLevel = marketRelevance; mostRelevantMarketPrice = item.last_price; mostRelevantMarketKey = histKey; + mostRelevantMarketSeason = item.last_season; // Assuming 'season' is the key where the season info is stored } // Update the most relevant customer price if this item's relevance is higher and it has a 'cust' key - if (customerRelevance > highestCustomerRelevanceLevel && 'cust' in item) { + if (customerRelevance > highestCustomerRelevanceLevel) { highestCustomerRelevanceLevel = customerRelevance; mostRelevantCustomerPrice = item.last_price; mostRelevantCustomerKey = histKey; + mostRelevantCustomerSeason = item.last_season; // Assuming 'season' is the key where the season info is stored } } } @@ -102,7 +107,8 @@ function apply_guidance(doc: any) { if (mostRelevantMarketPrice !== null) { doc.mostRelevantMarketPriceInfo = { price: mostRelevantMarketPrice, - histKey: mostRelevantMarketKey + histKey: mostRelevantMarketKey, + season: mostRelevantMarketSeason }; } @@ -110,11 +116,23 @@ function apply_guidance(doc: any) { if (mostRelevantCustomerPrice !== null) { doc.mostRelevantCustomerPriceInfo = { price: mostRelevantCustomerPrice, - histKey: mostRelevantCustomerKey + histKey: mostRelevantCustomerKey, + season: mostRelevantCustomerSeason }; } doc.targetPrice = doc.v1tp ?? doc.v0tp ?? null; + // Determine the anchor price and source + if (doc.targetPrice !== undefined && (mostRelevantCustomerPrice === undefined || doc.targetPrice < mostRelevantCustomerPrice)) { + doc.anchorPrice = doc.targetPrice; + doc.anchorSource = 'targetPrice'; + } else if (mostRelevantCustomerPrice !== undefined) { + doc.anchorPrice = mostRelevantCustomerPrice; + doc.anchorSource = 'customerPrice'; + } else { + doc.anchorPrice = null; + doc.anchorSource = 'none'; // or any other default value you wish to indicate no anchor price was found + } return doc; } @@ -130,6 +148,7 @@ function updateWithMostRecentPrice(items) { const lastPrice = item.season[recentYear].price_usd; // Append the last_price to the item item.last_price = lastPrice; + item.last_year = recentYear; } }