Added API routes to provide some information for JS; added CoffeeScript to grab benchmark results for a test
This commit is contained in:
@ -1,2 +1,3 @@
|
|||||||
$ ->
|
$ ->
|
||||||
|
# run foundation scripts
|
||||||
$(document).foundation()
|
$(document).foundation()
|
||||||
|
49
assets/scripts/test.coffee
Normal file
49
assets/scripts/test.coffee
Normal file
@ -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('<td>' + benchmarkData.name + '</td>')
|
||||||
|
tableRow.append('<td>' + benchmarkData.scoring + '</td>')
|
||||||
|
tableRow.append('<td>' + resultData.length + '</td>')
|
||||||
|
|
||||||
|
if resultData.length != 0
|
||||||
|
tableRow.append('<td>' + (avg_total / resultData.length) + '</td>')
|
||||||
|
else
|
||||||
|
tableRow.append('<td>N/a</td>')
|
||||||
|
|
||||||
|
if min_total != 0
|
||||||
|
tableRow.append('<td>' + (min_total / resultData.length) + '</td>')
|
||||||
|
tableRow.append('<td>' + (max_total / resultData.length) + '</td>')
|
||||||
|
else
|
||||||
|
tableRow.append('<td>N/a</td>')
|
||||||
|
tableRow.append('<td>N/a</td>')
|
||||||
|
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)
|
||||||
|
)
|
23
src/routes/api1.rb
Normal file
23
src/routes/api1.rb
Normal file
@ -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
|
@ -6,3 +6,5 @@ require_relative 'benchmark'
|
|||||||
require_relative 'result'
|
require_relative 'result'
|
||||||
require_relative 'reports'
|
require_relative 'reports'
|
||||||
require_relative 'test'
|
require_relative 'test'
|
||||||
|
|
||||||
|
require_relative 'api1'
|
||||||
|
@ -27,7 +27,7 @@ class GameData < Sinatra::Base
|
|||||||
result_maximum = params[:result_maximum] if params.key?(:result_maximum)
|
result_maximum = params[:result_maximum] if params.key?(:result_maximum)
|
||||||
|
|
||||||
Result.create(
|
Result.create(
|
||||||
hardware_id: params[:result_hardware],
|
test_id: params[:result_test],
|
||||||
benchmark_id: params[:result_benchmark],
|
benchmark_id: params[:result_benchmark],
|
||||||
avg_score: params[:result_average],
|
avg_score: params[:result_average],
|
||||||
min_score: result_minimum,
|
min_score: result_minimum,
|
||||||
@ -35,8 +35,8 @@ class GameData < Sinatra::Base
|
|||||||
)
|
)
|
||||||
|
|
||||||
if params.key?(:result_referrer)
|
if params.key?(:result_referrer)
|
||||||
if params[:result_referrer] == 'hardware'
|
if params[:result_referrer] == 'test'
|
||||||
redirect "/hardware/#{params[:result_hardware]}"
|
redirect "/test/#{params[:result_test]}"
|
||||||
elsif params[:result_referrer] == 'benchmark'
|
elsif params[:result_referrer] == 'benchmark'
|
||||||
redirect "/benchmark/#{params[:result_benchmark]}"
|
redirect "/benchmark/#{params[:result_benchmark]}"
|
||||||
end
|
end
|
||||||
|
@ -40,11 +40,9 @@ class GameData < Sinatra::Base
|
|||||||
|
|
||||||
get '/test/:test_id' do
|
get '/test/:test_id' do
|
||||||
tst = Test.where(id: params[:test_id]).first()
|
tst = Test.where(id: params[:test_id]).first()
|
||||||
benchmarks = Benchmark.order(:name).all()
|
|
||||||
erb :'test/view', locals: {
|
erb :'test/view', locals: {
|
||||||
title: tst.name,
|
title: tst.name,
|
||||||
test: tst,
|
test: tst
|
||||||
benchmarks: benchmarks
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<% tests.each do |t| %>
|
<% tests.each do |t| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="/hardware/<%= t.id %>"><%= t.name %></a></td>
|
<td><a href="/test/<%= t.id %>"><%= t.name %></a></td>
|
||||||
<td><%= t.benchmark.length %></td>
|
<td><%= t.benchmark.length %></td>
|
||||||
<td><%= date_format(t.created_at) %></td>
|
<td><%= date_format(t.created_at) %></td>
|
||||||
<td><%= date_format(t.updated_at) %></td>
|
<td><%= date_format(t.updated_at) %></td>
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
<div class="grix-x grix-margin-x">
|
<div class="grix-x grix-margin-x">
|
||||||
<div class="cell small-12">
|
<div class="cell small-12">
|
||||||
<form class="u-full-width" action="/result/add" method="post">
|
<form class="u-full-width" action="/result/add" method="post">
|
||||||
<input type="hidden" name="result_hardware" value="<%= test.id %>">
|
<input type="hidden" name="result_test" value="<%= test.id %>">
|
||||||
<input type="hidden" name="result_referrer" value="test">
|
<input type="hidden" name="result_referrer" value="test">
|
||||||
|
|
||||||
<div class="grid-x grid-margin-x">
|
<div class="grid-x grid-margin-x">
|
||||||
@ -67,18 +67,25 @@
|
|||||||
|
|
||||||
<h4>Benchmark results for this test:</h4>
|
<h4>Benchmark results for this test:</h4>
|
||||||
|
|
||||||
<table>
|
<table id="results-table" data-test-id="<%= test.id %>">
|
||||||
<thead>
|
<thead>
|
||||||
<th>Benchmark name</th>
|
<tr>
|
||||||
<th>Scoring type</th>
|
<th>Benchmark name</th>
|
||||||
<th># results</th>
|
<th>Scoring type</th>
|
||||||
<th>Average</th>
|
<th># results</th>
|
||||||
<th>Minimum</th>
|
<th>Average</th>
|
||||||
<th>Maximum</th>
|
<th>Minimum</th>
|
||||||
|
<th>Maximum</th>
|
||||||
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
<% test.benchmark.each do |benchmark| %>
|
||||||
|
<tr data-benchmark-id="<%= benchmark.id %>"></tr>
|
||||||
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- load test data fetching functionality -->
|
||||||
|
<script src="/js/test.js" charset="utf-8"></script>
|
||||||
|
Reference in New Issue
Block a user