vault backup: 2023-11-10 02:22:23
This commit is contained in:
parent
aa5f2a0a51
commit
5e0a1186d8
@ -16,76 +16,76 @@ export function apply_guidance(doc: any) {
|
|||||||
let mostRelevantCustomerSource = null;
|
let mostRelevantCustomerSource = null;
|
||||||
|
|
||||||
// Function to update price and assign relevance indicator
|
// Function to update price and assign relevance indicator
|
||||||
//function setAnchors(items, channelFirstChar, v1ds, v0ds, histKey) {
|
function setAnchors(items, channelFirstChar, v1ds, v0ds, histKey) {
|
||||||
// for (let item of items) {
|
for (let item of items) {
|
||||||
// // Update the last_price with the most recent price
|
// Update the last_price with the most recent price
|
||||||
// const years = Object.keys(item.season).map(Number).filter(year => year >= 2020);
|
const years = Object.keys(item.season).map(Number).filter(year => year >= 2020);
|
||||||
// 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 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;
|
const earlyPrice = item.season[earlyYear].price_usd;
|
||||||
// item.last_price = lastPrice;
|
item.last_price = lastPrice;
|
||||||
// item.early_price = earlyPrice;
|
item.early_price = earlyPrice;
|
||||||
// item.last_season = recentYear;
|
item.last_season = recentYear;
|
||||||
// item.early_season = earlyYear;
|
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
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // Initialize relevance as numeric value
|
// Initialize relevance as numeric value
|
||||||
// let marketRelevance = 0; // Assume 0 is 'not relevant'
|
let marketRelevance = 0; // Assume 0 is 'not relevant'
|
||||||
// let customerRelevance = 0; // Assume 0 is 'not relevant'
|
let customerRelevance = 0; // Assume 0 is 'not relevant'
|
||||||
|
|
||||||
|
|
||||||
// // Check if the first character of the item's channel matches the first character of the document's channel
|
// Check if the first character of the item's channel matches the first character of the document's channel
|
||||||
// if (item.chan.charAt(0) === channelFirstChar) {
|
if (item.chan.charAt(0) === channelFirstChar) {
|
||||||
// marketRelevance = 1; // 'relevant'
|
marketRelevance = 1; // 'relevant'
|
||||||
|
|
||||||
|
|
||||||
// // Further refine relevance based on v1ds and v0ds
|
// Further refine relevance based on v1ds and v0ds
|
||||||
// if (item.v1ds === v1ds) {
|
if (item.v1ds === v1ds) {
|
||||||
// marketRelevance = 2; // 'most relevant' because v1ds matches
|
marketRelevance = 2; // 'most relevant' because v1ds matches
|
||||||
|
|
||||||
// // Check for customer relevance if 'cust' key exists
|
// Check for customer relevance if 'cust' key exists
|
||||||
// customerRelevance = item.cust ? 3 : 0;
|
customerRelevance = item.cust ? 3 : 0;
|
||||||
// } else if (item.v0ds === v0ds) {
|
} else if (item.v0ds === v0ds) {
|
||||||
// marketRelevance = marketRelevance === 2 ? 2 : 1; // Keep relevance as is if v1ds was matched, otherwise it's just 'relevant'
|
marketRelevance = marketRelevance === 2 ? 2 : 1; // Keep relevance as is if v1ds was matched, otherwise it's just 'relevant'
|
||||||
// customerRelevance = item.cust ? 2 : 0;
|
customerRelevance = item.cust ? 2 : 0;
|
||||||
// } else if (item.cust) {
|
} else if (item.cust) {
|
||||||
// customerRelevance = item.v1ds ? 2 : item.v0ds ? 1 : 0;
|
customerRelevance = item.v1ds ? 2 : item.v0ds ? 1 : 0;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // Assign the calculated relevance to the item
|
// Assign the calculated relevance to the item
|
||||||
// item.marketRelevance = marketRelevance;
|
item.marketRelevance = marketRelevance;
|
||||||
// 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) {
|
if (marketRelevance > highestMarketRelevanceLevel) {
|
||||||
// highestMarketRelevanceLevel = marketRelevance;
|
highestMarketRelevanceLevel = marketRelevance;
|
||||||
// mostRelevantMarketPrice = item.last_price;
|
mostRelevantMarketPrice = item.last_price;
|
||||||
// mostRelevantMarketPriceEarly = item.early_price;
|
mostRelevantMarketPriceEarly = item.early_price;
|
||||||
// mostRelevantMarketKey = histKey;
|
mostRelevantMarketKey = histKey;
|
||||||
// mostRelevantMarketSource = item;
|
mostRelevantMarketSource = item;
|
||||||
// delete mostRelevantMarketSource.season;
|
delete mostRelevantMarketSource.season;
|
||||||
// mostRelevantMarketSeason = item.last_season; // Assuming 'season' is the key where the season info is stored
|
mostRelevantMarketSeason = item.last_season; // Assuming 'season' is the key where the season info is stored
|
||||||
// mostRelevantMarketSeasonEarly = item.early_season;
|
mostRelevantMarketSeasonEarly = item.early_season;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // 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;
|
||||||
// mostRelevantCustomerPriceRecent = item.last_price;
|
mostRelevantCustomerPriceRecent = item.last_price;
|
||||||
// mostRelevantCustomerPriceEarly = item.early_price;
|
mostRelevantCustomerPriceEarly = item.early_price;
|
||||||
// mostRelevantCustomerKey = histKey;
|
mostRelevantCustomerKey = histKey;
|
||||||
// mostRelevantCustomerSource = item;
|
mostRelevantCustomerSource = item;
|
||||||
// delete mostRelevantCustomerSource.season;
|
delete mostRelevantCustomerSource.season;
|
||||||
// mostRelevantCustomerSeasonRecent = 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
|
mostRelevantCustomerSeasonEarly = item.early_season; // Assuming 'season' is the key where the season info is stored
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
|
|
||||||
//// Iterate over each key in the "hist" object
|
//// Iterate over each key in the "hist" object
|
||||||
//for (let key of Object.keys(doc.hist)) {
|
//for (let key of Object.keys(doc.hist)) {
|
||||||
@ -117,34 +117,40 @@ export function apply_guidance(doc: any) {
|
|||||||
// };
|
// };
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//doc.targetPrice = doc.v1tp ?? doc.v0tp ?? null;
|
|
||||||
//// Determine the anchor price and source
|
|
||||||
//if (doc.targetPrice !== undefined && (mostRelevantCustomerPriceEarly === undefined || doc.targetPrice < mostRelevantCustomerPriceEarly)) {
|
|
||||||
// doc.anchorPrice = doc.targetPrice;
|
|
||||||
// doc.anchorSource = 'Target 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
|
|
||||||
//}
|
|
||||||
|
|
||||||
//const inflation = Math.max(...Object.keys(doc.iidx).map(Number));
|
doc.targetPrice = doc.v1tp ?? doc.v0tp ?? null;
|
||||||
//const inflationFactor = doc.iidx[inflation] + 1;
|
// Determine the anchor price and source
|
||||||
//doc.inflationFactor = inflationFactor;
|
if (doc.targetPrice !== undefined && (doc.hist.cust.early_price === undefined || doc.targetPrice < doc.hist.cust.early_price)) {
|
||||||
//var calcPrice = doc.anchorPrice * doc.inflationFactor;
|
doc.anchorPrice = doc.targetPrice;
|
||||||
//calcPrice = parseFloat(calcPrice.toFixed(5));
|
doc.anchorSource = 'Target Price';
|
||||||
//let finalReason = "";
|
} else if (doc.hist.cust.early_price !== undefined) {
|
||||||
//if (calcPrice >= doc.list) {
|
if (doc.hist.cust.relevance !== 'customer exact') {
|
||||||
// doc.calcCeiling = "Cap At List";
|
doc.anchorPrice = doc.hist.cust.early_price * doc.bridgePremium;
|
||||||
// doc.finalPrice = doc.list;
|
doc.anchorSource = doc.hist.cust.early_season + ' Similar (' + doc.hist.cust.ds + ') Customer Price ' + doc.hist.cust.early_price + ' x ' + doc.bridgePremium + ' = ' + doc.anchorPrice;
|
||||||
// finalReason = `${doc.anchorSource} ${doc.anchorPrice} x ${inflationFactor} = ${calcPrice} but cap at list ${doc.list}`;
|
} else {
|
||||||
//} else {
|
doc.anchorPrice = doc.hist.cust.early_price;
|
||||||
// doc.finalPrice = calcPrice;
|
doc.anchorSource = doc.hist.cust.early_season + ' Customer Price ' + doc.hist.cust.early_price;
|
||||||
// finalReason = `${doc.anchorSource} ${doc.anchorPrice} x ${inflationFactor} = ${calcPrice}`;
|
}
|
||||||
//}
|
} else {
|
||||||
//doc.finalReason = finalReason;
|
doc.anchorPrice = null;
|
||||||
|
doc.anchorSource = 'none'; // or any other default value you wish to indicate no anchor price was found
|
||||||
|
}
|
||||||
|
|
||||||
|
const inflation = Math.max(...Object.keys(doc.iidx).map(Number));
|
||||||
|
const inflationFactor = doc.iidx[inflation] + 1;
|
||||||
|
doc.inflationFactor = inflationFactor;
|
||||||
|
var calcPrice = doc.anchorPrice * doc.inflationFactor;
|
||||||
|
calcPrice = parseFloat(calcPrice.toFixed(5));
|
||||||
|
let finalReason = "";
|
||||||
|
if (calcPrice >= doc.list) {
|
||||||
|
doc.calcCeiling = "Cap At List";
|
||||||
|
doc.finalPrice = doc.list;
|
||||||
|
finalReason = `${doc.anchorSource} ${doc.anchorPrice} x ${inflationFactor} = ${calcPrice} but cap at list ${doc.list}`;
|
||||||
|
} else {
|
||||||
|
doc.finalPrice = calcPrice;
|
||||||
|
finalReason = `${doc.anchorSource} ${doc.anchorPrice} x ${inflationFactor} = ${calcPrice}`;
|
||||||
|
}
|
||||||
|
doc.finalReason = finalReason;
|
||||||
|
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user