Skip to content

Instantly share code, notes, and snippets.

@arronmabrey
Last active November 21, 2023 04:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arronmabrey/95cab5541a152581a2944ba7efac8d71 to your computer and use it in GitHub Desktop.
Save arronmabrey/95cab5541a152581a2944ba7efac8d71 to your computer and use it in GitHub Desktop.
eta.rb
def eta mod, start_time, total_count, current_time, current_idx
current_count = current_idx + 1
if (current_idx % mod).zero? || current_count >= total_count
percent_done = ((current_count.to_f / total_count.to_f) * 100).round(2)
rem_count = total_count - current_count
run_sec = (current_time - start_time).to_i
avg_parse_time = run_sec.to_f / current_count.to_f
rem_sec = rem_count * avg_parse_time
eta_time = current_time + rem_sec
puts "Start: #{start_time} Current: #{current_time} Runtime: #{run_sec}s #{percent_done}% #{current_count}/#{total_count} rem: #{rem_count} apt: #{avg_parse_time.round(2)} ETA: #{eta_time}"
end
end
items = (1..100)
total_count = items.count
start_time = Time.zone.now
items.each_with_index.map do |id, idx|
eta(10, start_time, total_count, Time.zone.now, idx)
sleep rand(0.1..0.5)
[id, idx]
end
# Start: 2023-11-20 20:26:09 -0800 Current: 2023-11-20 20:26:10 -0800 Runtime: 0s 1.0% 1/100 rem: 99 apt: 0.0 ETA: 2023-11-20 20:26:10 -0800
# Start: 2023-11-20 20:26:09 -0800 Current: 2023-11-20 20:26:13 -0800 Runtime: 3s 11.0% 11/100 rem: 89 apt: 0.27 ETA: 2023-11-20 20:26:37 -0800
# Start: 2023-11-20 20:26:09 -0800 Current: 2023-11-20 20:26:17 -0800 Runtime: 7s 21.0% 21/100 rem: 79 apt: 0.33 ETA: 2023-11-20 20:26:43 -0800
# Start: 2023-11-20 20:26:09 -0800 Current: 2023-11-20 20:26:19 -0800 Runtime: 10s 31.0% 31/100 rem: 69 apt: 0.32 ETA: 2023-11-20 20:26:42 -0800
# Start: 2023-11-20 20:26:09 -0800 Current: 2023-11-20 20:26:22 -0800 Runtime: 12s 41.0% 41/100 rem: 59 apt: 0.29 ETA: 2023-11-20 20:26:39 -0800
# Start: 2023-11-20 20:26:09 -0800 Current: 2023-11-20 20:26:24 -0800 Runtime: 14s 51.0% 51/100 rem: 49 apt: 0.27 ETA: 2023-11-20 20:26:38 -0800
# Start: 2023-11-20 20:26:09 -0800 Current: 2023-11-20 20:26:27 -0800 Runtime: 17s 61.0% 61/100 rem: 39 apt: 0.28 ETA: 2023-11-20 20:26:38 -0800
# Start: 2023-11-20 20:26:09 -0800 Current: 2023-11-20 20:26:30 -0800 Runtime: 20s 71.0% 71/100 rem: 29 apt: 0.28 ETA: 2023-11-20 20:26:38 -0800
# Start: 2023-11-20 20:26:09 -0800 Current: 2023-11-20 20:26:34 -0800 Runtime: 24s 81.0% 81/100 rem: 19 apt: 0.3 ETA: 2023-11-20 20:26:39 -0800
# Start: 2023-11-20 20:26:09 -0800 Current: 2023-11-20 20:26:37 -0800 Runtime: 27s 91.0% 91/100 rem: 9 apt: 0.3 ETA: 2023-11-20 20:26:39 -0800
# Start: 2023-11-20 20:26:09 -0800 Current: 2023-11-20 20:26:39 -0800 Runtime: 29s 100.0% 100/100 rem: 0 apt: 0.29 ETA: 2023-11-20 20:26:39 -0800
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment