Class: Omnizip::Progress::ProgressTracker

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(total_files:, total_bytes:, reporters: [], update_interval: 0.5, eta_strategy: :exponential_smoothing) ⇒ ProgressTracker

Initialize a new progress tracker

Parameters:

  • total_files (Integer)

    Total number of files to process

  • total_bytes (Integer)

    Total bytes to process

  • reporters (Array<ProgressReporter>) (defaults to: [])

    Progress reporters

  • update_interval (Float) (defaults to: 0.5)

    Minimum seconds between reports

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

    ETA estimation strategy



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_estimatorObject (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_timeObject (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_progressObject (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

#reportersObject (readonly)

Returns the value of attribute reporters.



15
16
17
# File 'lib/omnizip/progress/progress_tracker.rb', line 15

def reporters
  @reporters
end

#update_intervalObject (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

Parameters:



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_processedInteger

Get number of bytes processed

Returns:

  • (Integer)

    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

Returns:

  • (Boolean)

    true if complete



164
165
166
# File 'lib/omnizip/progress/progress_tracker.rb', line 164

def complete?
  operation_progress.complete?
end

#current_fileString?

Get current file being processed

Returns:

  • (String, nil)

    Current file name



87
88
89
# File 'lib/omnizip/progress/progress_tracker.rb', line 87

def current_file
  operation_progress.current_file
end

#elapsed_secondsFloat

Get elapsed time

Returns:

  • (Float)

    Seconds elapsed



171
172
173
# File 'lib/omnizip/progress/progress_tracker.rb', line 171

def elapsed_seconds
  operation_progress.elapsed_seconds
end

#eta_formattedString

Get formatted ETA string

Returns:

  • (String)

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



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_resultModels::ETAResult

Get full ETA result with confidence

Returns:



131
132
133
# File 'lib/omnizip/progress/progress_tracker.rb', line 131

def eta_result
  eta_estimator.estimate(operation_progress.remaining_bytes)
end

#eta_secondsFloat

Get ETA in seconds

Returns:

  • (Float)

    Estimated seconds remaining



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_processedInteger

Get number of files processed

Returns:

  • (Integer)

    Files processed



73
74
75
# File 'lib/omnizip/progress/progress_tracker.rb', line 73

def files_processed
  operation_progress.files_done
end

#percentageFloat

Get current completion percentage

Returns:

  • (Float)

    Percentage complete (0.0-100.0)



66
67
68
# File 'lib/omnizip/progress/progress_tracker.rb', line 66

def percentage
  operation_progress.percentage
end

#rate_bpsFloat

Get processing rate in bytes/s

Returns:

  • (Float)

    Bytes per second



101
102
103
# File 'lib/omnizip/progress/progress_tracker.rb', line 101

def rate_bps
  eta_estimator.rate_calculator.bytes_per_second
end

#rate_formattedString

Get formatted rate string

Returns:

  • (String)

    Formatted rate (e.g., "2.5 MB/s")



108
109
110
# File 'lib/omnizip/progress/progress_tracker.rb', line 108

def rate_formatted
  eta_estimator.rate_calculator.format_rate
end

#rate_mbpsFloat

Get processing rate in MB/s

Returns:

  • (Float)

    Megabytes per second



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

Parameters:



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

#reportObject

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

Parameters:

  • files (Integer)

    Number of files completed

  • bytes (Integer)

    Number of bytes processed

  • current_file (String) (defaults to: nil)

    Name of file currently processing



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