From 480cd9bc76178cd6605e168d19235482bfa0c79f Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Mon, 6 Nov 2023 16:09:59 -0500 Subject: [PATCH] vault backup: 2023-11-06 16:09:59 --- api.ts | 32 +++++++++++++++++++++----------- cgpt.patch | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 11 deletions(-) create mode 100644 cgpt.patch diff --git a/api.ts b/api.ts index c5f0311..cfd6652 100644 --- a/api.ts +++ b/api.ts @@ -37,9 +37,11 @@ function apply_guidance(doc: any) { let mostRelevantMarketSeason = null; let highestMarketRelevanceLevel = -1; - let mostRelevantCustomerPrice = null; + let mostRelevantCustomerPriceEarly = null; + let mostRelevantCustomerPriceRecent = null; let mostRelevantCustomerKey = null; - let mostRelevantCustomerSeason = null; + let mostRelevantCustomerSeasonEarly = null; + let mostRelevantCustomerSeasonRecent = null; let highestCustomerRelevanceLevel = -1; // Function to update price and assign relevance indicator @@ -49,9 +51,13 @@ function apply_guidance(doc: any) { const years = Object.keys(item.season); if (years.length > 0) { const recentYear = Math.max(...years.map(Number)); + const earlyYear = Math.min(...years.map(Number)); const lastPrice = item.season[recentYear].price_usd; + const earlyPrice = item.season[earlyYear].price_usd; item.last_price = lastPrice; + item.early_price = earlyPrice; item.last_season = recentYear; + item.early_season = earlyYear; } else { item.last_price = null; // or some default value as appropriate } @@ -90,9 +96,11 @@ function apply_guidance(doc: any) { // Update the most relevant customer price if this item's relevance is higher and it has a 'cust' key if (customerRelevance > highestCustomerRelevanceLevel) { highestCustomerRelevanceLevel = customerRelevance; - mostRelevantCustomerPrice = item.last_price; + mostRelevantCustomerPriceRecent = item.last_price; + mostRelevantCustomerPriceEarly = item.early_price; mostRelevantCustomerKey = histKey; - mostRelevantCustomerSeason = item.last_season; // Assuming 'season' is the key where the season info is stored + mostRelevantCustomerSeasonRecent = item.last_season; // Assuming 'season' is the key where the season info is stored + mostRelevantCustomerSeasonEarly = item.early_season; // Assuming 'season' is the key where the season info is stored } } } @@ -113,22 +121,24 @@ function apply_guidance(doc: any) { } // Assign the most relevant customer price and key to the top level of the document - if (mostRelevantCustomerPrice !== null) { + if (mostRelevantCustomerPriceRecent !== null) { doc.mostRelevantCustomerPriceInfo = { - price: mostRelevantCustomerPrice, + price: mostRelevantCustomerPriceRecent, + price_early: mostRelevantCustomerPriceEarly, histKey: mostRelevantCustomerKey, - season: mostRelevantCustomerSeason + season: mostRelevantCustomerSeasonRecent, + season_early: mostRelevantCustomerSeasonEarly }; } doc.targetPrice = doc.v1tp ?? doc.v0tp ?? null; // Determine the anchor price and source - if (doc.targetPrice !== undefined && (mostRelevantCustomerPrice === undefined || doc.targetPrice < mostRelevantCustomerPrice)) { + if (doc.targetPrice !== undefined && (mostRelevantCustomerPriceEarly === undefined || doc.targetPrice < mostRelevantCustomerPriceEarly)) { doc.anchorPrice = doc.targetPrice; doc.anchorSource = 'Target Price'; - } else if (mostRelevantCustomerPrice !== undefined) { - doc.anchorPrice = mostRelevantCustomerPrice; - doc.anchorSource = doc.mostRelevantCustomerSeason + ' Customer Price'; + } else if (mostRelevantCustomerPriceEarly !== undefined) { + doc.anchorPrice = mostRelevantCustomerPriceEarly; + doc.anchorSource = mostRelevantCustomerSeasonEarly + ' Customer Price'; } else { doc.anchorPrice = null; doc.anchorSource = 'none'; // or any other default value you wish to indicate no anchor price was found diff --git a/cgpt.patch b/cgpt.patch new file mode 100644 index 0000000..9b0f32e --- /dev/null +++ b/cgpt.patch @@ -0,0 +1,38 @@ +--- old_apply_guidance.js ++++ new_apply_guidance.js +@@ -1,5 +1,6 @@ + function apply_guidance(doc: any) { + let mostRelevantMarketPrice = null; + let mostRelevantMarketKey = null; ++ let earliestCustomerPriceSince2020 = null; + let highestMarketRelevanceLevel = -1; + + let mostRelevantCustomerPrice = null; +@@ -20,6 +21,15 @@ + let customerRelevance = 0; // Assume 0 is 'not relevant' + + // ... (rest of the existing logic) ++ ++ // Check for the earliest customer price since 2020 ++ if (item.cust && item.last_season >= 2020) { ++ if (earliestCustomerPriceSince2020 === null || item.last_season < earliestCustomerPriceSince2020.season) { ++ earliestCustomerPriceSince2020 = { ++ price: item.last_price, ++ season: item.last_season ++ }; ++ } ++ } + + // ... (rest of the existing logic) + +@@ -50,6 +60,10 @@ + // ... (rest of the existing logic) + + // Assign the most relevant customer price and key to the top level of the document ++ if (earliestCustomerPriceSince2020 !== null) { ++ doc.earliestCustomerPriceSince2020 = earliestCustomerPriceSince2020; ++ } ++ + if (mostRelevantCustomerPrice !== null) { + doc.mostRelevantCustomerPriceInfo = { + price: mostRelevantCustomerPrice,