public function UpdateCurrentRank(Course $course, Comment $comment) { $c = $course->comments; $total_comment = $course->comments->count(); $teach = $comment->teach_q; $time = $comment->time_c; $sign = $comment->sign_d; $test = $comment->test_d; $homework = $comment->homework_d; $grade = $comment->grade_d; $TA = $comment->TA_r; $practical = $comment->practical_r; $roll = $comment->rollCall_r; $nutrition = $comment->nutrition_r; $Pasitive = $teach + $practical + $TA + $nutrition; $Negative = $test + $homework + $grade + $time + $roll + $sign; $test = 100 - $test; $homework = 100 - $homework; $grade = 100 - $grade; $time = 100 - $time; $roll = 100 - $roll; $sign = 100 - $sign; $total = ($Pasitive + $test + $homework + $grade + $time + $sign + $roll) / 100; // If Negative == Pasitive, current_rank won't be changed $rank = $course->current_rank; if ($Negative > $Pasitive * 1.5) { $rank -= $total; } else { if ($Negative < $Pasitive * 1.5) { $rank += $total; } } $course->current_rank = $rank; $course->teach_quality = ($c->sum('teach_q') + 50) / ($total_comment + 1); $course->time_cost = ($c->sum('time_c') + 50) / ($total_comment + 1); $course->sign_dif = ($c->sum('sign_d') + 50) / ($total_comment + 1); $course->test_dif = ($c->sum('test_d') + 50) / ($total_comment + 1); $course->homework_dif = ($c->sum('homework_d') + 50) / ($total_comment + 1); $course->grade_dif = ($c->sum('grade_d') + 50) / ($total_comment + 1); $course->TA_rank = ($c->sum('TA_r') + 50) / ($total_comment + 1); $course->practical_rank = ($c->sum('practical_r') + 50) / ($total_comment + 1); $course->roll_freq = ($c->sum('rollCall_r') + 50) / ($total_comment + 1); $course->nutrition_rank = ($c->sum('nutrition_r') + 50) / ($total_comment + 1); $course->judge_people = $total_comment; $course->save(); }