Class: Serialbench::Models::ResultStore

Inherits:
Object
  • Object
show all
Defined in:
lib/serialbench/models/result_store.rb

Constant Summary collapse

DEFAULT_BASE_PATH =
'results'
RUNS_PATH =
'runs'
SETS_PATH =
'sets'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_path = DEFAULT_BASE_PATH) ⇒ ResultStore

Returns a new instance of ResultStore.



15
16
17
18
# File 'lib/serialbench/models/result_store.rb', line 15

def initialize(base_path = DEFAULT_BASE_PATH)
  @base_path = base_path
  ensure_results_directory
end

Instance Attribute Details

#base_pathObject (readonly)

Returns the value of attribute base_path.



13
14
15
# File 'lib/serialbench/models/result_store.rb', line 13

def base_path
  @base_path
end

Class Method Details

.defaultObject



20
21
22
# File 'lib/serialbench/models/result_store.rb', line 20

def self.default
  @default ||= new
end

Instance Method Details

#create_resultset(name, run_platform_strings, metadata: {}) ⇒ Object

Convenience methods



51
52
53
54
55
56
# File 'lib/serialbench/models/result_store.rb', line 51

def create_resultset(name, run_platform_strings, metadata: {})
  run_paths = run_platform_strings.map { |ps| File.join(runs_path, ps) }
  resultset = ResultSet.create(name, run_paths, metadata: )
  save_resultset(resultset)
  resultset
end

#ensure_results_directoryObject



102
103
104
105
# File 'lib/serialbench/models/result_store.rb', line 102

def ensure_results_directory
  FileUtils.mkdir_p(runs_path) unless Dir.exist?(runs_path)
  FileUtils.mkdir_p(sets_path) unless Dir.exist?(sets_path)
end

#find_resultsets(tags: nil, limit: nil) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/serialbench/models/result_store.rb', line 42

def find_resultsets(tags: nil, limit: nil)
  resultsets = ResultSet.find_all(sets_path)

  resultsets = resultsets.select { |resultset| (Array(tags) - resultset.tags).empty? } if tags

  limit ? resultsets.first(limit) : resultsets
end

#find_runs(tags: nil, limit: nil) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/serialbench/models/result_store.rb', line 29

def find_runs(tags: nil, limit: nil)
  runs = Result.find_all(runs_path)

  runs = runs.select { |run| (Array(tags) - run.tags).empty? } if tags

  limit ? runs.first(limit) : runs
end

#runs_pathObject

Run management



25
26
27
# File 'lib/serialbench/models/result_store.rb', line 25

def runs_path
  File.join(@base_path, RUNS_PATH)
end

#sets_pathObject

Run set management



38
39
40
# File 'lib/serialbench/models/result_store.rb', line 38

def sets_path
  File.join(@base_path, SETS_PATH)
end

#valid?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/serialbench/models/result_store.rb', line 98

def valid?
  validate_structure.empty?
end

#validate_structureObject

Validation



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/serialbench/models/result_store.rb', line 59

def validate_structure
  errors = []

  # Check base structure
  errors << "Base path does not exist: #{@base_path}" unless Dir.exist?(@base_path)
  errors << "Runs directory does not exist: #{runs_path}" unless Dir.exist?(runs_path)
  errors << "Sets directory does not exist: #{sets_path}" unless Dir.exist?(sets_path)

  # Validate individual runs
  if Dir.exist?(runs_path)
    Dir.glob(File.join(runs_path, '*')).each do |run_path|
      next unless Dir.exist?(run_path)

      begin
        run = Result.load(run_path)
        run.validate!
      rescue StandardError => e
        errors << "Invalid result at #{run_path}: #{e.message}"
      end
    end
  end

  # Validate result sets
  if Dir.exist?(sets_path)
    Dir.glob(File.join(sets_path, '*')).each do |set_path|
      next unless Dir.exist?(set_path)

      begin
        resultset = ResultSet.load(set_path)
        resultset.validate!
      rescue StandardError => e
        errors << "Invalid result set at #{set_path}: #{e.message}"
      end
    end
  end

  errors
end