Added functionality to add a benchmark result
This commit is contained in:
		| @@ -1,6 +1,6 @@ | ||||
| class Result < Sequel::Model | ||||
|  | ||||
|   many_to_one :hardware | ||||
|   many_to_one :benchmarks | ||||
|   many_to_one :benchmark | ||||
|  | ||||
| end | ||||
|   | ||||
| @@ -1,3 +1,4 @@ | ||||
| require_relative 'index' | ||||
| require_relative 'hardware' | ||||
| require_relative 'benchmark' | ||||
| require_relative 'result' | ||||
|   | ||||
							
								
								
									
										36
									
								
								src/routes/result.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								src/routes/result.rb
									
									
									
									
									
										Normal 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 | ||||
		Reference in New Issue
	
	Block a user