Added ability to add benchmark results to a test

This commit is contained in:
Gregory Ballantine 2025-06-23 18:39:01 -04:00
parent c1da3b6a57
commit 2b5193dccf
4 changed files with 47 additions and 7 deletions

View File

@ -1,5 +1,18 @@
testId = $('#results-table').data('test-id')
$ ->
$('#test-result-form').on 'submit', (e) ->
e.preventDefault()
form = $(this)
formData = $(this).serialize()
benchmarkId = $(this).find('[name="result_benchmark"]').val()
$.post '/api/v1/result/add', formData, (response) ->
if response == 'success'
fetchTestBenchmarkResults(testId, benchmarkId)
form[0].reset()
fetchTestBenchmarkResults = (testId, benchmarkId) ->
try
benchmarkSearchParams = new URLSearchParams
@ -18,12 +31,14 @@ fetchTestBenchmarkResults = (testId, benchmarkId) ->
max_total = 0
for result in resultData
avg_total += result.avg_score
min_total += result.min_score
max_total += result.max_score
avg_total += result.avgScore
min_total += result.minScore
max_total += result.maxScore
tableRow = $("#results-table tr[data-benchmark-id=#{benchmarkId}]")
tableRow.empty()
tableRow.append('<td>' + benchmarkData.name + '</td>')
tableRow.append('<td>' + benchmarkData.scoring + '</td>')
tableRow.append('<td>' + resultData.length + '</td>')

View File

@ -1,5 +1,6 @@
const Benchmark = require('../models').models.Benchmark;
const Result = require('../models').models.Result;
const Test = require('../models').models.Test;
// GET /api/v1/benchmark/details
exports.getBenchmarkDetails = async function(req, res) {
@ -37,3 +38,26 @@ exports.getResultList = async function(req, res) {
});
}
};
// POST /api/v1/result/add - add a benchmark result to the database
exports.postResultAdd = async function(req, res) {
try {
const result = await Result.create({
avgScore: req.body.result_avg,
minScore: req.body.result_min,
maxScore: req.body.result_max
});
let benchmark = await Benchmark.findByPk(req.body.result_benchmark);
result.setBenchmark(benchmark);
let test = await Test.findByPk(req.body.result_test);
result.setTest(test);
res.json('success');
} catch (err) {
res.status(500).json({
error: 'Internal server error occurred while adding result.'
});
}
};

View File

@ -34,5 +34,6 @@ module.exports = function(app) {
// API v1 routes
app.get('/api/v1/benchmark/details', apiv1Routes.getBenchmarkDetails);
app.get('/api/v1/result/list', apiv1Routes.getResultList);
app.post('/api/v1/result/add', apiv1Routes.postResultAdd);
};

View File

@ -10,7 +10,7 @@
<hr>
<div class="row">
<form id="result_form" class="twelve columns" action="/result/add" method="post">
<form id="test-result-form" class="twelve columns" action="/api/v1/result/add" method="post">
<input type="hidden" name="result_test" value="{{ test.id }}">
<div class="row">
@ -28,21 +28,21 @@
<div class="two columns">
<label for="result_avg">
Average:
<input type="number" id="result_avg" class="u-full-width" name="result_avg">
<input type="number" id="result_avg" class="u-full-width" name="result_avg" step="0.01" required>
</label>
</div>
<div class="two columns">
<label for="result_min">
Minimum:
<input type="number" id="result_min" class="u-full-width" name="result_min">
<input type="number" id="result_min" class="u-full-width" name="result_min" step="0.01">
</label>
</div>
<div class="two columns">
<label for="result_max">
Maximum:
<input type="number" id="result_max" class="u-full-width" name="result_max">
<input type="number" id="result_max" class="u-full-width" name="result_max" step="0.01">
</label>
</div>