public function seedHighGrades($batches, $allStudents, $departmentid) { foreach ($batches as $batch) { $students = $allStudents[$batch]; $totalHigh = 0; foreach ($students as $student) { $gwa = Studentterm::getOneGradesDepartment($student->studentid, $departmentid); if ($gwa > 1.0 || $gwa < 3.0) { $totalHigh++; } } $newCorrelation = new Correlation(); $newCorrelation->factorid = 7; $newCorrelation->batch = $batch; $countStudents = count($students); if ($countStudents > 0) { $newCorrelation->ratio = $totalHigh / $countStudents; } else { $newCorrelation->ratio = 0; } $newCorrelation->unittype = 'department'; $newCorrelation->departmentid = $departmentid; $newCorrelation->save(); } }