Last active
December 18, 2016 14:22
-
-
Save Fingercomp/cfe2cc63e547f5d004f76707053835f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local scale = 0.75 | |
local avgs = {} | |
local function calcAvg(last) | |
if #avgs == 0 then | |
table.insert(avgs, last) | |
return last | |
end | |
local len = #avgs | |
local sum = 0 | |
local div = 0 | |
for n, v in pairs(avgs) do | |
local s = 1/((len - n + 1)^scale) | |
sum = sum + s * v | |
div = div + s | |
end | |
local result = (last + sum) / (1 + div) | |
table.insert(avgs, result) | |
return result | |
end | |
local function calcSpeed(len, time) | |
return len / time | |
end | |
local function eta(avg, got, total) | |
return (total - got) / avg | |
end | |
local total = 100 | |
for i = 0, total, 10 do | |
local speed = calcSpeed(10, i / 10 + 1) | |
local avg = calcAvg(speed) | |
print("got: " .. ("%.5f"):format(i) .. | |
",\t total: " .. ("%.5f"):format(total) .. | |
",\t speed: " .. ("%.5f"):format(speed) .. | |
",\t avg: " .. ("%.5f"):format(avg) .. | |
",\t eta: " .. ("%.5f"):format(eta(avg, i, total))) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment