Added functionality to add a benchmark result

This commit is contained in:
2023-07-05 23:39:08 -04:00
parent 691e2e9b1e
commit 7655b75410
6 changed files with 142 additions and 2 deletions

View File

@ -1,6 +1,6 @@
class Result < Sequel::Model
many_to_one :hardware
many_to_one :benchmarks
many_to_one :benchmark
end

View File

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

36
src/routes/result.rb Normal file
View File

@ -0,0 +1,36 @@
class GameData < Sinatra::Base
get '/result' do
results = Result.reverse(:updated_at).limit(10).all()
erb :'result/index', locals: {
title: 'List of Results',
results: results
}
end
get '/result/add' do
hardware = Hardware.all()
benchmarks = Benchmark.all()
erb :'result/add', locals: {
title: 'Add Result',
hardware: hardware,
benchmarks: benchmarks
}
end
post '/result/add' do
benchmark = Benchmark.where(:id => params[:result_benchmark]).first()
formatted_score = params[:result_average]
if benchmark.scoring == 'fps'
formatted_score = params[:result_average] + ':' + params[:result_minimum] + ':' + params[:result_maximum]
end
result = Result.create(
hardware_id: params[:result_hardware],
benchmark_id: params[:result_benchmark],
score: formatted_score
)
redirect "/result"
end
end