[Issue #5] - Reworked app to better organize results with their corresponding tests

This commit is contained in:
2023-09-21 20:41:25 -06:00
parent 269587e6c9
commit c940a248d7
16 changed files with 266 additions and 7 deletions

View File

@ -1,5 +1,5 @@
class Benchmark < Sequel::Model
one_to_many :results
one_to_many :tests
end

View File

@ -1,5 +1,5 @@
class Hardware < Sequel::Model(:hardware)
one_to_many :results
one_to_many :tests
end

View File

@ -1,3 +1,4 @@
require_relative 'hardware'
require_relative 'benchmark'
require_relative 'result'
require_relative 'test'

View File

@ -1,7 +1,6 @@
class Result < Sequel::Model
many_to_one :hardware
many_to_one :benchmark
many_to_one :test
def formatted_score()
return self.score

27
src/models/test.rb Normal file
View File

@ -0,0 +1,27 @@
class Test < Sequel::Model
one_to_many :results # link Test model to its related results
many_to_one :benchmark # link Test model back to its benchmark
many_to_one :hardware # link Test model back to hardware used in test
# formats the name of the test for display in the web UI
def formatted_name()
return "#{self.date_tag} - #{self.hardware.name} / #{self.benchmark.name}"
end
# formats the name of the test for use in a graph
def graph_name()
return "#{self.hardware.name} (#{self.date_tag})"
end
# determines whether the test has enough results to fulfill the requirement
def valid?()
return (self.results.length >= $conf.get('testing.minimum_results_required'))
end
# determines how many results are still missing for a test
def missing_results()
return ($conf.get('testing.minimum_results_required') - self.results.length)
end
end

View File

@ -1,9 +1,11 @@
class GameData < Sinatra::Base
get '/' do
tests = Test.reverse(:updated_at).limit(10).all()
results = Result.reverse(:updated_at).limit(10).all()
erb :'index/index', locals: {
title: 'Dashboard',
tests: tests,
results: results
}
end

View File

@ -2,3 +2,4 @@ require_relative 'index'
require_relative 'hardware'
require_relative 'benchmark'
require_relative 'result'
require_relative 'test'

48
src/routes/test.rb Normal file
View File

@ -0,0 +1,48 @@
class GameData < Sinatra::Base
get '/test' do
tests = Test.reverse(:updated_at).limit(10).all()
erb :'test/index', locals: {
title: 'List of Tests',
tests: tests
}
end
get '/test/:test_id' do
test = Test.where(id: params[:test_id]).first()
erb :'test/view', locals: {
title: "Test: #{test.date_tag}",
test: test
}
end
get '/test/add' do
hardware = Hardware.all()
benchmarks = Benchmark.all()
erb :'test/add', locals: {
title: 'Add Test',
hardware: hardware,
benchmarks: benchmarks
}
end
post '/test/add' do
date_tag = params[:test_date_tag]
# make sure the date tag field is formatting properly
unless date_tag.start_with?('(')
date_tag = '(' + date_tag
end
unless date_tag.end_with?(')')
date_tag = date_tag + ')'
end
test = Test.create(
date_tag: params[:test_date_tag],
hardware_id: params[:test_hardware],
benchmark_id: params[:test_benchmark]
)
redirect "/test/#{test.id}"
end
end