Add ETA to //many, and tidy up message generation in //subdivide

This commit is contained in:
Starbeamrainbowlabs 2020-10-10 17:01:08 +01:00
parent 4367b4bc70
commit ef165b9c58
No known key found for this signature in database
GPG Key ID: 1BE5172E637709C2
4 changed files with 32 additions and 9 deletions

@ -5,6 +5,7 @@ It's about time I started a changelog! This will serve from now on as the master
## v1.10 (unreleased) ## v1.10 (unreleased)
- `//maze`: Fix some parts of generated mazes staying solid - `//maze`: Fix some parts of generated mazes staying solid
- `//maze`, `//maze3d`: Allow non-number seeds (existing seeds aren't affected - they will still produce identical output) - `//maze`, `//maze3d`: Allow non-number seeds (existing seeds aren't affected - they will still produce identical output)
- `//many`: Improve format of progress messages, add ETA
## v1.9: The Nature Update (20th September 2020) ## v1.9: The Nature Update (20th September 2020)

@ -25,3 +25,10 @@ end
function worldeditadditions.get_ms_time() function worldeditadditions.get_ms_time()
return minetest.get_us_time() / 1000 return minetest.get_us_time() / 1000
end end
function worldeditadditions.eta(existing_times, times_total_count)
local average = worldeditadditions.average(existing_times)
local times_left = times_total_count - #existing_times
if times_left == 0 then return 0 end
return average * times_left
end

@ -35,7 +35,14 @@ local function step(params)
local start_time = worldeditadditions.get_ms_time() local start_time = worldeditadditions.get_ms_time()
local full_cmd = params.cmd_name.." "..params.args local full_cmd = params.cmd_name.." "..params.args
worldedit.player_notify(params.name, "[ many ] [ /"..full_cmd.." ] "..(params.i + 1).." / "..params.count.." (~"..worldeditadditions.round(((params.i + 1) / params.count)*100, 2).."%)") worldedit.player_notify(params.name, string.format("[ many | /%s ] %d / %d (~%.2f%%) complete | last: %s, average: %s, ETA: ~%s",
full_cmd,
(params.i + 1), params.count,
((params.i + 1) / params.count)*100,
worldeditadditions.human_time(params.times[#params.times] or 0),
worldeditadditions.human_time(worldeditadditions.average(params.times)),
worldeditadditions.human_time(worldeditadditions.eta(params.times, params.count))
))
local cmd = minetest.chatcommands[params.cmd_name] local cmd = minetest.chatcommands[params.cmd_name]
@ -43,7 +50,7 @@ local function step(params)
cmd.func(params.name, params.args) cmd.func(params.name, params.args)
params.times[#params.times + 1] = (worldeditadditions.get_ms_time() - start_time) table.insert(params.times, worldeditadditions.get_ms_time() - start_time)
params.i = params.i + 1 params.i = params.i + 1
if params.i < params.count then if params.i < params.count then
@ -52,7 +59,7 @@ local function step(params)
local total_time = (worldeditadditions.get_ms_time() - params.master_start_time) local total_time = (worldeditadditions.get_ms_time() - params.master_start_time)
local done_message = {} local done_message = {}
table.insert(done_message, table.insert(done_message,
string.format("Executed '"..full_cmd.."' %d times in %s (~%s / time", string.format("Executed '"..full_cmd.."' %d times in %s (~%s / time)",
#params.times, #params.times,
worldeditadditions.human_time(total_time), worldeditadditions.human_time(total_time),
worldeditadditions.human_time( worldeditadditions.human_time(

@ -136,14 +136,22 @@ worldedit.register_command("subdivide", {
-- print("eta", eta, "time_average", time_average, "chunks_left", chunks_total - i) -- print("eta", eta, "time_average", time_average, "chunks_left", chunks_total - i)
-- Send updates every 2 seconds, and after the first 3 chunks are done -- Send updates every 2 seconds, and after the first 3 chunks are done
print("[DEBUG]",
i, chunks_total,
(i / chunks_total) * 100,
wea.human_time(time_this),
wea.human_time(time_average),
"eta", eta, "[human]", wea.human_time(eta), "end")
if worldeditadditions.get_ms_time() - time_last_msg > 2 * 1000 or i == 3 or i == chunks_total then if worldeditadditions.get_ms_time() - time_last_msg > 2 * 1000 or i == 3 or i == chunks_total then
worldedit.player_notify(name, worldedit.player_notify(name,
msg_prefix string.format("%s%d / %d (~%.2f%%) complete | last chunk: %s, average: %s, ETA: ~%s",
..i.." / "..chunks_total.." (~" msg_prefix,
..string.format("%.2f", (i / chunks_total) * 100).."%) complete | " i, chunks_total,
.."last chunk: "..wea.human_time(time_this) (i / chunks_total) * 100,
..", average: "..wea.human_time(time_average) wea.human_time(time_this),
..", ETA: ~"..wea.human_time(eta) wea.human_time(time_average),
wea.human_time(eta)
)
) )
time_last_msg = worldeditadditions.get_ms_time() time_last_msg = worldeditadditions.get_ms_time()
end end