Module: Omnizip::ETA

Defined in:
lib/omnizip/eta.rb,
lib/omnizip/eta/sample_history.rb,
lib/omnizip/eta/time_estimator.rb,
lib/omnizip/eta/rate_calculator.rb,
lib/omnizip/eta/moving_average_estimator.rb,
lib/omnizip/eta/exponential_smoothing_estimator.rb

Overview

ETA (Estimated Time to Arrival) calculation module.

This module provides time estimation capabilities for long-running operations. It tracks historical progress samples and uses various estimation strategies to predict completion time.

Examples:

Basic usage

estimator = Omnizip::ETA.create_estimator(:exponential_smoothing)
estimator.add_sample(bytes_processed: 1000, files_processed: 10)
# ... more samples ...
eta = estimator.estimate(remaining_bytes: 5000)
puts "ETA: #{eta.formatted}"

Defined Under Namespace

Classes: ExponentialSmoothingEstimator, MovingAverageEstimator, RateCalculator, SampleHistory, TimeEstimator

Class Method Summary collapse

Class Method Details

.create_estimator(strategy = :exponential_smoothing, **options) ⇒ TimeEstimator

Create a new time estimator

Parameters:

  • strategy (Symbol) (defaults to: :exponential_smoothing)

    Estimation strategy (:exponential_smoothing, :moving_average)

  • options (Hash)

    Strategy-specific options

Returns:



37
38
39
40
41
42
43
44
45
46
# File 'lib/omnizip/eta.rb', line 37

def self.create_estimator(strategy = :exponential_smoothing, **options)
  case strategy
  when :exponential_smoothing
    ExponentialSmoothingEstimator.new(**options)
  when :moving_average
    MovingAverageEstimator.new(**options)
  else
    raise ArgumentError, "Unknown estimation strategy: #{strategy}"
  end
end

.format_time(seconds) ⇒ String

Format seconds as human-readable time string

Parameters:

  • seconds (Float)

    Seconds to format

Returns:

  • (String)

    Formatted time (e.g., "2m 30s")



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/omnizip/eta.rb', line 52

def self.format_time(seconds)
  return "0s" if seconds <= 0
  return "" if seconds.infinite?

  hours = (seconds / 3600).floor
  minutes = ((seconds % 3600) / 60).floor
  secs = (seconds % 60).round

  parts = []
  parts << "#{hours}h" if hours.positive?
  parts << "#{minutes}m" if minutes.positive? || hours.positive?
  parts << "#{secs}s"

  parts.join(" ")
end