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

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

View File

@ -1,3 +1,6 @@
database:
adapter: 'sqlite'
database: 'data/gamedata.db'
testing:
minimum_results_required: 3

View File

@ -0,0 +1,31 @@
Sequel.migration do
up do
# create tests table
create_table(:tests) do
primary_key :id
String :date_tag, null: false
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP
DateTime :updated_at, default: Sequel::CURRENT_TIMESTAMP
end
# add foreign keys to tests table
alter_table(:tests) do
add_foreign_key(:benchmark_id, :benchmarks, null: false)
add_foreign_key(:hardware_id, :hardware, null: false)
end
# add the test ID link to results table; remove old links to hardware and benchmarks tables
alter_table(:results) do
add_foreign_key(:test_id, :tests, null: false)
drop_column(:benchmark_id)
drop_column(:hardware_id)
end
end
down do
drop_column(:results, :test_id)
drop_table(:tests)
end
end

View File

@ -1,3 +1,7 @@
#main-nav{
margin-bottom: 15px;
}
h1.invalid{
color: red;
}

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

View File

@ -1,12 +1,43 @@
<div class="grid-x grid-margin-x">
<% if results.length > 0 %>
<% if tests.length > 0 %>
<div class="cell small-12">
<h2>Latest tests:</h2>
</div>
<div class="cell small-12">
<table>
<thead>
<tr>
<th>Hardware tested</th>
<th>Benchmark used</th>
<th># results</th>
</tr>
</thead>
<tbody>
<% tests.each do |t| %>
<tr>
<td><%= t.hardware.name %></td>
<td><%= t.benchmark.name %></td>
<td><%= t.results.length %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
<% else %>
<div class="cell small-12">
<p>I'm sorry, there don't appear to be any tests created yet. Check again later!</p>
</div>
<% end %>
<% if results.length > 0 %>
<div class="cell small-12">``
<h2>Latest benchmark results:</h2>
</div>
<div class="cell small-12">
<table>
<thead>
<tr>
<th>Test</th>
<th>Hardware tested</th>
<th>Benchmark used</th>
<th>Score</th>
@ -15,8 +46,9 @@
<tbody>
<% results.each do |r| %>
<tr>
<td><%= r.hardware.name %></td>
<td><%= r.benchmark.name %></td>
<td><%= r.test.name %></td>
<td><%= r.test.hardware.name %></td>
<td><%= r.test.benchmark.name %></td>
<td><%= r.formatted_score() %></td>
</tr>
<% end %>

View File

@ -4,6 +4,7 @@
<li><a href="/">Dashboard</a></li>
<li><a href="/hardware">Hardware</a></li>
<li><a href="/benchmark">Benchmarks</a></li>
<li><a href="/test">Tests</a></li>
<li><a href="/result">Results</a></li>
<li><a href="/comparison">Comparisons</a></li>
</ul>

46
views/test/add.erb Normal file
View File

@ -0,0 +1,46 @@
<div class="grid-x grid-margin-x">
<div class="cell small-12">
<h1>Add new test</h1>
</div>
</div>
<div class="grid-x grid-margin-x">
<form class="cell small-12" action="/test/add" method="post">
<div class="grid-x grid-padding-x">
<div class="cell smal-12">
<label>
Date Tag:
<input type="text" name="test_date_tag" placeholder="(XY/AB)">
</label>
</div>
</div>
<div class="grid-x grid-padding-x">
<div class="cell medium-6">
<label>
Hardware:
<select name="test_hardware">
<% hardware.each do |h| %>
<option value="<%= h.id %>"><%= h.name %></option>
<% end %>
</select>
</label>
</div>
<div class="cell medium-6">
<label>
Benchmark:
<select name="test_benchmark">
<% benchmarks.each do |b| %>
<option value="<%= b.id %>"><%= b.name %></option>
<% end %>
</select>
</label>
</div>
</div>
<input type="submit" class="button" value="Submit">
</form>
</div>

42
views/test/index.erb Normal file
View File

@ -0,0 +1,42 @@
<div class="grid-x grid-margin-x">
<div class="cell small-12">
<h1>List of tests</h1>
</div>
<div class="cell small-12">
<p>
<a href="/test/add">Add new test</a>
</p>
</div>
</div>
<div class="grid-x grid-margin-x">
<% if tests.length > 0 %>
<div class="cell small-12">
<table>
<thead>
<tr>
<th>Test name</th>
<th># of results</th>
<th>Date added</th>
<th>Date modified</th>
</tr>
</thead>
<tbody>
<% tests.each do |t| %>
<tr>
<td><%= t.name %></td>
<td><%= t.results.length %></td>
<td><%= date_format(t.created_at) %></td>
<td><%= date_format(t.updated_at) %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
<% else %>
<div class="cell small-12">
<p>I'm sorry, there don't appear to be any tests added yet. Check again later!</p>
</div>
<% end %>
</div>

22
views/test/view.erb Normal file
View File

@ -0,0 +1,22 @@
<div class="grid-x grid-margin-x">
<div class="cell small-12">
<h1 <%- unless test.valid? %> class="invalid"<% end %>><%= test.formatted_name %></h1>
<% unless test.valid? %>
<h4 class="invalid">Missing <%= test.missing_results %> results!</h4>
<% end %>
</div>
<div class="cell small-12">
<h3>Test results</h3>
<% if test.results.length > 0 %>
<ul>
<% test.results.each do |res| %>
<li></li>
<% end %>
</ul>
<% else %>
<p>There are no results</p>
<% end %>
</div>
</div>