Class: Omnizip::Progress::ProgressTracker
- Inherits:
-
Object
- Object
- Omnizip::Progress::ProgressTracker
- Defined in:
- lib/omnizip/progress/progress_tracker.rb
Overview
Central progress tracking coordinator.
This class tracks operation progress, calculates rates and ETA, and reports progress to configured reporters. It integrates the OperationProgress model with ETA calculation.
Instance Attribute Summary collapse
-
#eta_estimator ⇒ Object
readonly
Returns the value of attribute eta_estimator.
-
#last_report_time ⇒ Object
readonly
Returns the value of attribute last_report_time.
-
#operation_progress ⇒ Object
readonly
Returns the value of attribute operation_progress.
-
#reporters ⇒ Object
readonly
Returns the value of attribute reporters.
-
#update_interval ⇒ Object
readonly
Returns the value of attribute update_interval.
Instance Method Summary collapse
-
#add_reporter(reporter) ⇒ Object
Add a reporter.
-
#bytes_processed ⇒ Integer
Get number of bytes processed.
-
#complete? ⇒ Boolean
Check if operation is complete.
-
#current_file ⇒ String?
Get current file being processed.
-
#elapsed_seconds ⇒ Float
Get elapsed time.
-
#eta_formatted ⇒ String
Get formatted ETA string.
-
#eta_result ⇒ Models::ETAResult
Get full ETA result with confidence.
-
#eta_seconds ⇒ Float
Get ETA in seconds.
-
#files_processed ⇒ Integer
Get number of files processed.
-
#initialize(total_files:, total_bytes:, reporters: [], update_interval: 0.5, eta_strategy: :exponential_smoothing) ⇒ ProgressTracker
constructor
Initialize a new progress tracker.
-
#percentage ⇒ Float
Get current completion percentage.
-
#rate_bps ⇒ Float
Get processing rate in bytes/s.
-
#rate_formatted ⇒ String
Get formatted rate string.
-
#rate_mbps ⇒ Float
Get processing rate in MB/s.
-
#remove_reporter(reporter) ⇒ Object
Remove a reporter.
-
#report ⇒ Object
Force a progress report (regardless of interval).
-
#update(files:, bytes:, current_file: nil) ⇒ Object
Update progress with new values.
Constructor Details
#initialize(total_files:, total_bytes:, reporters: [], update_interval: 0.5, eta_strategy: :exponential_smoothing) ⇒ ProgressTracker
Initialize a new progress tracker
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/omnizip/progress/progress_tracker.rb', line 25 def initialize(total_files:, total_bytes:, reporters: [], update_interval: 0.5, eta_strategy: :exponential_smoothing) @operation_progress = OperationProgress.new( total_files: total_files, total_bytes: total_bytes, ) @eta_estimator = ETA.create_estimator(eta_strategy) @reporters = Array(reporters) @update_interval = update_interval @last_report_time = Time.now - update_interval # Allow immediate first report @mutex = Mutex.new # Thread safety end |
Instance Attribute Details
#eta_estimator ⇒ Object (readonly)
Returns the value of attribute eta_estimator.
15 16 17 |
# File 'lib/omnizip/progress/progress_tracker.rb', line 15 def eta_estimator @eta_estimator end |
#last_report_time ⇒ Object (readonly)
Returns the value of attribute last_report_time.
15 16 17 |
# File 'lib/omnizip/progress/progress_tracker.rb', line 15 def last_report_time @last_report_time end |
#operation_progress ⇒ Object (readonly)
Returns the value of attribute operation_progress.
15 16 17 |
# File 'lib/omnizip/progress/progress_tracker.rb', line 15 def operation_progress @operation_progress end |
#reporters ⇒ Object (readonly)
Returns the value of attribute reporters.
15 16 17 |
# File 'lib/omnizip/progress/progress_tracker.rb', line 15 def reporters @reporters end |
#update_interval ⇒ Object (readonly)
Returns the value of attribute update_interval.
15 16 17 |
# File 'lib/omnizip/progress/progress_tracker.rb', line 15 def update_interval @update_interval end |
Instance Method Details
#add_reporter(reporter) ⇒ Object
Add a reporter
146 147 148 149 150 |
# File 'lib/omnizip/progress/progress_tracker.rb', line 146 def add_reporter(reporter) @mutex.synchronize do @reporters << reporter end end |
#bytes_processed ⇒ Integer
Get number of bytes processed
80 81 82 |
# File 'lib/omnizip/progress/progress_tracker.rb', line 80 def bytes_processed operation_progress.bytes_done end |
#complete? ⇒ Boolean
Check if operation is complete
164 165 166 |
# File 'lib/omnizip/progress/progress_tracker.rb', line 164 def complete? operation_progress.complete? end |
#current_file ⇒ String?
Get current file being processed
87 88 89 |
# File 'lib/omnizip/progress/progress_tracker.rb', line 87 def current_file operation_progress.current_file end |
#elapsed_seconds ⇒ Float
Get elapsed time
171 172 173 |
# File 'lib/omnizip/progress/progress_tracker.rb', line 171 def elapsed_seconds operation_progress.elapsed_seconds end |
#eta_formatted ⇒ String
Get formatted ETA string
123 124 125 126 |
# File 'lib/omnizip/progress/progress_tracker.rb', line 123 def eta_formatted result = eta_estimator.estimate(operation_progress.remaining_bytes) result.formatted end |
#eta_result ⇒ Models::ETAResult
Get full ETA result with confidence
131 132 133 |
# File 'lib/omnizip/progress/progress_tracker.rb', line 131 def eta_result eta_estimator.estimate(operation_progress.remaining_bytes) end |
#eta_seconds ⇒ Float
Get ETA in seconds
115 116 117 118 |
# File 'lib/omnizip/progress/progress_tracker.rb', line 115 def eta_seconds result = eta_estimator.estimate(operation_progress.remaining_bytes) result.seconds_remaining end |
#files_processed ⇒ Integer
Get number of files processed
73 74 75 |
# File 'lib/omnizip/progress/progress_tracker.rb', line 73 def files_processed operation_progress.files_done end |
#percentage ⇒ Float
Get current completion percentage
66 67 68 |
# File 'lib/omnizip/progress/progress_tracker.rb', line 66 def percentage operation_progress.percentage end |
#rate_bps ⇒ Float
Get processing rate in bytes/s
101 102 103 |
# File 'lib/omnizip/progress/progress_tracker.rb', line 101 def rate_bps eta_estimator.rate_calculator.bytes_per_second end |
#rate_formatted ⇒ String
Get formatted rate string
108 109 110 |
# File 'lib/omnizip/progress/progress_tracker.rb', line 108 def rate_formatted eta_estimator.rate_calculator.format_rate end |
#rate_mbps ⇒ Float
Get processing rate in MB/s
94 95 96 |
# File 'lib/omnizip/progress/progress_tracker.rb', line 94 def rate_mbps eta_estimator.rate_calculator.megabytes_per_second end |
#remove_reporter(reporter) ⇒ Object
Remove a reporter
155 156 157 158 159 |
# File 'lib/omnizip/progress/progress_tracker.rb', line 155 def remove_reporter(reporter) @mutex.synchronize do @reporters.delete(reporter) end end |
#report ⇒ Object
Force a progress report (regardless of interval)
136 137 138 139 140 141 |
# File 'lib/omnizip/progress/progress_tracker.rb', line 136 def report @mutex.synchronize do reporters.each { |reporter| reporter.report(self) } @last_report_time = Time.now end end |
#update(files:, bytes:, current_file: nil) ⇒ Object
Update progress with new values
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/omnizip/progress/progress_tracker.rb', line 43 def update(files:, bytes:, current_file: nil) @mutex.synchronize do # Update operation progress operation_progress.update( files: files, bytes: bytes, current_file: current_file, ) # Add sample to ETA estimator eta_estimator.add_sample( bytes_processed: bytes, files_processed: files, ) # Report if enough time has passed report_if_needed end end |