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) {
|
foreach ($this->benchmarks as $i => $b) {
|
||||||
$benchmarkResults = $this->results()->where('benchmark_id', $b->id)->get();
|
$benchmarkResults = $this->results()->where('benchmark_id', $b->id)->get();
|
||||||
|
|
||||||
$averageResults = [];
|
if (count($benchmarkResults) > 0) {
|
||||||
$minimumResults = [];
|
$averageResults = [];
|
||||||
$maximumResults = [];
|
$minimumResults = [];
|
||||||
foreach ($benchmarkResults as $r) {
|
$maximumResults = [];
|
||||||
array_push($averageResults, $r->average);
|
foreach ($benchmarkResults as $r) {
|
||||||
array_push($minimumResults, $r->minimum);
|
array_push($averageResults, $r->average);
|
||||||
array_push($maximumResults, $r->maximum);
|
array_push($minimumResults, $r->minimum);
|
||||||
}
|
array_push($maximumResults, $r->maximum);
|
||||||
|
}
|
||||||
|
|
||||||
$data[$i] = [
|
$data[$i] = [
|
||||||
'name' => $b->name,
|
'name' => $b->name,
|
||||||
'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;
|
||||||
|
Loading…
Reference in New Issue
Block a user