Add 24 hour observed growth

This commit is contained in:
Skylar Grant 2023-01-26 21:30:41 -05:00
parent f5daa186ac
commit a69bca9259
2 changed files with 31 additions and 23 deletions

View File

@ -198,9 +198,9 @@ const functions = {
const hist24hDifference = (leaderboardEntry.treeHeight - dayAgoTree.treeHeight).toFixed(1); const hist24hDifference = (leaderboardEntry.treeHeight - dayAgoTree.treeHeight).toFixed(1);
statusIndicator += `+${hist24hDifference}ft|` statusIndicator += `+${hist24hDifference}ft|`
// Get the watering time for this tree // Get the 24h watering time for this tree
const waterTime = parseFloat(functions.getWaterTime(leaderboardEntry.treeHeight)).toFixed(0); const totalWaterTime = await functions.timeToHeight(dayAgoTree.treeHeight, leaderboardEntry.treeHeight);
statusIndicator += `${waterTime} mins]\`\``; statusIndicator += `${totalWaterTime}]\`\``;
// Determine if this tree is the guild's tree // Determine if this tree is the guild's tree
if (leaderboardEntry.hasPin) { if (leaderboardEntry.hasPin) {
@ -216,7 +216,8 @@ const functions = {
} }
} }
// Build a string using the current leaderboard entry and the historic entry from 24 hours ago // Build a string using the current leaderboard entry and the historic entry from 24 hours ago
comparisonReplyString += ` ${statusIndicator}\n`; comparisonReplyString += `\n${statusIndicator}\n`;
if (process.env.isDev == 'true') comparisonReplyString += `Current Height: ${leaderboardEntry.treeHeight} 24h Ago Height: ${dayAgoTree.treeHeight}\n`;
} }
return comparisonReplyString; return comparisonReplyString;
} catch (err) { } catch (err) {
@ -311,26 +312,33 @@ const functions = {
}); });
}, },
getWaterTime(size) { getWaterTime(size) {
const seconds = Math.floor(Math.pow(size * 0.07 + 5, 1.1)); return Math.floor(Math.pow(size * 0.07 + 5, 1.1)); // Seconds
return (Math.floor((Math.pow(size * 0.07 + 5, 1.1))) / 60).toFixed(2);
}, },
timeToHeight(interaction, destHeight) { timeToHeight(beginHeight, destHeight) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
dbfn.getGuildInfo(interaction.guildId).then(res => { let time = 0;
let guildInfo = res.data; for (let i = beginHeight; i < destHeight; i++) {
let currentHeight = parseInt(guildInfo.treeHeight); const waterTime = parseFloat(functions.getWaterTime(i));
let time = 0; // console.log("Height: " + i + "Time: " + waterTime);
for (let i = currentHeight; i < destHeight; i++) { time += waterTime;
const waterTime = parseFloat(functions.getWaterTime(i)); }
console.log("Height: " + i + "Time: " + waterTime);
time += waterTime; // 60 secs in min
} // 3600 secs in hr
resolve(time.toFixed(2)); // 86400 sec in day
}).catch(err => {
console.error(err); let units = " secs";
reject(err); if ( 60 < time && time <= 3600 ) { // Minutes
return; time = parseFloat(time / 60).toFixed(1);
}) units = " mins";
} else if ( 3600 < time && time <= 86400 ) {
time = parseFloat(time / 3600).toFixed(1);
units = " hrs";
} else if ( 86400 < time ) {
time = parseFloat(time / 86400).toFixed(1);
units = " days";
}
resolve(time + units);
}); });
} }
}; };

View File

@ -1,6 +1,6 @@
{ {
"name": "silvanus", "name": "silvanus",
"version": "1.1.2", "version": "1.1.3",
"description": "Grow A Tree Comparison Tool", "description": "Grow A Tree Comparison Tool",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {