Skip to content

Instantly share code, notes, and snippets.

@Fingercomp

Fingercomp/eta.lua

Last active Dec 18, 2016
Embed
What would you like to do?
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