public function seedUnits($batches, $allStudents, $departmentid) { foreach ($batches as $batch) { $students = $allStudents[$batch]; $totalUnderload = 0; $totalNodata = 0; foreach ($students as $student) { $units = Assessment::getOneAveUnitsDepartment($student->studentid, $departmentid); if ($units === -1) { $totalNodata++; } else { if ($units < 15) { $totalUnderload++; } else { } } } $newCorrelation = new Correlation(); $newCorrelation->factorid = 6; $newCorrelation->batch = $batch; $countStudents = count($students); if ($countStudents - $totalNodata > 0) { $newCorrelation->ratio = $totalUnderload / ($countStudents - $totalNodata); } else { $newCorrelation->ratio = 0; } $newCorrelation->unittype = 'department'; $newCorrelation->departmentid = $departmentid; $newCorrelation->save(); } }