vault backup: 2023-11-06 16:09:59

This commit is contained in:
Paul Trowbridge 2023-11-06 16:09:59 -05:00
parent ba44e463d2
commit 480cd9bc76
2 changed files with 59 additions and 11 deletions

32
api.ts
View File

@ -37,9 +37,11 @@ function apply_guidance(doc: any) {
let mostRelevantMarketSeason = null; let mostRelevantMarketSeason = null;
let highestMarketRelevanceLevel = -1; let highestMarketRelevanceLevel = -1;
let mostRelevantCustomerPrice = null; let mostRelevantCustomerPriceEarly = null;
let mostRelevantCustomerPriceRecent = null;
let mostRelevantCustomerKey = null; let mostRelevantCustomerKey = null;
let mostRelevantCustomerSeason = null; let mostRelevantCustomerSeasonEarly = null;
let mostRelevantCustomerSeasonRecent = null;
let highestCustomerRelevanceLevel = -1; let highestCustomerRelevanceLevel = -1;
// Function to update price and assign relevance indicator // Function to update price and assign relevance indicator
@ -49,9 +51,13 @@ function apply_guidance(doc: any) {
const years = Object.keys(item.season); const years = Object.keys(item.season);
if (years.length > 0) { if (years.length > 0) {
const recentYear = Math.max(...years.map(Number)); const recentYear = Math.max(...years.map(Number));
const earlyYear = Math.min(...years.map(Number));
const lastPrice = item.season[recentYear].price_usd; const lastPrice = item.season[recentYear].price_usd;
const earlyPrice = item.season[earlyYear].price_usd;
item.last_price = lastPrice; item.last_price = lastPrice;
item.early_price = earlyPrice;
item.last_season = recentYear; item.last_season = recentYear;
item.early_season = earlyYear;
} else { } else {
item.last_price = null; // or some default value as appropriate 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 // Update the most relevant customer price if this item's relevance is higher and it has a 'cust' key
if (customerRelevance > highestCustomerRelevanceLevel) { if (customerRelevance > highestCustomerRelevanceLevel) {
highestCustomerRelevanceLevel = customerRelevance; highestCustomerRelevanceLevel = customerRelevance;
mostRelevantCustomerPrice = item.last_price; mostRelevantCustomerPriceRecent = item.last_price;
mostRelevantCustomerPriceEarly = item.early_price;
mostRelevantCustomerKey = histKey; 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 // Assign the most relevant customer price and key to the top level of the document
if (mostRelevantCustomerPrice !== null) { if (mostRelevantCustomerPriceRecent !== null) {
doc.mostRelevantCustomerPriceInfo = { doc.mostRelevantCustomerPriceInfo = {
price: mostRelevantCustomerPrice, price: mostRelevantCustomerPriceRecent,
price_early: mostRelevantCustomerPriceEarly,
histKey: mostRelevantCustomerKey, histKey: mostRelevantCustomerKey,
season: mostRelevantCustomerSeason season: mostRelevantCustomerSeasonRecent,
season_early: mostRelevantCustomerSeasonEarly
}; };
} }
doc.targetPrice = doc.v1tp ?? doc.v0tp ?? null; doc.targetPrice = doc.v1tp ?? doc.v0tp ?? null;
// Determine the anchor price and source // 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.anchorPrice = doc.targetPrice;
doc.anchorSource = 'Target Price'; doc.anchorSource = 'Target Price';
} else if (mostRelevantCustomerPrice !== undefined) { } else if (mostRelevantCustomerPriceEarly !== undefined) {
doc.anchorPrice = mostRelevantCustomerPrice; doc.anchorPrice = mostRelevantCustomerPriceEarly;
doc.anchorSource = doc.mostRelevantCustomerSeason + ' Customer Price'; doc.anchorSource = mostRelevantCustomerSeasonEarly + ' Customer Price';
} else { } else {
doc.anchorPrice = null; doc.anchorPrice = null;
doc.anchorSource = 'none'; // or any other default value you wish to indicate no anchor price was found doc.anchorSource = 'none'; // or any other default value you wish to indicate no anchor price was found

38
cgpt.patch Normal file
View File

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