Added ability to load benchmark results when viewing a test
This commit is contained in:
parent
a83f7e3b0b
commit
175bfa0dfd
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/result/list?#{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)
|
||||||
|
)
|
@ -26,8 +26,4 @@ Benchmark.hasMany(Result);
|
|||||||
Result.belongsTo(Test);
|
Result.belongsTo(Test);
|
||||||
Test.hasMany(Result);
|
Test.hasMany(Result);
|
||||||
|
|
||||||
// Result/Hardware many-to-one
|
|
||||||
Result.belongsTo(Hardware);
|
|
||||||
Hardware.hasMany(Result);
|
|
||||||
|
|
||||||
module.exports = sequelize;
|
module.exports = sequelize;
|
||||||
|
39
src/routes/api_v1.js
Normal file
39
src/routes/api_v1.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
const Benchmark = require('../models').models.Benchmark;
|
||||||
|
const Result = require('../models').models.Result;
|
||||||
|
|
||||||
|
// GET /api/v1/benchmark/details
|
||||||
|
exports.getBenchmarkDetails = async function(req, res) {
|
||||||
|
try {
|
||||||
|
const benchmark = await Benchmark.findByPk(req.query.benchmark_id);
|
||||||
|
|
||||||
|
if (!benchmark) {
|
||||||
|
return res.status(404).json({
|
||||||
|
error: 'Benchmark not found.'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
res.json(benchmark);
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).json({
|
||||||
|
error: 'Internal server error occurred while fetching benchmark details.'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// GET /api/v1/result/list - list of results for a test
|
||||||
|
exports.getResultList = async function(req, res) {
|
||||||
|
try {
|
||||||
|
var results = await Result.findAll({
|
||||||
|
where: {
|
||||||
|
TestId: req.query.test_id,
|
||||||
|
BenchmarkId: req.query.benchmark_id
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
res.json(results);
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).json({
|
||||||
|
error: 'Internal server error occurred while fetching benchmark results.'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
@ -3,6 +3,7 @@ const topRoutes = require('./toplevel');
|
|||||||
const testRoutes = require('./test');
|
const testRoutes = require('./test');
|
||||||
const hardwareRoutes = require('./hardware');
|
const hardwareRoutes = require('./hardware');
|
||||||
const benchmarkRoutes = require('./benchmark');
|
const benchmarkRoutes = require('./benchmark');
|
||||||
|
const apiv1Routes = require('./api_v1');
|
||||||
|
|
||||||
module.exports = function(app) {
|
module.exports = function(app) {
|
||||||
|
|
||||||
@ -30,4 +31,8 @@ module.exports = function(app) {
|
|||||||
app.post('/test/add', testRoutes.postAdd);
|
app.post('/test/add', testRoutes.postAdd);
|
||||||
app.get('/test/:test_id', testRoutes.getView);
|
app.get('/test/:test_id', testRoutes.getView);
|
||||||
|
|
||||||
|
// API v1 routes
|
||||||
|
app.get('/api/v1/benchmark/details', apiv1Routes.getBenchmarkDetails);
|
||||||
|
app.get('/api/v1/result/list', apiv1Routes.getResultList);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -56,10 +56,11 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="twelve columns">
|
<div class="twelve columns">
|
||||||
<h3>Benchmarks</h3>
|
<h3>Benchmarks</h3>
|
||||||
<table class="u-full-width">
|
<table id="results-table" data-test-id="{{ test.id }}" class="u-full-width">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Benchmark</td>
|
<td>Benchmark</td>
|
||||||
|
<td>Scoring type</td>
|
||||||
<td># Results</td>
|
<td># Results</td>
|
||||||
<td>Avg.</td>
|
<td>Avg.</td>
|
||||||
<td>Min.</td>
|
<td>Min.</td>
|
||||||
@ -68,13 +69,7 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for b in test.getBenchmarks() %}
|
{% for b in test.getBenchmarks() %}
|
||||||
<tr>
|
<tr data-benchmark-id="{{ b.id }}"></tr>
|
||||||
<td>{{ b.name }}</td>
|
|
||||||
<td>{{ test.getResults({where: {testId: test.id}})|length }}</td>
|
|
||||||
<td>N/a</td>
|
|
||||||
<td>N/a</td>
|
|
||||||
<td>N/a</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@ -84,4 +79,6 @@
|
|||||||
|
|
||||||
<p><a href="/test">Back</a></p>
|
<p><a href="/test">Back</a></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script src="/js/test.js" type="text/javascript"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user