Class: Judges::Statistics
Overview
Statistics collector for judge executions.
This class collects and aggregates statistics about judge executions across multiple cycles, providing insights into performance and results.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2024-2025 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#empty? ⇒ Boolean
Check if statistics are empty.
-
#initialize ⇒ Statistics
constructor
Initialize empty statistics.
-
#record(name, time, result, churn = nil) ⇒ Object
Record statistics for a judge execution.
-
#report(loog) ⇒ Object
Generate a formatted statistics report.
Constructor Details
#initialize ⇒ Statistics
Initialize empty statistics.
18 19 20 |
# File 'lib/judges/statistics.rb', line 18 def initialize @data = {} end |
Instance Method Details
#empty? ⇒ Boolean
Check if statistics are empty.
24 25 26 |
# File 'lib/judges/statistics.rb', line 24 def empty? @data.empty? end |
#record(name, time, result, churn = nil) ⇒ Object
Record statistics for a judge execution.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/judges/statistics.rb', line 33 def record(name, time, result, churn = nil) unless @data[name] @data[name] = { total_time: 0.0, cycles: 0, results: [], total_churn: nil } end stats = @data[name] stats[:total_time] += time stats[:cycles] += 1 stats[:results] << result return unless churn if stats[:total_churn] stats[:total_churn] += churn else stats[:total_churn] = churn end end |
#report(loog) ⇒ Object
Generate a formatted statistics report.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/judges/statistics.rb', line 56 def report(loog) return if empty? fmt = "%-30s\t%9s\t%7s\t%15s\t%-15s" loog.info( [ 'Judge execution summary:', format(fmt, 'Judge', 'Seconds', 'Cycles', 'Changes', 'Results'), format(fmt, '---', '---', '---', '---', '---'), @data.sort_by { |_, stats| stats[:total_time] }.reverse.map do |name, stats| format(fmt, name, format('%.3f', stats[:total_time]), stats[:cycles], stats[:total_churn] ? stats[:total_churn].to_s : 'N/A', summarize(stats[:results])) end.join("\n ") ].join("\n ") ) end |