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' require 'yaml'
# Config - loads and manages the app's configuration
class Config class Config
DEFAULT_CONFIG = 'config/defaults.yaml' DEFAULT_CONFIG = 'config/defaults.yaml'
def initialize(config_path) def initialize(config_path)
@data = YAML::load_file(DEFAULT_CONFIG) @data = YAML.load_file(DEFAULT_CONFIG)
if File.exists?(config_path) # merge in user-defined configuration if it exists
@data.merge!(YAML::load_file(config_path)) @data.merge!(YAML.load_file(config_path)) if File.exist?(config_path)
end
end end
def get(key, depth = 0) def get(key)
bits = key.split('.') bits = key.split('.')
value = @data value = @data

View File

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

View File

@ -1,3 +1,6 @@
# frozen_string_literal: true
# Benchmark - database model for PC benchmarks
class Benchmark < Sequel::Model class Benchmark < Sequel::Model
one_to_many :tests 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) class Hardware < Sequel::Model(:hardware)
one_to_many :tests one_to_many :tests

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,4 +1,8 @@
# frozen_string_literal: true
# /test routes
class GameData < Sinatra::Base class GameData < Sinatra::Base
get '/test' do get '/test' do
tests = Test.reverse(:updated_at).limit(10).all() tests = Test.reverse(:updated_at).limit(10).all()
@ -30,19 +34,16 @@ class GameData < Sinatra::Base
date_tag = params[:test_date_tag] date_tag = params[:test_date_tag]
# make sure the date tag field is formatting properly # make sure the date tag field is formatting properly
unless date_tag.start_with?('(') date_tag = "(#{date_tag}" unless date_tag.start_with?('(')
date_tag = '(' + date_tag date_tag += ')' unless date_tag.end_with?(')')
end
unless date_tag.end_with?(')')
date_tag = date_tag + ')'
end
test = Test.create( test = Test.create(
date_tag: params[:test_date_tag], date_tag: date_tag,
hardware_id: params[:test_hardware], hardware_id: params[:test_hardware],
benchmark_id: params[:test_benchmark] benchmark_id: params[:test_benchmark]
) )
redirect "/test/#{test.id}" redirect "/test/#{test.id}"
end end
end end

View File

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