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
1 changed files with 23 additions and 4 deletions

27
api.ts
View File

@ -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;
}
}