Removed Test object to simplify database schema; updated docker scripts to run database migrations before starting the server if the database doesn't exist
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Gregory Ballantine 2024-02-09 08:40:34 -05:00
parent c83d517437
commit ef2e0a12a5
17 changed files with 17 additions and 274 deletions

View File

@ -12,4 +12,4 @@ RUN gem install rake
COPY . ./ COPY . ./
ENTRYPOINT ["rake", "server:dev"] ENTRYPOINT ["bash", "entrypoints/dev.sh"]

View File

@ -4,6 +4,7 @@ Sequel.migration do
# create tests table # create tests table
create_table(:results) do create_table(:results) do
primary_key :id primary_key :id
foreign_key :hardware_id, :hardware
foreign_key :benchmark_id, :benchmarks foreign_key :benchmark_id, :benchmarks
Float :avg_score, null: false Float :avg_score, null: false
Float :min_score Float :min_score
@ -11,18 +12,9 @@ Sequel.migration do
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP
DateTime :updated_at, default: Sequel::CURRENT_TIMESTAMP DateTime :updated_at, default: Sequel::CURRENT_TIMESTAMP
end end
# create many-to-many table for results and tests
create_table(:tests_results) do
foreign_key :test_id, :tests
foreign_key :result_id, :results
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP
DateTime :updated_at, default: Sequel::CURRENT_TIMESTAMP
end
end end
down do down do
drop_table(:tests_results)
drop_table(:results) drop_table(:results)
end end

View File

@ -1,28 +0,0 @@
Sequel.migration do
up do
# create tests table
create_table(:tests) do
primary_key :id
foreign_key :hardware_id, :hardware
String :date_tag, null: false
String :description, text: true
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP
DateTime :updated_at, default: Sequel::CURRENT_TIMESTAMP
end
# create many-to-many table for benchmarks and tests
create_table(:tests_benchmarks) do
foreign_key :test_id, :tests
foreign_key :benchmark_id, :benchmarks
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP
DateTime :updated_at, default: Sequel::CURRENT_TIMESTAMP
end
end
down do
drop_table(:tests_benchmarks)
drop_table(:tests)
end
end

7
entrypoints/dev.sh Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
if [ ! -f ./data/gamedata.db ]; then
rake db:migrate
fi
rake server:dev

View File

@ -3,6 +3,6 @@
# Benchmark - database model for PC benchmarks # Benchmark - database model for PC benchmarks
class Benchmark < Sequel::Model class Benchmark < Sequel::Model
one_to_many :tests one_to_many :results
end end

View File

@ -3,6 +3,6 @@
# Hardware - database model for PC hardware # Hardware - database model for PC hardware
class Hardware < Sequel::Model(:hardware) class Hardware < Sequel::Model(:hardware)
one_to_many :tests one_to_many :results
end end

View File

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

View File

@ -3,7 +3,8 @@
# Result - database model for benchmark results # Result - database model for benchmark results
class Result < Sequel::Model class Result < Sequel::Model
many_to_one :test many_to_one :hardware
many_to_one :benchmarks
def formatted_score def formatted_score
return @score return @score

View File

@ -1,30 +0,0 @@
# frozen_string_literal: true
# Test - database model for PC hardware tests
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 "#{@date_tag} - #{@hardware.name} / #{@benchmark.name}"
end
# formats the name of the test for use in a graph
def graph_name
return "#{@hardware.name} (#{@date_tag})"
end
# determines whether the test has enough results to fulfill the requirement
def valid?
return (@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') - @results.length)
end
end

View File

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

View File

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

View File

@ -1,53 +0,0 @@
# frozen_string_literal: true
# /test routes
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/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
date_tag = "(#{date_tag}" unless date_tag.start_with?('(')
date_tag += ')' unless date_tag.end_with?(')')
test = Test.create(
date_tag: date_tag,
hardware_id: params[:test_hardware]
)
params[:test_benchmarks].each do |b|
benchmark = Benchmark.where(id: b).first()
test.add_benchmark(benchmark)
end
redirect "/test/#{test.id}"
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
end

View File

@ -1,36 +1,6 @@
<div class="grid-x grid-margin-x"> <div class="grid-x grid-margin-x">
<% 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 %> <% if results.length > 0 %>
<div class="cell small-12">`` <div class="cell small-12">
<h2>Latest benchmark results:</h2> <h2>Latest benchmark results:</h2>
</div> </div>
<div class="cell small-12"> <div class="cell small-12">
@ -46,9 +16,8 @@
<tbody> <tbody>
<% results.each do |r| %> <% results.each do |r| %>
<tr> <tr>
<td><%= r.test.name %></td> <td><%= r.hardware.name %></td>
<td><%= r.test.hardware.name %></td> <td><%= r.benchmark.name %></td>
<td><%= r.test.benchmark.name %></td>
<td><%= r.formatted_score() %></td> <td><%= r.formatted_score() %></td>
</tr> </tr>
<% end %> <% end %>

View File

@ -4,9 +4,8 @@
<li><a href="/">Dashboard</a></li> <li><a href="/">Dashboard</a></li>
<li><a href="/hardware">Hardware</a></li> <li><a href="/hardware">Hardware</a></li>
<li><a href="/benchmark">Benchmarks</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="/result">Results</a></li>
<li><a href="/comparison">Comparisons</a></li> <li><a href="/reports">Reports</a></li>
</ul> </ul>
</div> </div>
</div> </div>

View File

@ -1,46 +0,0 @@
<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 small-12 medium-3">
<label>
Date Tag:
<input type="text" name="test_date_tag" placeholder="(XY/AB)">
</label>
</div>
<div class="cell medium-9">
<label>
Hardware:
<select name="test_hardware">
<% hardware.each do |h| %>
<option value="<%= h.id %>"><%= h.name %></option>
<% end %>
</select>
</label>
</div>
</div>
<div class="grid-x grid-padding-x">
<div class="cell small-12">
<label>
Benchmark:
<select name="test_benchmark[]" multiple>
<% 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>

View File

@ -1,42 +0,0 @@
<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><a href="/test/<%= t.id %>"><%= t.name %></a></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>

View File

@ -1,22 +0,0 @@
<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>