diff --git a/assets/scripts/edgeville.coffee b/assets/scripts/edgeville.coffee index 7eda933..2887d5b 100644 --- a/assets/scripts/edgeville.coffee +++ b/assets/scripts/edgeville.coffee @@ -1,3 +1,21 @@ $ -> # run foundation scripts console.log('Ready.') + +averageResults = (results, decimals = 2) -> + avgScore = 0 + minScore = Infinity + maxScore = -Infinity + + factor = (10 ^ decimals) + + for result in results + avgScore += result.avg_score + minScore = Math.min(minScore, result.min_score) + maxScore = Math.max(maxScore, result.max_score) + + return { + avgScore: Math.round((avgScore / results.length) * factor) / factor, + minScore: minScore, + maxScore: maxScore, + } diff --git a/assets/scripts/reports.coffee b/assets/scripts/reports.coffee index c6a1e86..8e38122 100644 --- a/assets/scripts/reports.coffee +++ b/assets/scripts/reports.coffee @@ -67,21 +67,14 @@ $ -> 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 if result.min_score - max_total += result.max_score if result.max_score + resultAverage = averageResults(resultData) data.labels.push(testData.name) - data.datasets[0].data.push(avg_total / resultData.length) + data.datasets[0].data.push(resultAverage.avgScore) console.log(data.datasets[0].data) switch benchmarkData.scoring when 'fps', 'ms' - data.datasets[1].data.push(min_total / resultData.length) + data.datasets[1].data.push(resultAverage.minScore) catch error console.error 'An error occurred while fetching benchmark results.', error diff --git a/assets/scripts/test.coffee b/assets/scripts/test.coffee index 5e69e21..4c91865 100644 --- a/assets/scripts/test.coffee +++ b/assets/scripts/test.coffee @@ -13,14 +13,7 @@ fetchTestBenchmarkResults = (testId, 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 + resultAverage = averageResults(resultData) tableRow = $("#results-table tr[data-benchmark-id=#{benchmarkId}]") @@ -29,14 +22,16 @@ fetchTestBenchmarkResults = (testId, benchmarkId) -> tableRow.append('