public function checkSectionsScores()
 {
     $user = Auth::User();
     //        find all section which the teacher records
     $allExaminations = Examinationsinfo::where('users_id', '=', $user->id)->get();
     //        find all section in an examination
     /*        $allExaminationsIds = DB::table('examinationsinfos')
               ->where('users_id', '=', $user->id)->get();*/
     $allExaminationsInfosUnique = Examinationsinfo::where('users_id', '=', $user->id)->get()->unique('examinations_id');
     //        dd($allExaminationsIds);
     //        $allExaminationsIdUnique = $allExaminationsIds->unique('examinations_id');
     //        foreach($allSectionsEachExaminations as $allSectionsEachExamnation){
     //            $allSectionsEachExamination =
     //
     //        }
     //        $allExaminationsAllSections = [];
     //        dd($allExaminationsIdUnique);
     $allExaminationsAllSectionsArray = array();
     $i = 0;
     foreach ($allExaminationsInfosUnique as $examinationInfoUnique) {
         $examination = Examination::find($examinationInfoUnique->examinations_id);
         $allExaminationsAllSectionsArray[$i]['examName'] = $examination->name;
         if ($examination->semester == 1) {
             $allExaminationsAllSectionsArray[$i]['examSemester'] = '第一学期';
         } elseif ($examination->semester == 2) {
             $allExaminationsAllSectionsArray[$i]['examSemester'] = '第二学期';
         } elseif ($examination->semester == 3) {
             $allExaminationsAllSectionsArray[$i]['examSemester'] = '小学期';
         } else {
             $allExaminationsAllSectionsArray[$i]['examSemester'] = '其他';
         }
         if ($examination->type == 1) {
             $allExaminationsAllSectionsArray[$i]['examType'] = '期末考试';
         } elseif ($examination->type == 2) {
             $allExaminationsAllSectionsArray[$i]['examType'] = '期中考试';
         } elseif ($examination->type == 3) {
             $allExaminationsAllSectionsArray[$i]['examType'] = '月考';
         } else {
             $allExaminationsAllSectionsArray[$i]['examType'] = '普通考试';
         }
         //            $allExaminationsAllSectionsArray[$i]['examSemester'] =$examination->semester;
         $allExaminationsAllSectionsArray[$i]['examDate'] = $examination->date;
         //            $allExaminationsAllSectionsArray[$i]['examType'] =$examination->type;
         $allExaminationsAllSectionsArray[$i]['examId'] = $examination->id;
         $allSectionsIdsThisExamination = DB::table('examinationsinfos')->where('examinations_id', '=', $examinationInfoUnique->examinations_id)->lists('sections_id');
         $allSectionsThisExamination = DB::table('sections')->whereIn('id', $allSectionsIdsThisExamination)->get();
         //            dd($allSectionsThisExamination);
         $j = 0;
         $allSections = array();
         foreach ($allSectionsThisExamination as $sectionThisExamination) {
             $allSections[$j]['sectionTotal'] = $sectionThisExamination->total;
             $allSections[$j]['sectionGrade'] = $sectionThisExamination->grade;
             $allSections[$j]['sectionOrder'] = $sectionThisExamination->order;
             $allSections[$j]['sectionId'] = $sectionThisExamination->id;
             /*                $allExaminationsAllSectionsArray[$i][$j]['sectionGrade']=$sectionThisExamination->grade;
                             $allExaminationsAllSectionsArray[$i][$j]['sectionOrder']=$sectionThisExamination->order;*/
             /* $allExaminationsAllSectionsArray[$i][$j]= $sectionThisExamination->toArray();*/
             $j++;
         }
         $allExaminationsAllSectionsArray[$i]['sectionsThisExamiantion'] = $allSections;
         $i++;
     }
     //        dd($allExaminationsAllSectionsArray);
     return view('scores.checkSectionsScores', compact('allExaminationsAllSectionsArray'));
 }
