mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-30 19:13:53 +01:00
38e5c81d33
- Don't use wea.sum() on a table full of all the times we've recorded so far - Limit individual stats list lengths to 25 to avoid memory issues when running with a large number of chunks - Tally total times / metrics as we go to avoid memory issues
44 lines
1.2 KiB
Lua
44 lines
1.2 KiB
Lua
-- From http://lua-users.org/wiki/SimpleRound
|
|
function worldeditadditions.round(num, numDecimalPlaces)
|
|
local mult = 10^(numDecimalPlaces or 0)
|
|
return math.floor(num * mult + 0.5) / mult
|
|
end
|
|
|
|
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
|
|
|
|
function worldeditadditions.sum(list)
|
|
if #list == 0 then return 0 end
|
|
local sum = 0
|
|
for i,value in ipairs(list) do
|
|
sum = sum + value
|
|
end
|
|
return sum
|
|
end
|
|
|
|
|
|
function worldeditadditions.average(list)
|
|
print("[DEBUG] averaging "..#list.." numbers")
|
|
if #list == 0 then return 0 end
|
|
return worldeditadditions.sum(list) / #list
|
|
end
|
|
|
|
--- Returns the minetest.get_us_time() in ms
|
|
-- @return float
|
|
function worldeditadditions.get_ms_time()
|
|
return minetest.get_us_time() / 1000
|
|
end
|
|
|
|
function worldeditadditions.eta(existing_times, times_total_count)
|
|
print("[DEBUG] eta got "..#existing_times.." numbers")
|
|
local average = worldeditadditions.average(
|
|
worldeditadditions.table_get_last(existing_times, 25)
|
|
)
|
|
local times_left = times_total_count - #existing_times
|
|
if times_left == 0 then return 0 end
|
|
return average * times_left
|
|
end
|