Class: Omnizip::ETA::ExponentialSmoothingEstimator
- Inherits:
-
TimeEstimator
- Object
- TimeEstimator
- Omnizip::ETA::ExponentialSmoothingEstimator
- Defined in:
- lib/omnizip/eta/exponential_smoothing_estimator.rb
Overview
ETA estimator using exponential smoothing.
This estimator uses exponential smoothing to give more weight to recent samples while still considering historical data. This provides a good balance between responsiveness and stability.
The smoothing factor (alpha) determines how much weight to give to new samples: 0.0 = ignore new data, 1.0 = only use new data.
Instance Attribute Summary collapse
-
#smoothed_rate ⇒ Object
readonly
Returns the value of attribute smoothed_rate.
-
#smoothing_factor ⇒ Object
readonly
Returns the value of attribute smoothing_factor.
Attributes inherited from TimeEstimator
#rate_calculator, #sample_history
Instance Method Summary collapse
-
#estimate(remaining_bytes) ⇒ Models::ETAResult
Estimate time remaining using exponential smoothing.
-
#initialize(smoothing_factor: 0.3, **options) ⇒ ExponentialSmoothingEstimator
constructor
Initialize a new exponential smoothing estimator.
-
#reset ⇒ Object
Reset smoothed rate (e.g., when operation changes significantly).
Methods inherited from TimeEstimator
#add_sample, #confidence_interval, #format_time, #sufficient_samples?
Constructor Details
#initialize(smoothing_factor: 0.3, **options) ⇒ ExponentialSmoothingEstimator
Initialize a new exponential smoothing estimator
25 26 27 28 29 |
# File 'lib/omnizip/eta/exponential_smoothing_estimator.rb', line 25 def initialize(smoothing_factor: 0.3, **) super(**) @smoothing_factor = smoothing_factor.clamp(0.0, 1.0) @smoothed_rate = nil end |
Instance Attribute Details
#smoothed_rate ⇒ Object (readonly)
Returns the value of attribute smoothed_rate.
18 19 20 |
# File 'lib/omnizip/eta/exponential_smoothing_estimator.rb', line 18 def smoothed_rate @smoothed_rate end |
#smoothing_factor ⇒ Object (readonly)
Returns the value of attribute smoothing_factor.
18 19 20 |
# File 'lib/omnizip/eta/exponential_smoothing_estimator.rb', line 18 def smoothing_factor @smoothing_factor end |
Instance Method Details
#estimate(remaining_bytes) ⇒ Models::ETAResult
Estimate time remaining using exponential smoothing
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/omnizip/eta/exponential_smoothing_estimator.rb', line 35 def estimate(remaining_bytes) return zero_result if remaining_bytes <= 0 unless sufficient_samples? return Models::ETAResult.new.tap do |result| result.seconds_remaining = 0.0 result.formatted = "calculating..." result.confidence_lower = 0.0 result.confidence_upper = 0.0 end end # Update smoothed rate current_rate = rate_calculator.bytes_per_second @smoothed_rate = if @smoothed_rate.nil? current_rate else (smoothing_factor * current_rate) + ((1.0 - smoothing_factor) * @smoothed_rate) end # Calculate ETA seconds_remaining = if @smoothed_rate.positive? remaining_bytes / @smoothed_rate else Float::INFINITY end # Calculate confidence interval lower, upper = confidence_interval(seconds_remaining) Models::ETAResult.new.tap do |result| result.seconds_remaining = seconds_remaining result.formatted = format_time(seconds_remaining) result.confidence_lower = lower result.confidence_upper = upper end end |
#reset ⇒ Object
Reset smoothed rate (e.g., when operation changes significantly)
76 77 78 |
# File 'lib/omnizip/eta/exponential_smoothing_estimator.rb', line 76 def reset @smoothed_rate = nil end |