vault backup: 2023-11-07 08:54:12
This commit is contained in:
parent
24c3a20d67
commit
28c5bd5c03
49
api.ts
49
api.ts
@ -33,8 +33,10 @@ 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 mostRelevantMarketPriceEarly = null;
|
||||||
let mostRelevantMarketKey = null;
|
let mostRelevantMarketKey = null;
|
||||||
let mostRelevantMarketSeason = null;
|
let mostRelevantMarketSeason = null;
|
||||||
|
let mostRelevantMarketSeasonEarly = null;
|
||||||
let highestMarketRelevanceLevel = -1;
|
let highestMarketRelevanceLevel = -1;
|
||||||
|
|
||||||
let mostRelevantCustomerPriceEarly = null;
|
let mostRelevantCustomerPriceEarly = null;
|
||||||
@ -74,9 +76,10 @@ function apply_guidance(doc: any) {
|
|||||||
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 ? 2 : 1
|
customerRelevance = item.cust ? 2 : 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 ? 1 : 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,8 +92,10 @@ function apply_guidance(doc: any) {
|
|||||||
if (marketRelevance > highestMarketRelevanceLevel) {
|
if (marketRelevance > highestMarketRelevanceLevel) {
|
||||||
highestMarketRelevanceLevel = marketRelevance;
|
highestMarketRelevanceLevel = marketRelevance;
|
||||||
mostRelevantMarketPrice = item.last_price;
|
mostRelevantMarketPrice = item.last_price;
|
||||||
|
mostRelevantMarketPriceEarly = item.early_price;
|
||||||
mostRelevantMarketKey = histKey;
|
mostRelevantMarketKey = histKey;
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
@ -107,41 +112,43 @@ function apply_guidance(doc: any) {
|
|||||||
|
|
||||||
// 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)) {
|
||||||
// Update price and relevance for each item in the current key
|
// Update price and relevance for each item in the current key
|
||||||
setAnchors(doc.hist[key], doc.chan[0], doc.v1ds, doc.v0ds, key);
|
setAnchors(doc.hist[key], doc.chan[0], doc.v1ds, doc.v0ds, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign the most relevant market price and key to the top level of the document
|
// Assign the most relevant market price and key to the top level of the document
|
||||||
if (mostRelevantMarketPrice !== null) {
|
if (mostRelevantMarketPrice !== null) {
|
||||||
doc.mostRelevantMarketPriceInfo = {
|
doc.mostRelevantMarketPriceInfo = {
|
||||||
price: mostRelevantMarketPrice,
|
price: mostRelevantMarketPrice,
|
||||||
histKey: mostRelevantMarketKey,
|
price_early: mostRelevantMarketPriceEarly,
|
||||||
season: mostRelevantMarketSeason
|
histKey: mostRelevantMarketKey,
|
||||||
};
|
season: mostRelevantMarketSeason,
|
||||||
|
season_early: mostRelevantMarketSeasonEarly
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 (mostRelevantCustomerPriceRecent !== null) {
|
if (mostRelevantCustomerPriceRecent !== null) {
|
||||||
doc.mostRelevantCustomerPriceInfo = {
|
doc.mostRelevantCustomerPriceInfo = {
|
||||||
price: mostRelevantCustomerPriceRecent,
|
price: mostRelevantCustomerPriceRecent,
|
||||||
price_early: mostRelevantCustomerPriceEarly,
|
price_early: mostRelevantCustomerPriceEarly,
|
||||||
histKey: mostRelevantCustomerKey,
|
histKey: mostRelevantCustomerKey,
|
||||||
season: mostRelevantCustomerSeasonRecent,
|
season: mostRelevantCustomerSeasonRecent,
|
||||||
season_early: mostRelevantCustomerSeasonEarly
|
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 && (mostRelevantCustomerPriceEarly === undefined || doc.targetPrice < mostRelevantCustomerPriceEarly)) {
|
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 (mostRelevantCustomerPriceEarly !== undefined) {
|
} else if (mostRelevantCustomerPriceEarly !== undefined) {
|
||||||
doc.anchorPrice = mostRelevantCustomerPriceEarly;
|
doc.anchorPrice = mostRelevantCustomerPriceEarly;
|
||||||
doc.anchorSource = mostRelevantCustomerSeasonEarly + ' 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
|
||||||
}
|
}
|
||||||
|
|
||||||
const inflation = Math.max(...Object.keys(doc.iidx).map(Number));
|
const inflation = Math.max(...Object.keys(doc.iidx).map(Number));
|
||||||
|
Loading…
Reference in New Issue
Block a user