From 9b9e4471bfa052cd154b5218304d3eb4cae5ae1d Mon Sep 17 00:00:00 2001 From: Harry Phillips Date: Fri, 12 Jul 2019 10:29:31 +0100 Subject: [PATCH] Better formatting --- src/main/resources/html/index.html | 2 +- src/main/resources/html/js/index.js | 39 ++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/main/resources/html/index.html b/src/main/resources/html/index.html index d281c6cb..c25d84e3 100644 --- a/src/main/resources/html/index.html +++ b/src/main/resources/html/index.html @@ -2,7 +2,7 @@ - {TITLE>>> + {TITLE} diff --git a/src/main/resources/html/js/index.js b/src/main/resources/html/js/index.js index e99f5240..65fc64f3 100644 --- a/src/main/resources/html/js/index.js +++ b/src/main/resources/html/js/index.js @@ -49,17 +49,32 @@ function escapeHtml(string) { let chart = null; +function filterTimePart(part, suffix) { + if (part === 0) { + part = null; + } else { + part = part.toString() + suffix; + } + return part; +} + function formatTime(secs) { - const sec_num = parseInt(secs, 10); - const hours = Math.floor(sec_num / 3600); - const minutes = Math.floor(sec_num / 60) % 60; - let seconds; - seconds = sec_num % 60; - - return [hours,minutes,seconds] - .map(v => v < 10 ? "0" + v : v) - .filter((v,i) => v !== "00" || i > 0) - .join(":") + secs = parseInt(secs, 10); + if (secs === null || secs < 0) return ""; + if (secs === 0) return "0s"; + let years = filterTimePart(Math.floor(secs / 3600 / 24 / 365), "y"); + let days = filterTimePart(Math.floor((secs / 3600 / 24) % 365), "d"); + let hours = filterTimePart(Math.floor((secs / 3600) % 24), "h"); + let minutes = filterTimePart(Math.floor(secs / 60) % 60, "m"); + let seconds = filterTimePart(secs % 60, "s"); + + let result = ""; + if (years !== null) result += " " + years; + if (days !== null) result += " " + days; + if (hours !== null) result += " " + hours; + if (minutes !== null) result += " " + minutes; + if (seconds !== null) result += " " + seconds; + return result.substr(1); } function formatBaseTarget(baseTarget) { @@ -70,11 +85,11 @@ function getPoolInfo() { fetch("/api/getConfig").then(http => { return http.json(); }).then(response => { + maxSubmissions = response.nAvg + response.processLag; document.getElementById("poolName").innerText = response.poolName; document.getElementById("poolAccount").innerHTML = formatMinerName(response.poolAccountRS, response.poolAccount, response.poolAccount, true); document.getElementById("nAvg").innerText = response.nAvg; document.getElementById("nMin").innerText = response.nMin; - maxSubmissions = response.nAvg + response.processLag; document.getElementById("maxDeadline").innerText = response.maxDeadline; document.getElementById("processLag").innerText = response.processLag + " Blocks"; document.getElementById("feeRecipient").innerText = response.feeRecipientRS; @@ -180,7 +195,7 @@ function getMiners() { return http.json(); }).then(response => { let table = document.getElementById("miners"); - table.innerHTML = "MinerCurrent DeadlinePending BalanceEffective CapacitynConf (Last (nAvg + processLag) rounds)ShareSoftware"; + table.innerHTML = "MinerCurrent DeadlinePending BalanceEffective CapacityConfirmed DeadlinesShareSoftware"; for (let i = 0; i < response.miners.length; i++) { let miner = response.miners[i]; let currentRoundDeadline = miner.currentRoundBestDeadline == null ? "" : formatTime(miner.currentRoundBestDeadline);