Fixed a lot of linter warnings
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Gregory Ballantine 2023-12-11 13:08:46 -05:00
parent 34741691ed
commit 516f125ea7
14 changed files with 76 additions and 34 deletions

View File

@ -1,18 +1,20 @@
# frozen_string_literal: true
require 'yaml'
# Config - loads and manages the app's configuration
class Config
DEFAULT_CONFIG = 'config/defaults.yaml'
def initialize(config_path)
@data = YAML::load_file(DEFAULT_CONFIG)
@data = YAML.load_file(DEFAULT_CONFIG)
if File.exists?(config_path)
@data.merge!(YAML::load_file(config_path))
end
# merge in user-defined configuration if it exists
@data.merge!(YAML.load_file(config_path)) if File.exist?(config_path)
end
def get(key, depth = 0)
def get(key)
bits = key.split('.')
value = @data

View File

@ -1,3 +1,6 @@
# frozen_string_literal: true
# Helpers - view helper functions
module Helpers
def date_format(date)

View File

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

View File

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

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_relative 'hardware'
require_relative 'benchmark'
require_relative 'result'

View File

@ -1,9 +1,12 @@
# frozen_string_literal: true
# Result - database model for benchmark results
class Result < Sequel::Model
many_to_one :test
def formatted_score()
return self.score
def formatted_score
return @score
end
end

View File

@ -1,27 +1,30 @@
# 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
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}"
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 "#{self.hardware.name} (#{self.date_tag})"
def graph_name
return "#{@hardware.name} (#{@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'))
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') - self.results.length)
def missing_results
return ($conf.get('testing.minimum_results_required') - @results.length)
end
end

View File

@ -1,4 +1,8 @@
# frozen_string_literal: true
# /benchmark routes
class GameData < Sinatra::Base
get '/benchmark' do
benchmarks = Benchmark.reverse(:updated_at).limit(10).all()
@ -20,6 +24,7 @@ class GameData < Sinatra::Base
description: params[:benchmark_description]
)
redirect "/benchmark"
redirect "/benchmark/#{benchmark.id}"
end
end

View File

@ -1,4 +1,8 @@
# frozen_string_literal: true
# /hardware routes
class GameData < Sinatra::Base
get '/hardware' do
hardware = Hardware.reverse(:updated_at).limit(10).all()
@ -19,6 +23,7 @@ class GameData < Sinatra::Base
type: params[:hardware_type]
)
redirect "/hardware"
redirect "/hardware#{hardware.id}"
end
end

View File

@ -1,4 +1,8 @@
# frozen_string_literal: true
# / (top-level) routes
class GameData < Sinatra::Base
get '/' do
tests = Test.reverse(:updated_at).limit(10).all()
results = Result.reverse(:updated_at).limit(10).all()
@ -10,5 +14,4 @@ class GameData < Sinatra::Base
}
end
# more routes...
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_relative 'index'
require_relative 'hardware'
require_relative 'benchmark'

View File

@ -1,4 +1,8 @@
# frozen_string_literal: true
# /result routes
class GameData < Sinatra::Base
get '/result' do
results = Result.reverse(:updated_at).limit(10).all()
@ -19,12 +23,10 @@ class GameData < Sinatra::Base
}
end
post '/result/add' do
benchmark = Benchmark.where(:id => params[:result_benchmark]).first()
result_minimum = params[:result_minimum] if params.key?(:result_minimum)
result_maximum = params[:result_maximum] if params.key?(:result_maximum)
result_minimum = params[:result_minimum] if params.has_key?(:result_minimum)
result_maximum = params[:result_maximum] if params.has_key?(:result_maximum)
result = Result.create(
Result.create(
hardware_id: params[:result_hardware],
benchmark_id: params[:result_benchmark],
score: params[:result_average],
@ -32,6 +34,7 @@ class GameData < Sinatra::Base
maximum_score: result_maximum
)
redirect "/result"
redirect '/result'
end
end

View File

@ -1,4 +1,8 @@
# frozen_string_literal: true
# /test routes
class GameData < Sinatra::Base
get '/test' do
tests = Test.reverse(:updated_at).limit(10).all()
@ -30,19 +34,16 @@ class GameData < Sinatra::Base
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
date_tag = "(#{date_tag}" unless date_tag.start_with?('(')
date_tag += ')' unless date_tag.end_with?(')')
test = Test.create(
date_tag: params[:test_date_tag],
date_tag: date_tag,
hardware_id: params[:test_hardware],
benchmark_id: params[:test_benchmark]
)
redirect "/test/#{test.id}"
end
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'sinatra/base'
require 'sequel'
require 'sqlite3'
@ -9,6 +11,7 @@ DB = Sequel.connect(adapter: $conf.get('database.adapter'), database: $conf.get(
# Base app
class GameData < Sinatra::Base
enable :sessions
# Set up static file serving
@ -21,6 +24,7 @@ class GameData < Sinatra::Base
# Set up our view engine
set :views, File.join(settings.root, '/../views')
end
# Load routes