Class: Binpacker::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/binpacker/report.rb,
sig/binpacker/report.rbs

Overview

Builds the machine-readable Run report: predicted versus actual per-Worker durations plus the worst per-Test Drift. See docs/design/run-report-format.md.

Constant Summary collapse

SCHEMA =

Returns:

  • (Integer)
1
DRIFT_LIMIT =

Returns:

  • (Integer)
10

Instance Method Summary collapse

Constructor Details

#initialize(profile:, algorithm:, predicted_loads:, worker_stats:, all_timings:, timings:) ⇒ Report

Returns a new instance of Report.

Parameters:

  • profile: (Object)
  • algorithm: (Object)
  • predicted_loads: (Object)
  • worker_stats: (Object)
  • all_timings: (Object)
  • timings: (Object)


12
13
14
15
16
17
18
19
# File 'lib/binpacker/report.rb', line 12

def initialize(profile:, algorithm:, predicted_loads:, worker_stats:, all_timings:, timings:)
  @profile = profile
  @algorithm = algorithm
  @predicted_loads = predicted_loads
  @worker_stats = worker_stats
  @all_timings = all_timings
  @timings = timings
end

Instance Method Details

#to_hHash[Symbol, untyped]

Returns:

  • (Hash[Symbol, untyped])


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/binpacker/report.rb', line 21

def to_h
  predicted = @predicted_loads
  actual = @worker_stats.map { |s| s[:total_time] }

  {
    schema: SCHEMA,
    profile: @profile,
    algorithm: @algorithm,
    worker_count: @worker_stats.size,
    predicted_makespan: round(predicted.max || 0.0),
    actual_makespan: round(actual.max || 0.0),
    workers: workers,
    balance: {
      predicted_deviation_pct: deviation_pct(predicted),
      actual_deviation_pct: deviation_pct(actual)
    },
    drift: drift
  }
end

#write(path) ⇒ Object

Parameters:

  • (Object)

Returns:

  • (Object)


41
42
43
# File 'lib/binpacker/report.rb', line 41

def write(path)
  File.write(path, JSON.pretty_generate(to_h))
end