diff --git a/config.json b/config.json index f28590d..faa5dcb 100644 --- a/config.json +++ b/config.json @@ -4,8 +4,8 @@ "ip": "0.0.0.0" }, "rates": { - "pingAll": 15000, - "connectTimeout": 10000 + "pingAll": 30000, + "connectTimeout": 5000 }, "oldPingsCleanup": { "enabled": false, @@ -13,6 +13,6 @@ }, "logFailedPings": true, "logToDatabase": true, - "graphDuration": 86400000, - "serverGraphDuration": 180000 + "graphDuration": 604800000, + "serverGraphDuration": 360000 } diff --git a/lib/app.js b/lib/app.js index 3bba5eb..5f02a01 100644 --- a/lib/app.js +++ b/lib/app.js @@ -6,6 +6,7 @@ const MessageOf = require("./message"); const config = require("../config"); const minecraftVersions = require("../minecraft_versions"); +const { formatMsToTime } = require("./utils/timeUtils"); class App { serverRegistrations = []; @@ -74,9 +75,11 @@ class App { // Send configuration data for rendering the page return { + // graphDurationLabel: + // config.graphDurationLabel || + // Math.floor(config.graphDuration / (60 * 60 * 1000)) + "h", graphDurationLabel: - config.graphDurationLabel || - Math.floor(config.graphDuration / (60 * 60 * 1000)) + "h", + config.graphDurationLabel || formatMsToTime(config.graphDuration), graphMaxLength: TimeTracker.getMaxGraphDataLength(), serverGraphMaxLength: TimeTracker.getMaxServerGraphDataLength(), servers: this.serverRegistrations.map((serverRegistration) => diff --git a/lib/utils/timeUtils.js b/lib/utils/timeUtils.js new file mode 100644 index 0000000..0dcaf8d --- /dev/null +++ b/lib/utils/timeUtils.js @@ -0,0 +1,28 @@ +/** + * Formats a time in milliseconds to a human readable format + * eg: 1000ms -> 1s or 60000ms -> 1m + * + * @param ms the time in milliseconds + * @returns the formatted time + */ +function formatMsToTime(ms) { + // this is really fucking shitty but it works! + const seconds = Math.floor(ms / 1000); + const minutes = Math.floor(seconds / 60); + const hours = Math.floor(minutes / 60); + const days = Math.floor(hours / 24); + + if (days > 0) { + return `${days}d`; + } else if (hours > 0) { + return `${hours}h`; + } else if (minutes > 0) { + return `${minutes}m`; + } else { + return `${seconds}s`; + } +} + +module.exports = { + formatMsToTime, +};