diff --git a/assets/scripts/edgeville.coffee b/assets/scripts/edgeville.coffee
index 032348c..853461e 100644
--- a/assets/scripts/edgeville.coffee
+++ b/assets/scripts/edgeville.coffee
@@ -1,2 +1,3 @@
$ ->
+ # run foundation scripts
$(document).foundation()
diff --git a/assets/scripts/test.coffee b/assets/scripts/test.coffee
new file mode 100644
index 0000000..644682f
--- /dev/null
+++ b/assets/scripts/test.coffee
@@ -0,0 +1,49 @@
+testId = $('#results-table').data('test-id')
+
+fetchTestBenchmarkResults = (testId, benchmarkId) ->
+ try
+ benchmarkSearchParams = new URLSearchParams
+ benchmark_id: benchmarkId
+ benchmarkRes = await fetch("/api/v1/benchmark/details?#{benchmarkSearchParams}")
+ benchmarkData = await benchmarkRes.json()
+
+ resultSearchParams = new URLSearchParams
+ test_id: testId
+ benchmark_id: benchmarkId
+ resultRes = await fetch("/api/v1/results?#{resultSearchParams}")
+ resultData = await resultRes.json()
+
+ avg_total = 0
+ min_total = 0
+ max_total = 0
+
+ for result in resultData
+ avg_total += result.avg_score
+ min_total += result.min_score
+ max_total += result.max_score
+
+ tableRow = $("#results-table tr[data-benchmark-id=#{benchmarkId}]")
+
+ tableRow.append('
' + benchmarkData.name + ' | ')
+ tableRow.append('' + benchmarkData.scoring + ' | ')
+ tableRow.append('' + resultData.length + ' | ')
+
+ if resultData.length != 0
+ tableRow.append('' + (avg_total / resultData.length) + ' | ')
+ else
+ tableRow.append('N/a | ')
+
+ if min_total != 0
+ tableRow.append('' + (min_total / resultData.length) + ' | ')
+ tableRow.append('' + (max_total / resultData.length) + ' | ')
+ else
+ tableRow.append('N/a | ')
+ tableRow.append('N/a | ')
+ catch error
+ console.error 'An error occurred while fetching benchmark results.', error
+
+$('#results-table tbody tr').each((index, tr) ->
+ benchmarkId = $(tr).data('benchmark-id')
+ console.log("Fetching results for benchmark id: " + benchmarkId)
+ fetchTestBenchmarkResults(testId, benchmarkId)
+)
diff --git a/src/routes/api1.rb b/src/routes/api1.rb
new file mode 100644
index 0000000..e7e8c53
--- /dev/null
+++ b/src/routes/api1.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+# /api/v1 routes
+class GameData < Sinatra::Base
+
+ get '/api/v1/benchmark/details' do
+ benchmark_id = params[:benchmark_id]
+
+ benchmark = Benchmark.where(id: benchmark_id).first()
+
+ json benchmark.values()
+ end
+
+ get '/api/v1/results' do
+ test_id = params[:test_id]
+ benchmark_id = params[:benchmark_id]
+
+ results = Result.where(test_id: test_id, benchmark_id: benchmark_id).all()
+
+ json results.map(&:values)
+ end
+
+end
diff --git a/src/routes/init.rb b/src/routes/init.rb
index e96f95e..c1158d7 100644
--- a/src/routes/init.rb
+++ b/src/routes/init.rb
@@ -6,3 +6,5 @@ require_relative 'benchmark'
require_relative 'result'
require_relative 'reports'
require_relative 'test'
+
+require_relative 'api1'
diff --git a/src/routes/result.rb b/src/routes/result.rb
index 58f20bd..4331ebc 100644
--- a/src/routes/result.rb
+++ b/src/routes/result.rb
@@ -27,7 +27,7 @@ class GameData < Sinatra::Base
result_maximum = params[:result_maximum] if params.key?(:result_maximum)
Result.create(
- hardware_id: params[:result_hardware],
+ test_id: params[:result_test],
benchmark_id: params[:result_benchmark],
avg_score: params[:result_average],
min_score: result_minimum,
@@ -35,8 +35,8 @@ class GameData < Sinatra::Base
)
if params.key?(:result_referrer)
- if params[:result_referrer] == 'hardware'
- redirect "/hardware/#{params[:result_hardware]}"
+ if params[:result_referrer] == 'test'
+ redirect "/test/#{params[:result_test]}"
elsif params[:result_referrer] == 'benchmark'
redirect "/benchmark/#{params[:result_benchmark]}"
end
diff --git a/src/routes/test.rb b/src/routes/test.rb
index 2cf7685..df97614 100644
--- a/src/routes/test.rb
+++ b/src/routes/test.rb
@@ -40,11 +40,9 @@ class GameData < Sinatra::Base
get '/test/:test_id' do
tst = Test.where(id: params[:test_id]).first()
- benchmarks = Benchmark.order(:name).all()
erb :'test/view', locals: {
title: tst.name,
- test: tst,
- benchmarks: benchmarks
+ test: tst
}
end
diff --git a/views/test/index.erb b/views/test/index.erb
index 520c912..8546a1e 100644
--- a/views/test/index.erb
+++ b/views/test/index.erb
@@ -25,7 +25,7 @@
<% tests.each do |t| %>
- <%= t.name %> |
+ <%= t.name %> |
<%= t.benchmark.length %> |
<%= date_format(t.created_at) %> |
<%= date_format(t.updated_at) %> |
diff --git a/views/test/view.erb b/views/test/view.erb
index 86069dd..1eb9e1d 100644
--- a/views/test/view.erb
+++ b/views/test/view.erb
@@ -21,7 +21,7 @@