vault backup: 2023-11-06 13:58:27

This commit is contained in:
Paul Trowbridge 2023-11-06 13:58:28 -05:00
parent 55d950d010
commit 2651b40e45
1 changed files with 19 additions and 12 deletions

31
api.ts
View File

@ -32,19 +32,26 @@ await client.connect();
const query = await Deno.readTextFile("sql/get.pg.sql");
function apply_guidance(doc: any) {
if (doc["hist"]["chan.mold.v0ds.vers"] && Array.isArray(doc["hist"]["chan.mold.v0ds.vers"])) {
// Loop through each element in the 'chan.mold.v0ds.vers' array
for (const element of doc["hist"]["chan.mold.v0ds.vers"]) {
// Process each element - 'element' is of type SeasonData
console.log(element); // Replace with actual processing logic
}
} else {
// Handle the case where 'chan.mold.v0ds.vers' is not an array or doesn't exist
console.error("'chan.mold.v0ds.vers' is not an array or does not exist in the document.");
}
return doc;
// Iterate over each key in the "hist" object
for (let key of Object.keys(doc.hist)) {
// Update each item in the current key with the most recent price
updateWithMostRecentPrice(doc.hist[key]);
}
return doc;
}
// Function to update each item with the most recent price
function updateWithMostRecentPrice(items) {
for (let item of items) {
// Find the most recent price
//const lastPrice = findMostRecentPrice(item.season);
const years = Object.keys(item.season);
const recentYear = Math.max(...years);
const lastPrice = item.season[recentYear].price_usd;
// Append the last_price to the item
item.last_price = lastPrice;
}
}
// Define a route to retrieve values from the database using parameters