public function getStudentsAllInfoEachSection($examinations_id, $sections_id) { // get all students in the section $studentsIds = User::getStudentBySection($sections_id); // // //get all above students transcripts in the examinations. // $transcripts = DB::table('transcripts')->where('examination_id', '=', $examinations_id) // ->whereIn('users_id', '=', $studentsId)->get(); // DB::table('transcripts') // ->join('users', 'transcripts.users_id', '=', 'users.id') // ->join('examinations', 'transcripts.examinations_id', '=', 'examinations.id') // ->get(); // $students = DB::table('users')->whereIn('id', '=', $studentsIds)->get(); $section = Section::find($sections_id); $examination = Examination::find($examinations_id); $examinationArray = array(); $examinationArray['name'] = $examination->name; if ($examination->semester == 1) { $examinationArray['semester'] = '第一学期'; } elseif ($examination->semester == 2) { $examinationArray['semester'] = '第二学期'; } elseif ($examination->semester == 3) { $examinationArray['semester'] = '小学期'; } else { $examinationArray['semester'] = '其他'; } if ($examination->type == 1) { $examinationArray['type'] = '期末考试'; } elseif ($examination->type == 2) { $examinationArray['type'] = '期中考试'; } elseif ($examination->type == 3) { $examinationArray['type'] = '月考'; } else { $examinationArray['type'] = '普通考试'; } $examinationArray['date'] = $examination->date; $arrayStudentScores = array(); $i = 0; // 这个班级的最大总分 $maxTotalScore = Transcript::getMaxTotalScores($studentsIds); // dd($maxTotalScore); foreach ($studentsIds as $studentsId) { $student = User::findOrFail($studentsId); $arrayStudentScores[$i]['student_id'] = $student->id; $arrayStudentScores[$i]['student_name'] = $student->realname; $arrayStudentScores[$i]['student_realName'] = $student->realname; $transcript = Transcript::where('users_id', '=', $student->id)->where('examinations_id', '=', $examinations_id)->first(); // dd($transcript); $arrayStudentScores[$i]['total'] = $transcript->total; $subjects = Subject::where('transcripts_id', '=', $transcript->id)->get(); foreach ($subjects as $subject) { $subjectType = $subject->type; if ($subjectType == 1) { $arrayStudentScores[$i]['chinese'] = $subject->score; } elseif ($subjectType == 2) { $arrayStudentScores[$i]['math'] = $subject->score; } elseif ($subjectType == 3) { $arrayStudentScores[$i]['english'] = $subject->score; } elseif ($subjectType == 4) { $arrayStudentScores[$i]['physics'] = $subject->score; } elseif ($subjectType == 5) { $arrayStudentScores[$i]['biology'] = $subject->score; } elseif ($subjectType == 6) { $arrayStudentScores[$i]['chemistry'] = $subject->score; } elseif ($subjectType == 7) { $arrayStudentScores[$i]['history'] = $subject->score; } elseif ($subjectType == 8) { $arrayStudentScores[$i]['politics'] = $subject->score; } else { $arrayStudentScores[$i]['geography'] = $subject->score; } } // 得到与最高分的分差 $arrayStudentScores[$i]['pointDifference'] = $maxTotalScore - $transcript->total; $transcript = Transcript::where('users_id', '=', $studentsId)->where('examinations_id', '=', $examinations_id)->first(); $arrayStudentScores[$i]['ranking'] = $transcript->rank; $i++; } // dd($arrayStudentScores); // 使用ranking进行排序 /* * 下面是对该班成绩的分析*/ // 该班级的该次考试的总和各科平均分 $examAverages = array(); $examAverages['totalAve'] = 0; $examAverages['chineseAve'] = 0; $examAverages['mathAve'] = 0; $examAverages['englishAve'] = 0; $examAverages['physicsAve'] = 0; $examAverages['biologyAve'] = 0; $examAverages['chemistryAve'] = 0; $examAverages['historyAve'] = 0; $examAverages['politicsAve'] = 0; $examAverages['geographyAve'] = 0; $count = 0; // 该次考试各科成绩中第一名,最后一名,平均分,中位数分析比较 $bestStudent = $arrayStudentScores[0]; $worstStudent = $arrayStudentScores[0]; $middleStudent = $arrayStudentScores[0]; $length = sizeof($arrayStudentScores); $halfLength = round($length / 2); // dd($halfLength); foreach ($arrayStudentScores as $studentExamScores) { $examAverages['totalAve'] += $studentExamScores['total']; $examAverages['chineseAve'] += $studentExamScores['chinese']; $examAverages['mathAve'] += $studentExamScores['math']; $examAverages['englishAve'] += $studentExamScores['english']; $examAverages['physicsAve'] += $studentExamScores['physics']; $examAverages['biologyAve'] += $studentExamScores['biology']; $examAverages['chemistryAve'] += $studentExamScores['chemistry']; $examAverages['historyAve'] += $studentExamScores['history']; $examAverages['politicsAve'] += $studentExamScores['politics']; $examAverages['geographyAve'] += $studentExamScores['geography']; $count++; //the best performance student if ($studentExamScores['ranking'] < $bestStudent['ranking']) { $bestStudent = $studentExamScores; } // the worst performance student if ($studentExamScores['ranking'] > $worstStudent['ranking']) { $worstStudent = $studentExamScores; } if ($studentExamScores['ranking'] == $halfLength) { $middleStudent = $studentExamScores; } } $examAverages['totalAve'] /= $count; $examAverages['chineseAve'] /= $count; $examAverages['mathAve'] /= $count; $examAverages['englishAve'] /= $count; $examAverages['physicsAve'] /= $count; $examAverages['biologyAve'] /= $count; $examAverages['chemistryAve'] /= $count; $examAverages['historyAve'] /= $count; $examAverages['politicsAve'] /= $count; $examAverages['geographyAve'] /= $count; // end该班级的该次考试的总和各科平均分 // 该次考试各科成绩中第一名,最后一名,平均分,中位数分析比较 // the best student // the worst student // the middle student // end该次考试各科成绩中第一名,最后一名,平均分,中位数分析比较 return view('scores.analyseSectionPerformance', compact('examinationArray', 'arrayStudentScores', 'section', 'examAverages', 'bestStudent', 'worstStudent', 'middleStudent')); }