public static function getStudentBySection($section_id) { // dd($section_id); $studentsIncludingTeacherIds = TeachingSection::where('sections_id', '=', $section_id)->lists('users_id'); $studentsId = DB::table('users')->where('role', '=', '1')->whereIn('id', $studentsIncludingTeacherIds)->lists('id'); // dd('------------------'); // dd($studentsId); return $studentsId; }
public function analyseStudentPerformance($studentId) { $student = User::find($studentId); $studentTeachingSection = TeachingSection::where('users_id', '=', $studentId)->first(); // dd($studentTeachingSection); $studentSection = Section::find($studentTeachingSection->sections_id); $studentArray = array(); $studentArray['name'] = $student->name; $studentArray['realname'] = $student->realname; $studentArray['grade'] = $studentSection->grade; $studentArray['order'] = $studentSection->order; // a table show all exminations the student has token // show the different table of different subjects. $allTranscripts = Transcript::where('users_id', '=', $studentId)->get(); // dd($allTranscripts); $studentExaminations = array(); $i = 0; foreach ($allTranscripts as $transcript) { /*对该成绩单的学生的每次考试的语文,数学,英语三科的排名*/ $studentExaminations[$i]['chineseRanking'] = Transcript::getStudentSubjectRanking($transcript, 1); $studentExaminations[$i]['mathRanking'] = Transcript::getStudentSubjectRanking($transcript, 2); $studentExaminations[$i]['englishRanking'] = Transcript::getStudentSubjectRanking($transcript, 3); $examination = Examination::find($transcript->examinations_id); $studentExaminations[$i]['examination_name'] = $examination->name; $studentExaminations[$i]['examination_semester'] = $examination->semester; $studentExaminations[$i]['examination_date'] = $examination->date; $studentExaminations[$i]['total'] = $transcript->total; $studentExaminations[$i]['rank'] = $transcript->rank; $subjects = Subject::where('transcripts_id', '=', $transcript->id)->get(); foreach ($subjects as $subject) { $subjectType = $subject->type; if ($subjectType == 1) { $studentExaminations[$i]['chinese'] = $subject->score; } elseif ($subjectType == 2) { $studentExaminations[$i]['math'] = $subject->score; } elseif ($subjectType == 3) { $studentExaminations[$i]['english'] = $subject->score; } elseif ($subjectType == 4) { $studentExaminations[$i]['physics'] = $subject->score; } elseif ($subjectType == 5) { $studentExaminations[$i]['biology'] = $subject->score; } elseif ($subjectType == 6) { $studentExaminations[$i]['chemistry'] = $subject->score; } elseif ($subjectType == 7) { $studentExaminations[$i]['history'] = $subject->score; } elseif ($subjectType == 8) { $studentExaminations[$i]['politics'] = $subject->score; } else { $studentExaminations[$i]['geography'] = $subject->score; } } $i++; } //dd($studentExaminations); return view('scores.analyseStudentPerformance', compact('studentArray', 'studentExaminations')); }
public static function getStudentSubjectRanking($currenttranscript, $subjectType) { $rank = 1; // 第一步: 找到该场考试 $examId = $currenttranscript->examinations_id; // 第二步: 找到和当前用户是属于一个班级的其他同学 $section = TeachingSection::where('users_id', '=', $currenttranscript->users_id)->first(); $sectionId = $section->sections_id; // dd($sectionId); $allStudentsIdsSameSection = User::getStudentBySection($sectionId); // 第三步: 找到同班同学的所有成绩单 $allTranscriptsSameExamSameSection = DB::table('transcripts')->where('examinations_id', '=', $examId)->whereIn('users_id', $allStudentsIdsSameSection)->get(); // 本身的指定某科 $currentSubject = Subject::where('type', '=', $subjectType)->where('transcripts_id', '=', $currenttranscript->id)->first(); foreach ($allTranscriptsSameExamSameSection as $transcript) { // 找到该成绩单上指定课程分数,并比较 $subject = Subject::where('type', '=', $subjectType)->where('transcripts_id', '=', $transcript->id)->first(); if ($subject->score > $currentSubject->score) { $rank++; } } return $rank; }
public function saveStudentSubject(Request $request) { $transcriptId = $request->input('transcriptId'); $transcript = Transcript::find($transcriptId); $chineseScore = $request->input('chinese'); $newSubject1 = new Subject(); $newSubject1->score = $chineseScore; $newSubject1->type = 1; $newSubject1->transcripts_id = $transcriptId; $newSubject1->save(); $transcript->total += $chineseScore; $transcript->save(); $mathScore = $request->input('math'); $newSubject2 = new Subject(); $newSubject2->score = $mathScore; $newSubject2->type = 2; $newSubject2->transcripts_id = $transcriptId; $newSubject2->save(); $transcript->total += $mathScore; $transcript->save(); $englishScore = $request->input('english'); $newSubject3 = new Subject(); $newSubject3->score = $englishScore; $newSubject3->type = 3; $newSubject3->transcripts_id = $transcriptId; $newSubject3->save(); $transcript->total += $englishScore; $transcript->save(); // 理科三门 if ($request->has('physics')) { $physicsScore = $request->input('physics'); $newSubject4 = new Subject(); $newSubject4->score = $physicsScore; $newSubject4->type = 4; $newSubject4->transcripts_id = $transcriptId; $newSubject4->save(); $transcript->total += $physicsScore; $transcript->save(); } if ($request->has('biology')) { $biologyScore = $request->input('biology'); $newSubject4 = new Subject(); $newSubject4->score = $biologyScore; $newSubject4->type = 5; $newSubject4->transcripts_id = $transcriptId; $newSubject4->save(); $transcript->total += $biologyScore; $transcript->save(); } if ($request->has('chemistry')) { $chemistryScore = $request->input('chemistry'); $newSubject5 = new Subject(); $newSubject5->score = $chemistryScore; $newSubject5->type = 6; $newSubject5->transcripts_id = $transcriptId; $newSubject5->save(); $transcript->total += $chemistryScore; $transcript->save(); } // 文科三门 if ($request->has('history')) { $historyScore = $request->input('history'); $newSubject6 = new Subject(); $newSubject6->score = $historyScore; $newSubject6->type = 7; $newSubject6->transcripts_id = $transcriptId; $newSubject6->save(); $transcript->total += $historyScore; $transcript->save(); } if ($request->has('politics')) { $politicsScore = $request->input('politics'); $newSubject7 = new Subject(); $newSubject7->score = $politicsScore; $newSubject7->type = 8; $newSubject7->transcripts_id = $transcriptId; $newSubject7->save(); $transcript->total += $politicsScore; $transcript->save(); } if ($request->has('geography')) { $geographyScore = $request->input('geography'); $newSubject8 = new Subject(); $newSubject8->score = $geographyScore; $newSubject8->type = 9; $newSubject8->transcripts_id = $transcriptId; $newSubject8->save(); $transcript->total += $geographyScore; $transcript->save(); } // 班级排名算法 $noRanking = 1; $previousTranscripts = Transcript::where('examinations_id', '=', $transcript->examinations_id)->get(); foreach ($previousTranscripts as $previousTranscript) { // 第一步: 判断该transcription的主人是否和本学生属于同一个班级 $previousStudentSectionId = TeachingSection::where('users_id', '=', $previousTranscript->users_id)->select('sections_id')->get(); $currentStudentSectionId = TeachingSection::where('users_id', '=', $transcript->users_id)->select('sections_id')->get(); if ($previousStudentSectionId == $currentStudentSectionId) { //第二步: 如果他们同一个班级, 并且总分比本学生的总分高的话, 就往后排一名 if ($previousTranscript->total > $transcript->total) { $noRanking++; } } } $transcript->rank = $noRanking; $transcript->save(); // end班级排名算法 // 将两个变量从session中取出, 并得到, 然后将这两个变量传送到一个controller的action中, 以便能够返回到之前这次新建考试的所教班级的所有学生页面中 /* if (Session::has('newExamination')) { $newExamination = Session::get('newExamination'); } if (Session::has('allStudentsAllSections')) { $allStudentsAllSections = Session::get('allStudentsAllSections'); }*/ return redirect()->action('ExaminationController@returnAllSectionsEachTestPage'); // return redirect()->route('profile', [1]); // return Redirect::back(); // flash()->overlay('老师你好,已经成功记录该班级的学生成绩', '成功'); // return view('dashboard.dashboard'); // return redirect('/createNewTest'); // return Redirect::intended('/'); // return Redirect::action('ExaminationController@createNewTest'); // YourController@store /* if (Session::has('backUrl')) { Session::keep('backUrl'); } return ($url = Session::get('backUrl')) ? Redirect::to($url) : Redirect::view('/dashboard'); // : Redirect::route('any.named.route');*/ }
public function forecastStudentFuturePerformance($studentId) { $student = User::find($studentId); // 这部分工作和CheckStudentController的中 analyseStudentPerformance 方法是一样, code取自该方法 $studentTeachingSection = TeachingSection::where('users_id', '=', $studentId)->first(); // dd($studentTeachingSection); $studentSection = Section::find($studentTeachingSection->sections_id); $studentArray = array(); $studentArray['name'] = $student->name; $studentArray['realname'] = $student->realname; $studentArray['grade'] = $studentSection->grade; $studentArray['order'] = $studentSection->order; $allTranscripts = Transcript::where('users_id', '=', $studentId)->get(); // 该学生的全部考试考试的所有各种平均分 $studentAllPreExamsAve = array(); $studentAllPreExamsAve['totalAve'] = 0; $studentAllPreExamsAve['rankingAve'] = 0; $studentAllPreExamsAve['chineseAve'] = 0; $studentAllPreExamsAve['mathAve'] = 0; $studentAllPreExamsAve['englishAve'] = 0; $studentAllPreExamsAve['physicsAve'] = 0; $studentAllPreExamsAve['biologyAve'] = 0; $studentAllPreExamsAve['chemistryAve'] = 0; $studentAllPreExamsAve['historyAve'] = 0; $studentAllPreExamsAve['geographyAve'] = 0; $studentAllPreExamsAve['politicsAve'] = 0; $count = 0; $previousTotalAndRankingArray = []; foreach ($allTranscripts as $transcript) { $examination = Examination::find($transcript->examinations_id); $tampTotalAndRankingArray = [floatval($transcript->total), floatval($transcript->rank), 1]; $previousTotalAndRankingArray[$count] = $tampTotalAndRankingArray; /* $previousTotalAndRankingArray[$count]['total'] = $transcript->total; $previousTotalAndRankingArray[$count]['rank'] = $transcript->rank; $previousTotalAndRankingArray[$count]['ballSize'] = 10;*/ $studentAllPreExamsAve['totalAve'] += $transcript->total; $studentAllPreExamsAve['rankingAve'] += $transcript->rank; $subjects = Subject::where('transcripts_id', '=', $transcript->id)->get(); foreach ($subjects as $subject) { $subjectType = $subject->type; if ($subjectType == 1) { $studentAllPreExamsAve['chineseAve'] += $subject->score; } elseif ($subjectType == 2) { $studentAllPreExamsAve['mathAve'] += $subject->score; } elseif ($subjectType == 3) { $studentAllPreExamsAve['englishAve'] += $subject->score; } elseif ($subjectType == 4) { $studentAllPreExamsAve['physicsAve'] += $subject->score; } elseif ($subjectType == 5) { $studentAllPreExamsAve['biologyAve'] += $subject->score; } elseif ($subjectType == 6) { $studentAllPreExamsAve['chemistryAve'] += $subject->score; } elseif ($subjectType == 7) { $studentAllPreExamsAve['historyAve'] += $subject->score; } elseif ($subjectType == 8) { $studentAllPreExamsAve['politicsAve'] += $subject->score; } else { $studentAllPreExamsAve['geographyAve'] += $subject->score; } } $count++; } $studentAllPreExamsAve['totalAve'] /= $count; $studentAllPreExamsAve['rankingAve'] = round($studentAllPreExamsAve['rankingAve'] / $count); $studentAllPreExamsAve['chineseAve'] /= $count; $studentAllPreExamsAve['mathAve'] /= $count; $studentAllPreExamsAve['englishAve'] /= $count; $studentAllPreExamsAve['physicsAve'] /= $count; $studentAllPreExamsAve['biologyAve'] /= $count; $studentAllPreExamsAve['chemistryAve'] /= $count; $studentAllPreExamsAve['historyAve'] /= $count; $studentAllPreExamsAve['politicsAve'] /= $count; $studentAllPreExamsAve['geographyAve'] /= $count; $studentAllPreExamsAveData = [$studentAllPreExamsAve['chineseAve'], $studentAllPreExamsAve['mathAve'], $studentAllPreExamsAve['englishAve'], $studentAllPreExamsAve['physicsAve'], $studentAllPreExamsAve['biologyAve'], $studentAllPreExamsAve['chemistryAve'], $studentAllPreExamsAve['historyAve'], $studentAllPreExamsAve['politicsAve'], $studentAllPreExamsAve['geographyAve']]; // end该学生的全部考试考试的所有各种平均分 // 对下次考试的预测 $forecastNextExam = array(); // 调用测试算法,对下次考试预测 $forecastNextExam['total'] = 862; $forecastNextExam['ranking'] = 1; $forecastNextExam['chinese'] = 108; $forecastNextExam['math'] = 117; $forecastNextExam['english'] = 77; $forecastNextExam['physics'] = 74; $forecastNextExam['biology'] = 80; $forecastNextExam['chemistry'] = 78; $forecastNextExam['history'] = 71; $forecastNextExam['politics'] = 82; $forecastNextExam['geography'] = 78; $forecastNextExamData = [$forecastNextExam['chinese'], $forecastNextExam['math'], $forecastNextExam['english'], $forecastNextExam['physics'], $forecastNextExam['biology'], $forecastNextExam['chemistry'], $forecastNextExam['history'], $forecastNextExam['politics'], $forecastNextExam['geography']]; // dd($studentArray); // dd($studentAllPreExamsAve); // dd($forecastNextExam); // 对之前所有考试的总分和排名, 平均排名和 未来排名 $averageTotalAndRankingArray = [[$studentAllPreExamsAve['totalAve'], $studentAllPreExamsAve['rankingAve'], 1]]; $forecastTotalAndRankingArray = [[$forecastNextExam['total'], $forecastNextExam['ranking'], 1]]; // dd($previousTotalAndRankingArray); // dd($averageTotalAndRankingArray); // dd($forecastTotalAndRankingArray); return view('forecast.forecastStudentsFuturePerformance', compact('studentArray', 'studentAllPreExamsAveData', 'forecastNextExamData', 'previousTotalAndRankingArray', 'averageTotalAndRankingArray', 'forecastTotalAndRankingArray')); }
public function importStudentOwnSections(Request $request) { $studentSectionId = $request->input('addStudentSections'); $user = Auth::user(); // 在teachingSection表中查找是否已经有这个学生,如果有就把原来信息改写,如果没有就插入一条记录 $studentTeachingSection = TeachingSection::getTeachingsectionByStudent($user); if ($studentTeachingSection === null) { //means it doesn't exist in teachingSection table. //we need to update it. $newStudentTeachingSection = new TeachingSection(); $newStudentTeachingSection->users_id = $user->id; $newStudentTeachingSection->sections_id = $studentSectionId; $section = Section::find($studentSectionId); $section->total += 1; $section->save(); $newStudentTeachingSection->save(); } else { //it already exists in teachingSection, we just update the latest section. $studentTeachingSection->sections_id = $studentSectionId; $studentTeachingSection->save(); } flash()->overlay('同学你好,已经成功修改了你的学习班级信息', '成功'); return redirect('/dashboard'); }
public static function getTeachingsectionBySections($section) { //a collection of teachingSection. $teachingSection = TeachingSection::where('sections_id', '=', $section->id)->get(); return $teachingSection; }