public function alterStbracket($batches, $allStudents)
 {
     foreach ($batches as $batch) {
         $students = $allStudents[$batch];
         $totalPoor = 0;
         foreach ($students as $student) {
             $results = Studentterm::getOneStbracket($student->studentid);
             $poor = 0;
             foreach ($results as $result) {
                 if (strpos($result->stfapbracket, 'A') !== false || strpos($result->stfapbracket, 'B') !== false || strpos($result->stfapbracket, '8') !== false || strpos($result->stfapbracket, '9') !== false) {
                     $poor = 1;
                 }
             }
             $totalPoor = $totalPoor + $poor;
         }
         $entry = Correlation::where('batch', $batch)->where('unittype', 'campus')->where('factorid', 3)->first();
         $countStudents = count($students);
         if ($countStudents > 0) {
             $entry->ratio = $totalPoor / $countStudents;
         } else {
             $entry->ratio = 0;
         }
         $entry->save();
     }
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::table('correlations', function (Blueprint $table) {
         //
     });
     $entries = Correlation::where('unittype', 'program')->get();
     foreach ($entries as $entry) {
         $batch = $entry->batch;
         $programid = $entry->programid;
         $dropoutsRaw = Studentdropout::getBatchDropoutsProgram($batch * 100000, $programid);
         $shiftsRaw = Studentshift::getBatchShiftsProgram($batch * 100000, $programid);
         $delayedRaw = Studentdelayed::getBatchDelayedProgram($batch * 100000, $programid);
         $studentids = [];
         foreach ($dropoutsRaw as $doRaw) {
             array_push($studentids, $doRaw->studentid);
         }
         foreach ($shiftsRaw as $sRaw) {
             array_push($studentids, $sRaw->studentid);
         }
         foreach ($delayedRaw as $dRaw) {
             array_push($studentids, $dRaw->studentid);
         }
         $studentids = array_values(array_unique($studentids));
         $students = Studentterm::getBatchStudentsCountProgram($batch * 100000, $programid);
         if ($students > 0) {
             $entry->dropouts = count($studentids) / $students;
         } else {
             $entry->dropouts = 0;
         }
         $entry->save();
     }
 }
 public function alterUnits($batches, $allStudents, $programid)
 {
     foreach ($batches as $batch) {
         $students = $allStudents[$batch];
         $totalUnderload = 0;
         $totalNodata = 0;
         foreach ($students as $student) {
             $units = Assessment::getOneAveUnitsProgram($student->studentid, $programid);
             if ($units === -1) {
                 $totalNodata++;
             } else {
                 if ($units < 15) {
                     $totalUnderload++;
                 } else {
                 }
             }
         }
         $entry = Correlation::where('batch', $batch)->where('unittype', 'program')->where('programid', $programid)->where('factorid', 6)->first();
         $countStudents = count($students);
         if ($countStudents - $totalNodata > 0) {
             $entry->ratio = $totalUnderload / ($countStudents - $totalNodata);
         } else {
             $entry->ratio = 0;
         }
         $entry->save();
     }
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::table('correlations', function (Blueprint $table) {
         //
     });
     $entries = Correlation::where('unittype', 'campus')->get();
     foreach ($entries as $entry) {
         $batch = $entry->batch;
         $dropouts = Studentdropout::getBatchDropoutsCount($batch * 100000);
         $delayed = Studentdelayed::getBatchDelayedCount($batch * 100000);
         $students = Studentterm::getBatchStudentsCount($batch * 100000);
         if ($students > 0) {
             $entry->dropouts = ($dropouts + $delayed) / $students;
         } else {
             $entry->dropouts = 0;
         }
         $entry->save();
     }
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::table('correlations', function (Blueprint $table) {
         //
     });
     $departmentlist = Department::whereHas('programs', function ($q) {
         $q->whereNotIn('programid', array(62, 66, 38));
         $q->where('degreelevel', 'U');
     })->get();
     $collegelist = [];
     $departmentids = [];
     foreach ($departmentlist as $department) {
         array_push($collegelist, $department->college);
         array_push($departmentids, $department->unitid);
     }
     $collegelist = array_unique($collegelist);
     $collegeids = [];
     foreach ($collegelist as $college) {
         array_push($collegeids, $college->unitid);
     }
     $entries = Correlation::where('unittype', 'college')->orWhere('unittype', 'department')->get();
     foreach ($entries as $entry) {
         if ($entry->unittype === 'college') {
             $collegeid = $entry->collegeid;
             if (in_array($collegeid, $collegeids)) {
             } else {
                 $entry->delete();
             }
         } elseif ($entry->unittype === 'department') {
             $departmentid = $entry->departmentid;
             if (in_array($departmentid, $departmentids)) {
             } else {
                 $entry->delete();
             }
         } else {
         }
     }
 }