Fixed division by zero error

This commit is contained in:
Gregory Ballantine 2024-06-03 11:41:30 -04:00
parent acbbbeb74f
commit e0c6e3ef68

View File

@ -30,6 +30,7 @@ class Test extends Model {
foreach ($this->benchmarks as $i => $b) { foreach ($this->benchmarks as $i => $b) {
$benchmarkResults = $this->results()->where('benchmark_id', $b->id)->get(); $benchmarkResults = $this->results()->where('benchmark_id', $b->id)->get();
if (count($benchmarkResults) > 0) {
$averageResults = []; $averageResults = [];
$minimumResults = []; $minimumResults = [];
$maximumResults = []; $maximumResults = [];
@ -44,9 +45,19 @@ class Test extends Model {
'scoring' => $b->scoring, 'scoring' => $b->scoring,
'count' => count($benchmarkResults), 'count' => count($benchmarkResults),
'average' => (array_sum($averageResults) / count($averageResults)), 'average' => (array_sum($averageResults) / count($averageResults)),
'minimum' => (array_sum($minimumResults) / count($minimumResults)), 'minimum' => (array_sum($minimumResults) / count($minimumResults) ? 1),
'maximum' => (array_sum($maximumResults) / count($maximumResults)), 'maximum' => (array_sum($maximumResults) / count($maximumResults)),
]; ];
} else {
$data[$i] = [
'name' => $b->name,
'scoring' => $b->scoring,
'count' => count($benchmarkResults),
'average' => 0,
'minimum' => 0,
'maximum' => 0,
];
}
} }
return $data; return $data;