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.
Defined Under Namespace
Classes: ExponentialSmoothingEstimator, MovingAverageEstimator, RateCalculator, SampleHistory, TimeEstimator
Class Method Summary collapse
-
.create_estimator(strategy = :exponential_smoothing, **options) ⇒ TimeEstimator
Create a new time estimator.
-
.format_time(seconds) ⇒ String
Format seconds as human-readable time string.
Class Method Details
.create_estimator(strategy = :exponential_smoothing, **options) ⇒ TimeEstimator
Create a new time estimator
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/omnizip/eta.rb', line 37 def self.create_estimator(strategy = :exponential_smoothing, **) case strategy when :exponential_smoothing ExponentialSmoothingEstimator.new(**) when :moving_average MovingAverageEstimator.new(**) else raise ArgumentError, "Unknown estimation strategy: #{strategy}" end end |
.format_time(seconds) ⇒ String
Format seconds as human-readable time string
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 |