vault backup: 2023-11-06 13:58:27
This commit is contained in:
parent
55d950d010
commit
2651b40e45
29
api.ts
29
api.ts
@ -33,18 +33,25 @@ 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.");
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user