From a0e9814a30346c56218d17bb4372f8b0a5f14c99 Mon Sep 17 00:00:00 2001 From: Gabriel Saillard Date: Wed, 24 Feb 2021 16:15:31 +0100 Subject: [PATCH] fix: NaN values for memory and cpu usage in toplist #1052 --- src/classes/toplist.class.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/classes/toplist.class.js b/src/classes/toplist.class.js index cfbf4af..cc381fe 100644 --- a/src/classes/toplist.class.js +++ b/src/classes/toplist.class.js @@ -25,8 +25,8 @@ class Toplist { }).filter((e, index, a) => { let i = a.findIndex(x => x.name === e.name); if (i !== -1 && i !== index) { - a[i].pcpu = a[i].pcpu+e.pcpu; - a[i].pmem = a[i].pmem+e.pmem; + a[i].cpu = a[i].cpu+e.cpu; + a[i].mem = a[i].mem+e.mem; return false; } return true; @@ -34,7 +34,7 @@ class Toplist { } let list = data.list.sort((a, b) => { - return ((b.pcpu-a.pcpu)*100 + b.pmem-a.pmem); + return ((b.cpu-a.cpu)*100 + b.mem-a.mem); }).splice(0, 5); document.querySelectorAll("#mod_toplist_table > tr").forEach(el => { @@ -44,8 +44,8 @@ class Toplist { let el = document.createElement("tr"); el.innerHTML = `${proc.pid} ${proc.name} - ${Math.round(proc.pcpu*10)/10}% - ${Math.round(proc.pmem*10)/10}%`; + ${Math.round(proc.cpu*10)/10}% + ${Math.round(proc.mem*10)/10}%`; document.getElementById("mod_toplist_table").append(el); }); }); @@ -98,8 +98,8 @@ class Toplist { }).filter((e, index, a) => { let i = a.findIndex(x => x.name === e.name); if (i !== -1 && i !== index) { - a[i].pcpu = a[i].pcpu + e.pcpu; - a[i].pmem = a[i].pmem + e.pmem; + a[i].cpu = a[i].cpu + e.cpu; + a[i].mem = a[i].mem + e.mem; return false; } return true; @@ -138,11 +138,11 @@ class Toplist { return 0; } case "CPU": - if (ascending) return a.pcpu - b.pcpu; - else return b.pcpu - a.pcpu; + if (ascending) return a.cpu - b.cpu; + else return b.cpu - a.cpu; case "Memory": - if (ascending) return a.pmem - b.pmem; - else return b.pmem - a.pmem; + if (ascending) return a.mem - b.mem; + else return b.mem - a.mem; case "State": if (a.state < b.state) return -1; if (a.state > b.state) return 1; @@ -155,10 +155,10 @@ class Toplist { else return b.runtime - a.runtime; default: // default to the same sorting as the toplist - return ((b.pcpu - a.pcpu) * 100 + b.pmem - a.pmem); + return ((b.cpu - a.cpu) * 100 + b.mem - a.mem); } }); - + if (removed) clearInterval(updateInterval); else { document.querySelectorAll("#processList > tr").forEach(el => { @@ -170,8 +170,8 @@ class Toplist { el.innerHTML = `${proc.pid} ${proc.name} ${proc.user} - ${Math.round(proc.pcpu * 10) / 10}% - ${Math.round(proc.pmem * 10) / 10}% + ${Math.round(proc.cpu * 10) / 10}% + ${Math.round(proc.mem * 10) / 10}% ${proc.state} ${proc.started} ${formatRuntime(proc.runtime)}`; -- GitLab