Skip to content

Commit

Permalink
Fix percentage calculation (#70)
Browse files Browse the repository at this point in the history
* Fix percentage calculation
m is in Mbits/s, v is in bytes/s
m was getting converted to bytes/s when useBits was false, however, it wasn't when useBits was true, meaning all percentages were 1/8th what they should be

* Update details.js
  • Loading branch information
Quphoria authored Oct 29, 2023
1 parent e7f3486 commit 558e198
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ function displayTable(tb, settings) {
progressbar('upstream', cachedData[1][1], settings.upstream, settings.useBits, settings.useMultiple);
}

function formatBandWidth(bdw, useBits) {
return bdw * Math.pow(1000, 2) / (useBits ? 1 : 8);
}

function formatSize(size, useBits, useMultiple) {
var res = String.format('%%%s.2m%s'.format(useMultiple, (useBits ? 'bit' : 'B')), useBits ? size * 8 : size);
return useMultiple == '1024' ? res.replace(/([KMGTPEZ])/, '$&i') : res;
Expand Down Expand Up @@ -277,9 +273,10 @@ function parseDefaultSettings(file) {
}

function progressbar(query, v, m, useBits, useMultiple) {
// v = B/s, m = Mb/s
var pg = $(query),
vn = v || 0,
mn = formatBandWidth(m, useBits) || 100,
vn = (v * 8) || 0,
mn = (m || 100) * Math.pow(1000, 2),
fv = formatSpeed(v, useBits, useMultiple),
pc = '%.2f'.format((100 / mn) * vn),
wt = Math.floor(pc > 100 ? 100 : pc),
Expand Down

0 comments on commit 558e198

Please sign in to comment.