Class: Classifier::Streaming::Progress
- Defined in:
- lib/classifier/streaming/progress.rb
Overview
Progress tracking object yielded to blocks during batch/stream operations. Provides information about training progress including completion percentage, elapsed time, processing rate, and estimated time remaining.
Instance Attribute Summary collapse
-
#completed ⇒ Object
Returns the value of attribute completed.
-
#current_batch ⇒ Object
Returns the value of attribute current_batch.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
-
#complete? ⇒ Boolean
Returns true if the operation is complete.
-
#elapsed ⇒ Object
Returns the elapsed time in seconds since the operation started.
-
#eta ⇒ Object
Returns the estimated time remaining in seconds.
-
#initialize(total: nil, completed: 0) ⇒ Progress
constructor
A new instance of Progress.
-
#percent ⇒ Object
Returns the completion percentage (0-100).
-
#rate ⇒ Object
Returns the processing rate in items per second.
-
#to_h ⇒ Object
Returns a hash representation of the progress state.
Constructor Details
#initialize(total: nil, completed: 0) ⇒ Progress
Returns a new instance of Progress.
25 26 27 28 29 30 |
# File 'lib/classifier/streaming/progress.rb', line 25 def initialize(total: nil, completed: 0) @completed = completed @total = total @start_time = Time.now @current_batch = 0 end |
Instance Attribute Details
#completed ⇒ Object
Returns the value of attribute completed.
22 23 24 |
# File 'lib/classifier/streaming/progress.rb', line 22 def completed @completed end |
#current_batch ⇒ Object
Returns the value of attribute current_batch.
22 23 24 |
# File 'lib/classifier/streaming/progress.rb', line 22 def current_batch @current_batch end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
21 22 23 |
# File 'lib/classifier/streaming/progress.rb', line 21 def start_time @start_time end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
21 22 23 |
# File 'lib/classifier/streaming/progress.rb', line 21 def total @total end |
Instance Method Details
#complete? ⇒ Boolean
Returns true if the operation is complete.
75 76 77 78 79 |
# File 'lib/classifier/streaming/progress.rb', line 75 def complete? return false unless @total @completed >= @total end |
#elapsed ⇒ Object
Returns the elapsed time in seconds since the operation started.
45 46 47 |
# File 'lib/classifier/streaming/progress.rb', line 45 def elapsed Time.now - @start_time end |
#eta ⇒ Object
Returns the estimated time remaining in seconds. Returns nil if total is unknown or rate is zero.
64 65 66 67 68 69 70 |
# File 'lib/classifier/streaming/progress.rb', line 64 def eta return nil unless @total return nil if rate.zero? return 0.0 if @completed >= @total (@total - @completed) / rate end |
#percent ⇒ Object
Returns the completion percentage (0-100). Returns nil if total is unknown.
36 37 38 39 40 |
# File 'lib/classifier/streaming/progress.rb', line 36 def percent return nil unless @total&.positive? (@completed.to_f / @total * 100).round(2) end |
#rate ⇒ Object
Returns the processing rate in items per second. Returns 0 if no time has elapsed.
53 54 55 56 57 58 |
# File 'lib/classifier/streaming/progress.rb', line 53 def rate e = elapsed return 0.0 if e.zero? @completed / e end |
#to_h ⇒ Object
Returns a hash representation of the progress state.
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/classifier/streaming/progress.rb', line 84 def to_h { completed: @completed, total: @total, percent: percent, elapsed: elapsed.round(2), rate: rate.round(2), eta: eta&.round(2) } end |