2020-05-11 03:02:02 +02:00
|
|
|
-- From http://lua-users.org/wiki/SimpleRound
|
2020-05-12 01:38:42 +02:00
|
|
|
function worldeditadditions.round(num, numDecimalPlaces)
|
2020-05-11 03:02:02 +02:00
|
|
|
local mult = 10^(numDecimalPlaces or 0)
|
|
|
|
return math.floor(num * mult + 0.5) / mult
|
|
|
|
end
|
2020-06-09 02:21:32 +02:00
|
|
|
|
|
|
|
function worldeditadditions.hypotenuse(x1, y1, x2, y2)
|
|
|
|
local xSquare = math.pow(x1 - x2, 2);
|
|
|
|
local ySquare = math.pow(y1 - y2, 2);
|
|
|
|
return math.sqrt(xSquare + ySquare);
|
|
|
|
end
|
2020-06-26 21:46:35 +02:00
|
|
|
|
2020-10-10 22:43:22 +02:00
|
|
|
function worldeditadditions.sum(list)
|
|
|
|
if #list == 0 then return 0 end
|
2020-06-26 21:46:35 +02:00
|
|
|
local sum = 0
|
|
|
|
for i,value in ipairs(list) do
|
|
|
|
sum = sum + value
|
|
|
|
end
|
2020-10-10 22:43:22 +02:00
|
|
|
return sum
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function worldeditadditions.average(list)
|
|
|
|
if #list == 0 then return 0 end
|
|
|
|
return worldeditadditions.sum(list) / #list
|
2020-06-26 21:46:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Returns the minetest.get_us_time() in ms
|
|
|
|
-- @return float
|
|
|
|
function worldeditadditions.get_ms_time()
|
|
|
|
return minetest.get_us_time() / 1000
|
|
|
|
end
|
2020-10-10 18:01:08 +02:00
|
|
|
|
2021-02-07 03:45:34 +01:00
|
|
|
function worldeditadditions.eta(existing_times, done_count, total_count)
|
2021-02-07 02:37:50 +01:00
|
|
|
local max = 100
|
2021-02-03 04:04:33 +01:00
|
|
|
local average = worldeditadditions.average(
|
2021-02-07 02:37:50 +01:00
|
|
|
worldeditadditions.table_get_last(existing_times, max)
|
2021-02-03 04:04:33 +01:00
|
|
|
)
|
2021-02-07 03:45:34 +01:00
|
|
|
local times_left = total_count - done_count
|
2020-10-10 18:01:08 +02:00
|
|
|
if times_left == 0 then return 0 end
|
|
|
|
return average * times_left
|
|
|
|
end
|