vault backup: 2023-11-06 15:03:33

This commit is contained in:
Paul Trowbridge 2023-11-06 15:03:33 -05:00
parent dbac08f9f3
commit cd7056c502
1 changed files with 43 additions and 19 deletions

62
api.ts
View File

@ -32,9 +32,13 @@ await client.connect();
const query = await Deno.readTextFile("sql/get.pg.sql");
function apply_guidance(doc: any) {
let mostRelevantPrice = null;
let mostRelevantKey = null;
let highestRelevanceLevel = -1; // Assume -1 is less than any relevance level
let mostRelevantMarketPrice = null;
let mostRelevantMarketKey = null;
let highestMarketRelevanceLevel = -1;
let mostRelevantCustomerPrice = null;
let mostRelevantCustomerKey = null;
let highestCustomerRelevanceLevel = -1;
// Function to update price and assign relevance indicator
function updatePriceAndAssignRelevance(items, channelFirstChar, v1ds, v0ds, histKey) {
@ -50,28 +54,40 @@ function apply_guidance(doc: any) {
}
// Initialize relevance as numeric value
let relevance = 0; // Assume 0 is 'not relevant'
let marketRelevance = 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
if (item.chan.charAt(0) === channelFirstChar) {
relevance = 1; // 'relevant'
marketRelevance = 1; // 'relevant'
// Further refine relevance based on v1ds and v0ds
if (item.v1ds === v1ds) {
relevance = 2; // 'most relevant' because v1ds matches
marketRelevance = 2; // 'most relevant' because v1ds matches
// Check for customer relevance if 'cust' key exists
customerRelevance = item.cust ? 2 : 1
} else if (item.v0ds === v0ds) {
relevance = relevance === 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'
}
}
// Assign the calculated relevance to the item
item.relevance = relevance;
// Update the most relevant price if this item's relevance is higher
if (relevance > highestRelevanceLevel) {
highestRelevanceLevel = relevance;
mostRelevantPrice = item.last_price;
mostRelevantKey = histKey;
// Assign the calculated relevance to the item
item.marketRelevance = marketRelevance;
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)) {
highestMarketRelevanceLevel = marketRelevance;
mostRelevantMarketPrice = item.last_price;
mostRelevantMarketKey = histKey;
}
// 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) {
highestCustomerRelevanceLevel = customerRelevance;
mostRelevantCustomerPrice = item.last_price;
mostRelevantCustomerKey = histKey;
}
}
}
@ -82,11 +98,19 @@ function apply_guidance(doc: any) {
updatePriceAndAssignRelevance(doc.hist[key], doc.chan[0], doc.v1ds, doc.v0ds, key);
}
// Assign the most relevant price and key to the top level of the document
if (mostRelevantPrice !== null) {
doc.mostRelevantPriceInfo = {
price: mostRelevantPrice,
histKey: mostRelevantKey
// Assign the most relevant market price and key to the top level of the document
if (mostRelevantMarketPrice !== null) {
doc.mostRelevantMarketPriceInfo = {
price: mostRelevantMarketPrice,
histKey: mostRelevantMarketKey
};
}
// Assign the most relevant customer price and key to the top level of the document
if (mostRelevantCustomerPrice !== null) {
doc.mostRelevantCustomerPriceInfo = {
price: mostRelevantCustomerPrice,
histKey: mostRelevantCustomerKey
};
}