From cec48533afc0cc7eb2947df583168af30dc40448 Mon Sep 17 00:00:00 2001 From: onefang Date: Thu, 2 Jan 2020 14:45:42 +1000 Subject: Curl uses k and M to mean 1024, not 1000. --- apt-panopticon.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apt-panopticon.lua b/apt-panopticon.lua index 8f953d0..ea964ec 100755 --- a/apt-panopticon.lua +++ b/apt-panopticon.lua @@ -957,11 +957,13 @@ os.execute('sleep 1') -- Wait for things to start up before checking for them. for l in io.lines(f) do local speed, crrnt = l:match('^%c *'..num..' +'..num..' +%d+ +'..num..' +%d+ +%d+ +('..num..') +%d+ +[%d%-]+:[%d%-]+:[%d%-]+ +[%d%-]+:[%d%-]+:[%d%-]+ +[%d%-]+:[%d%-]+:[%d%-]+ +('..num..')') if nil ~= speed then - if 'k' == speed:sub(-1, -1) then speed = speed:sub(1, -2) .. '000' end - if 'k' == crrnt:sub(-1, -1) then crrnt = crrnt:sub(1, -2) .. '000' end - if 'M' == speed:sub(-1, -1) then speed = speed:sub(1, -2) .. '000000' end - if 'M' == crrnt:sub(-1, -1) then crrnt = crrnt:sub(1, -2) .. '000000' end + if 'k' == speed:sub(-1, -1) then speed = tonumber(speed:sub(1, -2)) * 1024 + elseif 'M' == speed:sub(-1, -1) then speed = tonumber(speed:sub(1, -2)) * 1024 * 1024 + end speed = tonumber(speed) + if 'k' == crrnt:sub(-1, -1) then crrnt = tonumber(crrnt:sub(1, -2)) * 1024 + elseif 'M' == crrnt:sub(-1, -1) then crrnt = tonumber(crrnt:sub(1, -2)) * 1024 * 1024 + end crrnt = tonumber(crrnt) if speed < min and speed ~= 0 then min = speed end if speed > max then max = speed end -- cgit v1.1