vault backup: 2023-11-06 15:31:06

This commit is contained in:
Paul Trowbridge 2023-11-06 15:31:06 -05:00
parent ffccbdec28
commit ca730bb9bd

27
api.ts
View File

@ -34,10 +34,12 @@ const query = await Deno.readTextFile("sql/get.pg.sql");
function apply_guidance(doc: any) { function apply_guidance(doc: any) {
let mostRelevantMarketPrice = null; let mostRelevantMarketPrice = null;
let mostRelevantMarketKey = null; let mostRelevantMarketKey = null;
let mostRelevantMarketSeason = null;
let highestMarketRelevanceLevel = -1; let highestMarketRelevanceLevel = -1;
let mostRelevantCustomerPrice = null; let mostRelevantCustomerPrice = null;
let mostRelevantCustomerKey = null; let mostRelevantCustomerKey = null;
let mostRelevantCustomerSeason = null;
let highestCustomerRelevanceLevel = -1; let highestCustomerRelevanceLevel = -1;
// Function to update price and assign relevance indicator // 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 recentYear = Math.max(...years.map(Number));
const lastPrice = item.season[recentYear].price_usd; const lastPrice = item.season[recentYear].price_usd;
item.last_price = lastPrice; item.last_price = lastPrice;
item.last_season = recentYear;
} else { } else {
item.last_price = null; // or some default value as appropriate item.last_price = null; // or some default value as appropriate
} }
@ -77,17 +80,19 @@ function apply_guidance(doc: any) {
item.customerRelevance = customerRelevance; item.customerRelevance = customerRelevance;
// Update the most relevant market price if this item's relevance is higher and it doesn't have a 'cust' key // 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; highestMarketRelevanceLevel = marketRelevance;
mostRelevantMarketPrice = item.last_price; mostRelevantMarketPrice = item.last_price;
mostRelevantMarketKey = histKey; 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 // 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; highestCustomerRelevanceLevel = customerRelevance;
mostRelevantCustomerPrice = item.last_price; mostRelevantCustomerPrice = item.last_price;
mostRelevantCustomerKey = histKey; 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) { if (mostRelevantMarketPrice !== null) {
doc.mostRelevantMarketPriceInfo = { doc.mostRelevantMarketPriceInfo = {
price: mostRelevantMarketPrice, price: mostRelevantMarketPrice,
histKey: mostRelevantMarketKey histKey: mostRelevantMarketKey,
season: mostRelevantMarketSeason
}; };
} }
@ -110,11 +116,23 @@ function apply_guidance(doc: any) {
if (mostRelevantCustomerPrice !== null) { if (mostRelevantCustomerPrice !== null) {
doc.mostRelevantCustomerPriceInfo = { doc.mostRelevantCustomerPriceInfo = {
price: mostRelevantCustomerPrice, price: mostRelevantCustomerPrice,
histKey: mostRelevantCustomerKey histKey: mostRelevantCustomerKey,
season: mostRelevantCustomerSeason
}; };
} }
doc.targetPrice = doc.v1tp ?? doc.v0tp ?? null; 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; return doc;
} }
@ -130,6 +148,7 @@ function updateWithMostRecentPrice(items) {
const lastPrice = item.season[recentYear].price_usd; const lastPrice = item.season[recentYear].price_usd;
// Append the last_price to the item // Append the last_price to the item
item.last_price = lastPrice; item.last_price = lastPrice;
item.last_year = recentYear;
} }
} }