Class: Serialbench::Models::ResultSet

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/serialbench/models/result_set.rb

Overview

ResultSet model for managing collections of benchmark results

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load(path) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
# File 'lib/serialbench/models/result_set.rb', line 17

def self.load(path)
  raise ArgumentError, "Path does not exist: #{path}" unless Dir.exist?(path)

  # Load benchmark data
  data_file = File.join(path, 'resultset.yaml')

  raise ArgumentError, "No results data found in #{path}" unless File.exist?(data_file)

  from_yaml(IO.read(data_file))
end

Instance Method Details

#add_result(result_path) ⇒ Object

Raises:

  • (ArgumentError)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/serialbench/models/result_set.rb', line 37

def add_result(result_path)
  # Assume result_path is the directory containing benchmark results and is named
  # accordingly
  result_name = File.basename(result_path)
  raise ArgumentError, 'Result name cannot be empty' if result_name.empty?
  # Validate that the result path is a directory
  raise ArgumentError, 'Result path must be a directory' unless File.directory?(result_path)

  result_file_path = File.join(result_path, 'results.yaml')
  raise ArgumentError, "No results data found in #{result_path}" unless File.exist?(result_file_path)

  result = Result.load(result_path)

  # Validate that the result has required fields
  raise ArgumentError, "Result from #{result_path} is missing platform information" if result.platform.nil?
  raise ArgumentError, "Result from #{result_path} is missing environment_config" if result.environment_config.nil?
  raise ArgumentError, "Result from #{result_path} is missing benchmark_config" if result.benchmark_config.nil?

  # Check if result already exists:
  # If environment_config.created_at is identical;
  # If platform.platform_string is identical;
  # If benchmark_config.benchmark_name is identical;

  duplicates = results.select do |r|
    # Skip results with nil platform (defensive check)
    next if r.platform.nil? || result.platform.nil?

    r.platform.platform_string == result.platform.platform_string &&
      r.environment_config.created_at == result.environment_config.created_at &&
      r.benchmark_config.benchmark_name == result.benchmark_config.benchmark_name
  end

  raise ArgumentError, 'Result is already present in this resultset' if duplicates.any?

  # Add the result to the resultset
  results << result
  self.updated_at = Time.now.utc.iso8601

  result
end

#save(dir) ⇒ Object



32
33
34
35
# File 'lib/serialbench/models/result_set.rb', line 32

def save(dir)
  FileUtils.mkdir_p(dir)
  to_file(File.join(dir, 'resultset.yaml'))
end

#to_file(path) ⇒ Object



28
29
30
# File 'lib/serialbench/models/result_set.rb', line 28

def to_file(path)
  File.write(path, to_yaml)
end