Fixed division by zero error
This commit is contained in:
parent
acbbbeb74f
commit
e0c6e3ef68
@ -30,23 +30,34 @@ class Test extends Model {
|
||||
foreach ($this->benchmarks as $i => $b) {
|
||||
$benchmarkResults = $this->results()->where('benchmark_id', $b->id)->get();
|
||||
|
||||
$averageResults = [];
|
||||
$minimumResults = [];
|
||||
$maximumResults = [];
|
||||
foreach ($benchmarkResults as $r) {
|
||||
array_push($averageResults, $r->average);
|
||||
array_push($minimumResults, $r->minimum);
|
||||
array_push($maximumResults, $r->maximum);
|
||||
}
|
||||
if (count($benchmarkResults) > 0) {
|
||||
$averageResults = [];
|
||||
$minimumResults = [];
|
||||
$maximumResults = [];
|
||||
foreach ($benchmarkResults as $r) {
|
||||
array_push($averageResults, $r->average);
|
||||
array_push($minimumResults, $r->minimum);
|
||||
array_push($maximumResults, $r->maximum);
|
||||
}
|
||||
|
||||
$data[$i] = [
|
||||
'name' => $b->name,
|
||||
'scoring' => $b->scoring,
|
||||
'count' => count($benchmarkResults),
|
||||
'average' => (array_sum($averageResults) / count($averageResults)),
|
||||
'minimum' => (array_sum($minimumResults) / count($minimumResults)),
|
||||
'maximum' => (array_sum($maximumResults) / count($maximumResults)),
|
||||
];
|
||||
$data[$i] = [
|
||||
'name' => $b->name,
|
||||
'scoring' => $b->scoring,
|
||||
'count' => count($benchmarkResults),
|
||||
'average' => (array_sum($averageResults) / count($averageResults)),
|
||||
'minimum' => (array_sum($minimumResults) / count($minimumResults) ? 1),
|
||||
'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;
|
||||
|
Loading…
Reference in New Issue
Block a user