Added ability to load benchmark results when viewing a test

This commit is contained in:
Gregory Ballantine 2025-06-23 18:05:28 -04:00
parent a83f7e3b0b
commit 175bfa0dfd
5 changed files with 98 additions and 12 deletions

View 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)
)

View File

@ -26,8 +26,4 @@ Benchmark.hasMany(Result);
Result.belongsTo(Test);
Test.hasMany(Result);
// Result/Hardware many-to-one
Result.belongsTo(Hardware);
Hardware.hasMany(Result);
module.exports = sequelize;

39
src/routes/api_v1.js Normal file
View 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.'
});
}
};

View File

@ -3,6 +3,7 @@ const topRoutes = require('./toplevel');
const testRoutes = require('./test');
const hardwareRoutes = require('./hardware');
const benchmarkRoutes = require('./benchmark');
const apiv1Routes = require('./api_v1');
module.exports = function(app) {
@ -30,4 +31,8 @@ module.exports = function(app) {
app.post('/test/add', testRoutes.postAdd);
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);
};

View File

@ -56,10 +56,11 @@
<div class="row">
<div class="twelve columns">
<h3>Benchmarks</h3>
<table class="u-full-width">
<table id="results-table" data-test-id="{{ test.id }}" class="u-full-width">
<thead>
<tr>
<td>Benchmark</td>
<td>Scoring type</td>
<td># Results</td>
<td>Avg.</td>
<td>Min.</td>
@ -68,13 +69,7 @@
</thead>
<tbody>
{% for b in test.getBenchmarks() %}
<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>
<tr data-benchmark-id="{{ b.id }}"></tr>
{% endfor %}
</tbody>
</table>
@ -84,4 +79,6 @@
<p><a href="/test">Back</a></p>
</div>
<script src="/js/test.js" type="text/javascript"></script>
{% endblock %}