コード例 #2
0
 public function forecastSectionFuturePerformance($sectionId)
 {
     //       get all examinations info about this classes
     $section = Section::find($sectionId);
     //        得到该班级的最近3场考试的平均数据
     $allExamsIdsThisSection = Examinationsinfo::where('Sections_id', '=', $sectionId)->lists('examinations_id');
     $allExamsThisSection = Examination::whereIn('id', $allExamsIdsThisSection)->get();
     //        得到该班级的所有学生
     $allStudensIdsThisSection = User::getStudentBySection($sectionId);
     $allExamsAveData = array();
     $examCount = 0;
     foreach ($allExamsThisSection as $exam) {
         //            i用于标记某场考试该班级有多少学生参加了此次考试
         $i = 0;
         //            找到所有的transcripts, 具备两个要求, 第一个examinations_id 和sections_id
         $allTranscriptsThisSectionEachExam = DB::table('transcripts')->where('examinations_id', '=', $exam->id)->whereIn('users_id', $allStudensIdsThisSection)->get();
         $allExamsAveData[$examCount]['examName'] = $exam->name;
         $allExamsAveData[$examCount]['examDate'] = $exam->date;
         //            开始时为该班级的每次考试的语文平均成绩为0
         $allExamsAveData[$examCount]['chineseSectionAve'] = 0;
         $allExamsAveData[$examCount]['mathSectionAve'] = 0;
         $allExamsAveData[$examCount]['englishSectionAve'] = 0;
         $allExamsAveData[$examCount]['physicsSectionAve'] = 0;
         $allExamsAveData[$examCount]['biologySectionAve'] = 0;
         $allExamsAveData[$examCount]['chemistrySectionAve'] = 0;
         $allExamsAveData[$examCount]['historySectionAve'] = 0;
         $allExamsAveData[$examCount]['politicsSectionAve'] = 0;
         $allExamsAveData[$examCount]['geographySectionAve'] = 0;
         $allExamsAveData[$examCount]['totalSectionAve'] = 0;
         foreach ($allTranscriptsThisSectionEachExam as $transcriptThisSectionEachExam) {
             //                find out all subjects of this student in this examination
             $subjects = Subject::where('transcripts_id', '=', $transcriptThisSectionEachExam->id)->get();
             $allExamsAveData[$examCount]['totalSectionAve'] += $transcriptThisSectionEachExam->total;
             foreach ($subjects as $subject) {
                 $subjectType = $subject->type;
                 if ($subjectType == 1) {
                     $allExamsAveData[$examCount]['chineseSectionAve'] += $subject->score;
                 } elseif ($subjectType == 2) {
                     $allExamsAveData[$examCount]['mathSectionAve'] += $subject->score;
                 } elseif ($subjectType == 3) {
                     $allExamsAveData[$examCount]['englishSectionAve'] += $subject->score;
                 } elseif ($subjectType == 4) {
                     $allExamsAveData[$examCount]['physicsSectionAve'] += $subject->score;
                 } elseif ($subjectType == 5) {
                     $allExamsAveData[$examCount]['biologySectionAve'] += $subject->score;
                 } elseif ($subjectType == 6) {
                     $allExamsAveData[$examCount]['chemistrySectionAve'] += $subject->score;
                 } elseif ($subjectType == 7) {
                     $allExamsAveData[$examCount]['historySectionAve'] += $subject->score;
                 } elseif ($subjectType == 8) {
                     $allExamsAveData[$examCount]['politicsSectionAve'] += $subject->score;
                 } else {
                     $allExamsAveData[$examCount]['geographySectionAve'] += $subject->score;
                 }
             }
             //                一张transcript 意味这一个学生参加了这次考试
             $i++;
         }
         $allExamsAveData[$examCount]['chineseSectionAve'] /= $i;
         $allExamsAveData[$examCount]['mathSectionAve'] /= $i;
         $allExamsAveData[$examCount]['englishSectionAve'] /= $i;
         $allExamsAveData[$examCount]['physicsSectionAve'] /= $i;
         $allExamsAveData[$examCount]['biologySectionAve'] /= $i;
         $allExamsAveData[$examCount]['chemistrySectionAve'] /= $i;
         $allExamsAveData[$examCount]['historySectionAve'] /= $i;
         $allExamsAveData[$examCount]['politicsSectionAve'] /= $i;
         $allExamsAveData[$examCount]['geographySectionAve'] /= $i;
         $allExamsAveData[$examCount]['totalSectionAve'] /= $i;
         $examCount++;
     }
     //        得到所有考试的所有学生的每科平均分.
     $wholeAveData = array();
     $wholeAveData['wholeChineseAve'] = 0;
     $wholeAveData['wholeMathAve'] = 0;
     $wholeAveData['wholeEnglishAve'] = 0;
     $wholeAveData['wholePhysicsAve'] = 0;
     $wholeAveData['wholeBiologyAve'] = 0;
     $wholeAveData['wholeChemistryAve'] = 0;
     $wholeAveData['wholeHistoryAve'] = 0;
     $wholeAveData['wholePoliticsAve'] = 0;
     $wholeAveData['wholeGeographyAve'] = 0;
     $wholeAveData['wholeTotalAve'] = 0;
     foreach ($allExamsAveData as $eachExamAveData) {
         $wholeAveData['wholeChineseAve'] += $eachExamAveData['chineseSectionAve'];
         $wholeAveData['wholeMathAve'] += $eachExamAveData['mathSectionAve'];
         $wholeAveData['wholeEnglishAve'] += $eachExamAveData['englishSectionAve'];
         $wholeAveData['wholePhysicsAve'] += $eachExamAveData['physicsSectionAve'];
         $wholeAveData['wholeBiologyAve'] += $eachExamAveData['biologySectionAve'];
         $wholeAveData['wholeChemistryAve'] += $eachExamAveData['chemistrySectionAve'];
         $wholeAveData['wholeHistoryAve'] += $eachExamAveData['historySectionAve'];
         $wholeAveData['wholePoliticsAve'] += $eachExamAveData['politicsSectionAve'];
         $wholeAveData['wholeGeographyAve'] += $eachExamAveData['geographySectionAve'];
         $wholeAveData['wholeTotalAve'] += $eachExamAveData['totalSectionAve'];
     }
     $wholeAveData['wholeChineseAve'] /= $examCount;
     $wholeAveData['wholeMathAve'] /= $examCount;
     $wholeAveData['wholeEnglishAve'] /= $examCount;
     $wholeAveData['wholePhysicsAve'] /= $examCount;
     $wholeAveData['wholeBiologyAve'] /= $examCount;
     $wholeAveData['wholeChemistryAve'] /= $examCount;
     $wholeAveData['wholeHistoryAve'] /= $examCount;
     $wholeAveData['wholePoliticsAve'] /= $examCount;
     $wholeAveData['wholeGeographyAve'] /= $examCount;
     $wholeAveData['wholeTotalAve'] /= $examCount;
     //        end得到所有考试的所有学生的每科平均分.
     //        对班级未来的各科考试预测
     $wholeForecastData = array();
     $wholeForecastData['forecastChinese'] = 102.3;
     $wholeForecastData['forecastMathAve'] = 122.2;
     $wholeForecastData['forecastEnglish'] = 77.09999999999999;
     $wholeForecastData['forecastPhysics'] = 72.09999999999999;
     $wholeForecastData['forecastBiology'] = 84.2;
     $wholeForecastData['forecastChemistry'] = 70;
     $wholeForecastData['forecastHistory'] = 63.9;
     $wholeForecastData['forecastPolitics'] = 73;
     $wholeForecastData['forecastGeography'] = 84.90000000000001;
     $wholeForecastData['forecastTotal'] = 749.7;
     //        使用预测算法对班级的下次考试预测, 并更新$wholeForecastData的所有值
     //        dd($wholeForecastData);
     //        dd($wholeAveData);
     //        dd($allExamsAveData);
     //        将数据重新格式化成highcharts能够直接识别的形式.
     $wholeAveDataArray = [$wholeAveData['wholeChineseAve'], $wholeAveData['wholeMathAve'], $wholeAveData['wholeEnglishAve'], $wholeAveData['wholePhysicsAve'], $wholeAveData['wholeBiologyAve'], $wholeAveData['wholeChemistryAve'], $wholeAveData['wholeHistoryAve'], $wholeAveData['wholePoliticsAve'], $wholeAveData['wholeGeographyAve']];
     $wholeForecastDataArray = [$wholeForecastData['forecastChinese'], $wholeForecastData['forecastMathAve'], $wholeForecastData['forecastEnglish'], $wholeForecastData['forecastPhysics'], $wholeForecastData['forecastBiology'], $wholeForecastData['forecastChemistry'], $wholeForecastData['forecastHistory'], $wholeForecastData['forecastPolitics'], $wholeForecastData['forecastGeography']];
     //        $averageTotalAndRankingArray = [[$studentAllPreExamsAve['totalAve'],$studentAllPreExamsAve['rankingAve'],35]];
     //        $forecastTotalAndRankingArray = [[$forecastNextExam['total'],$forecastNextExam['ranking'],40]];
     //
     //        dd($wholeAveDataArray);
     //        dd($wholeForecastDataArray);
     return view('forecast.forecastSectionFuturePerformance', compact('section', 'wholeAveDataArray', 'wholeForecastDataArray', 'allExamsAveData', 'wholeForecastData'));
 }