Converted from coffeescript to javascript for frontend scripts (to much pain)
This commit is contained in:
@ -1,2 +0,0 @@
|
||||
$ ->
|
||||
console.log('Ready.')
|
3
assets/scripts/scar.js
Normal file
3
assets/scripts/scar.js
Normal file
@ -0,0 +1,3 @@
|
||||
$(document).ready(function () {
|
||||
console.log("Ready.");
|
||||
});
|
@ -1,62 +0,0 @@
|
||||
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
|
||||
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.avgScore
|
||||
min_total += result.minScore if result.minScore
|
||||
max_total += result.maxScore if result.maxScore
|
||||
|
||||
tableRow = $("#results-table tr[data-benchmark-id=#{benchmarkId}]")
|
||||
tableRow.empty()
|
||||
|
||||
tableRow.append('<td><a href="/benchmark/' + benchmarkData.id + '">' + benchmarkData.name + '</a></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)
|
82
assets/scripts/test.js
Normal file
82
assets/scripts/test.js
Normal file
@ -0,0 +1,82 @@
|
||||
const testId = $("#results-table").data("test-id");
|
||||
|
||||
$(function () {
|
||||
$("#test-result-form").on("submit", function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
const form = $(this);
|
||||
const formData = form.serialize();
|
||||
const benchmarkId = form.find('[name="result_benchmark"]').val();
|
||||
|
||||
$.post("/api/v1/result/add", formData, function (response) {
|
||||
if (response === "success") {
|
||||
fetchTestBenchmarkResults(testId, benchmarkId);
|
||||
form[0].reset();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
async function fetchTestBenchmarkResults(testId, benchmarkId) {
|
||||
try {
|
||||
const benchmarkSearchParams = new URLSearchParams({
|
||||
benchmark_id: benchmarkId,
|
||||
});
|
||||
const benchmarkRes = await fetch(
|
||||
`/api/v1/benchmark/details?${benchmarkSearchParams}`,
|
||||
);
|
||||
const benchmarkData = await benchmarkRes.json();
|
||||
|
||||
const resultSearchParams = new URLSearchParams({
|
||||
test_id: testId,
|
||||
benchmark_id: benchmarkId,
|
||||
});
|
||||
const resultRes = await fetch(`/api/v1/result/list?${resultSearchParams}`);
|
||||
const resultData = await resultRes.json();
|
||||
|
||||
let avg_total = 0;
|
||||
let min_total = 0;
|
||||
let max_total = 0;
|
||||
|
||||
for (const result of resultData) {
|
||||
avg_total += result.avgScore;
|
||||
if (result.minScore !== undefined) min_total += result.minScore;
|
||||
if (result.maxScore !== undefined) max_total += result.maxScore;
|
||||
}
|
||||
|
||||
const tableRow = $(`#results-table tr[data-benchmark-id=${benchmarkId}]`);
|
||||
tableRow.empty();
|
||||
|
||||
tableRow.append(
|
||||
'<td><a href="/benchmark/' +
|
||||
benchmarkData.id +
|
||||
'">' +
|
||||
benchmarkData.name +
|
||||
"</a></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(function (index, tr) {
|
||||
const benchmarkId = $(tr).data("benchmark-id");
|
||||
console.log("Fetching results for benchmark id: " + benchmarkId);
|
||||
fetchTestBenchmarkResults(testId, benchmarkId);
|
||||
});
|
Reference in New Issue
Block a user