'选择题','11'=>'不定项选择题','5'=>'填空题','7'=>'解答题','17'=>'选做解答题'); private $logicTypeName; private $imgArr = array(); private $isThird = 0; public function actionIndex($YII_ENV='development'){ // echo YII_ENV;exit; if(YII_ENV == "production"){ $file_html_url = "http://zsyas2.zhixinhuixue.com"; }else{ if(YII_ENV == 'development'){ $file_html_url = "http://xbas2.dev.xiaoben.com"; }else{ $file_html_url = "http://xbas2.testing.xiaoben.com"; } } //连接业务库 $conn = $this->getDbConnection(Yii::app()->params["default_server"]['addr'], Yii::app()->params["default_db"]['name'], Yii::app()->params["default_server"]['username'], Yii::app()->params["default_server"]['password']); if($conn){ $this->conn = $conn; $time = time(); //获取要生成教师讲案的数据 $sql = "select id,school_id,exam_group_id,class_ids,subject_id,is_labelled from download_table_setting where download_type = 3 and status = 1 and error_msg = '' and subject_id not in (3,6,51) and is_labelled=0 order by create_time asc limit 1"; $result_all = $this->conn->createCommand($sql)->queryAll(); //超过20分钟默认生成失败 $sql = "update download_table_setting set status = 3,error_msg ='系统错误,建议单个生成' where status = 4 and error_msg = '' and update_time <".($time-1200); $this->conn->createCommand($sql)->execute(); if($result_all){ foreach($result_all as $v_data_k=>$v_data){ if($v_data_k > 0){ break; } $sql = "update download_table_setting set update_time = {$time},status=4 where id ={$v_data['id']}"; $this->conn->createCommand($sql)->execute(); $error = array(); $pdfArr = array(); $is_success = 0; $force=1; try{ if($v_data['class_ids'] && $v_data['school_id'] && $v_data['exam_group_id']){ //连接学校库 $sql = "select database_host,database_user,database_password,database_name,group_id from `database` where school_id = '{$v_data['school_id']}'"; $conn = $this->getDbConnection(Yii::app()->params["default_server"]['addr'], Yii::app()->params["default_db"]['name'], Yii::app()->params["default_server"]['username'], Yii::app()->params["default_server"]['password']); if($conn){ $this->conn = $conn; }else{ echo "连接业务库失败\n"; $error[] = "连接业务库失败"; continue; } $result_one = $this->conn->createCommand($sql)->queryRow(); if($result_one){ $school_group_id = $result_one["group_id"]; if (!is_numeric($school_group_id)){ $school_group_id = 0; } $sConn = $this->getDbConnection($result_one["database_host"],$result_one["database_name"], $result_one["database_user"],$result_one["database_password"]); if($sConn){ $this->sConn = $sConn; echo '连接学校ID'.$v_data['school_id']."成功\n"; $null_data = 1; $pdfNames = array(); echo '开始获取任务ID'.$v_data['id']."的数据\n"; $classIds = explode(",", $v_data["class_ids"]); if($classIds){ foreach($classIds as $classId) { $this->sConn->active = false; $sConn = $this->getDbConnection($result_one["database_host"], $result_one["database_name"], $result_one["database_user"], $result_one["database_password"]); $this->sConn = $sConn; echo "开始获取classId=" . $classId . "的数据\n"; $sql = "select class_name from class where class_id = '{$classId}'"; $data_one = $this->sConn->createCommand($sql)->queryRow(); if($data_one){ $className = $data_one['class_name']; }else{ $className = ""; } $sql = "select exam_id,name from exam where exam_group_id = '{$v_data["exam_group_id"]}' and class_id = '{$classId}'"; $data_one = $this->sConn->createCommand($sql)->queryRow(); $examId=$data_one['exam_id']; $examName = $data_one["name"]; $sql = "select e.exam_group_id,e.class_id,e.subject_id,eg.is_third,e.name as exam_name,e.academicr_pdf_path,e.academicr_pdf_time,p.paper_id,e.is_academicr_pdf,c.class_name,e.tpl_index,e.tpl_data,e.is_fine_paper,academicr_common_practice,eg.qxk_paper_id from exam as e left join class as c on c.class_id=e.class_id left join exam_group as eg on e.exam_group_id=eg.exam_group_id left join paper as p on p.exam_id=e.exam_id where e.exam_id = {$examId}"; $examInfo=$this->sConn->createCommand($sql)->queryRow(); if($examInfo['subject_id']){ $this->subjectId = $examInfo['subject_id']; } $subjectId = $this->subjectId; $this->logicTypeName = getSubjectTopicType($subjectId); $pdfpath = str_replace("protected", "", Yii::app()->basePath) . $examInfo['academicr_pdf_path']; $pdfurl = $examInfo['academicr_pdf_path']; $res = array();//生成pdf命令结果 if(strpos($examInfo['academicr_pdf_path'],'http') !== false){ if(!file_get_contents($examInfo['academicr_pdf_path'])){ $force = 1; } }else{ $force = 1; } $getTopicTypeRelate = $this->getTopicTypeRelate(); $batch_subject_id = $subjectId; if($batch_subject_id == 8 && $examInfo['qxk_paper_id']){ $batch_subject_id = 0; } if (!$examInfo['academicr_pdf_path'] || $examInfo['is_academicr_pdf'] == 0 || $force) { $examGroupId = $examInfo['exam_group_id']; $arr=$this->sConn->createCommand("select topic_upload,answer_upload,template_type from third_multi_template where exam_group_id='{$examGroupId}'")->queryAll(); // if($subjectId == 8 && $examInfo['is_third'] == 1){ if($subjectId == 8 && $examInfo['is_third'] == 1 && !$examInfo['qxk_paper_id']){ $isUpload = 0; if($arr){ foreach ($arr as $k => $v){ $arr[$v['template_type']]=$v; } foreach ($arr as $k => $v){ if($k == 1 && $v['topic_upload'] == 1){ $isUpload++; }elseif($k == 2 && $v['answer_upload'] == 1){ $isUpload++; } } } //精品试卷不用上传试题和答案,第三方需要 if($examInfo['is_fine_paper'] <= 0 && $isUpload != 2){ echo "试卷试题或答案没上传!\n"; $error[] = $className."试卷试题或答案没上传!"; continue; } }elseif($subjectId == 12 && $examInfo['is_third'] == 1){ $isUpload = 0; if($arr){ foreach ($arr as $k => $v){ $arr[$v['template_type']]=$v; } foreach ($arr as $k => $v){ if($k == 1 && $v['topic_upload'] == 1){ $isUpload++; }elseif($k == 2 && $v['answer_upload'] == 1){ $isUpload++; } } } if($isUpload != 2){ echo "试卷试题或答案没上传!\n"; continue; } } $sql = "select exam_id from exam where exam_group_id = {$examGroupId}"; $examIds = $this->sConn->createCommand($sql)->queryColumn(); $isThird = $this->getExamIsTird($examGroupId,$examId); $this->isThird = $isThird; //去除没有上传成绩的学生 $ptrInfo = $stuIdsArr = array(); if($examIds){ $stuIdsArr = $this->getHasScoreStu($examIds); $ptrInfo = $this->getStudentExamInfo($examIds); } if(!$ptrInfo){ echo "考试没有数据!\n"; $error[] = $className."考试没有数据!"; continue; } $paperIds = array(); foreach($ptrInfo as $value){ $paperIds[$value['exam_id']] = $value['paper_id']; } //试卷总分 $paperScore = $this->getPaperScore($paperIds); if(!$paperScore){ echo "试卷总分不正确!\n"; $error[] = $className."试卷总分不正确!"; continue; } /**************************** 一、班级情况分析 ***********************************/ //获取当前考试的上一次考试数据 $examDate = $this->getExamTime($examId); $sql = "select cep.exam_id,e.exam_group_id from class_exam_printer as cep left join exam as e on e.exam_id = cep.exam_id where e.subject_id = {$examInfo['subject_id']} and cep.add_time < {$examDate} and e.class_id = {$examInfo['class_id']} and cep.type = 0 and e.status = 1 order by add_time desc"; $preInfo= $this->sConn->createCommand($sql)->queryRow(); $preExamId = isset($preInfo['exam_id'])?$preInfo['exam_id']:''; $preExamGroupId = isset($preInfo['exam_group_id'])?$preInfo['exam_group_id']:''; $prePaperScore = 0; $preStuIdsArr = array(); if($preExamId){ $sql = "select exam_id from exam where exam_group_id = {$preExamGroupId}"; $preExamIds = $this->sConn->createCommand($sql)->queryColumn(); //去除没有上传成绩的学生 $prePtrInfo = array(); if($preExamIds){ $preStuIdsArr = $this->getHasScoreStu($preExamIds); $prePtrInfo = $this->getStudentExamInfo($preExamIds); } $prePaperIds = array(); foreach($prePtrInfo as $value){ $prePaperIds[$value['exam_id']] = $value['paper_id']; } if($prePaperIds){ $prePaperScore = $this->getPaperScore($prePaperIds); } }else{ $prePtrInfo = array(); } if(!$prePaperScore && $prePtrInfo){ echo "试卷总分不正确!\n"; $error[] = $className."试卷总分不正确!"; continue; } if(isset($paperIds[$examId])){ $paperId = $paperIds[$examId]; }else{ echo "试卷id没有考试信息!\n"; $error[] = $className."试卷id没有考试信息!"; continue; } //班级排名得分率人数等数据 $classAnalyData = $this->getClassAnalyse($examId,$ptrInfo,$paperScore,$preExamId,$prePtrInfo,$prePaperScore,$stuIdsArr,$preStuIdsArr); //大幅进步,大幅退步,前5名和后5名 $largeOrderData = $this->getLargeOrder($examId,$ptrInfo,$preExamId,$prePtrInfo,$stuIdsArr,$preStuIdsArr); $sutName = isset($largeOrderData['stu_name'])?$largeOrderData['stu_name']:array(); $sutOrder = isset($largeOrderData['stu_order'])?$largeOrderData['stu_order']:array(); unset($ptrInfo); unset($prePtrInfo); /**************************** 二、考试情况分析 ***********************************/ //试卷题对应的题号,分数 list($largeTopicType,$largeTopicMethod) = $this->getPaperLargeTopicInfo($paperId); list($smallTopicScore,$smallTopicNo,$topicScore,$topicNo,$topicType,$topicLogicType,$topicRelLarge,$topicRelMethod,$topicTypeRelNo,$topicRelTopicCount) = $this->getPaperTopicInfo2($paperId,$largeTopicType,$subjectId,$examInfo); if(!$topicScore){ echo "没有试卷题数据!\n"; $error[] = $className."没有试卷题数据!"; continue; } $stuRs = $this->getStudentRs($paperIds); if(!$stuRs){ echo "没有学生做题数据!\n"; $error[] = $className."没有学生做题数据!"; continue; } $typeMasterData = $this->getTopicTypeAnaly($stuRs,$topicScore,$topicNo,$paperId,$topicLogicType,$topicRelLarge,$smallTopicNo); //英语全学科判断 if($subjectId == 8 && $examInfo['qxk_paper_id']){ $newTopicTypeRelNo = array(); foreach($topicTypeRelNo as $topic_type=>$topic_data){ if(isset($getTopicTypeRelate[$topic_type])){ $newTopicTypeRelNo[$getTopicTypeRelate[$topic_type]] = $topic_data; }else{ $newTopicTypeRelNo[$topic_type] = $topic_data; } } $topicTypeRelNo = $newTopicTypeRelNo; } //班级高频错题 统计班级得分率小于50%的题目 $high_rate_wrong_topic = array(); if($typeMasterData['type_name_arr']){ foreach($typeMasterData['type_name_arr'] as $large_type=>$type_name){ if(isset($topicTypeRelNo[$large_type])){ $high_rate_wrong_topic[$large_type] = array(array(),array(),array(),array(),array()); foreach($topicTypeRelNo[$large_type] as $topic_id=>$topic_no){ $topic_class_rate = isset($typeMasterData['topic_class_rate'][$topic_id]) ? $typeMasterData['topic_class_rate'][$topic_id] : 0; if($topic_class_rate <= 10){ $high_rate_wrong_topic[$large_type][0][] = $smallTopicNo[$topic_id]; }elseif($topic_class_rate>10 && ($topic_class_rate<=20)){ $high_rate_wrong_topic[$large_type][1][] = $smallTopicNo[$topic_id]; }elseif($topic_class_rate>20 && ($topic_class_rate<=30)){ $high_rate_wrong_topic[$large_type][2][] = $smallTopicNo[$topic_id]; }elseif($topic_class_rate>30 && ($topic_class_rate<=40)){ $high_rate_wrong_topic[$large_type][3][] = $smallTopicNo[$topic_id]; }elseif($topic_class_rate>40 && ($topic_class_rate<=50)){ $high_rate_wrong_topic[$large_type][4][] = $smallTopicNo[$topic_id]; } } } } } $typeMasterData['high_rate_wrong_topic'] = $high_rate_wrong_topic; $typeRateImgUrl = array(); /**************************** 三、考点掌握情况 ***********************************/ //题信息 $topicIds = array_keys($topicNo); $tplData = array(); if($examInfo['tpl_data']){ $tplData = $examInfo['tpl_data']; if($tplData && !is_array($tplData)){ $tplData = json_decode($tplData,true); } } $isNewEnglish = (isset($tplData['isNewEnglish']) && $tplData['isNewEnglish'] == 1)?1:0; $_params = array('isFormat' => $subjectId == 8 ? 0 : 1 , 'isTird' => $isThird ,'isNewEnglish' => $isNewEnglish,'isNoReplaceLable'=>1); $topicDetails = $this->apiBrainPost('/topic/batchAll', array('topicIds' => $topicIds,'subjectId' => $batch_subject_id ,'params' => $_params),25,true); unset($tplData); $methodName = array(); $largeTopicScore = array(); if (!$topicDetails) { echo "获取接口batchALL无数据!\n"; $error[] = $className."获取接口batchALL无数据!"; continue; } elseif (isset($topicDetails['status']) && $topicDetails['status']==0) { echo $topicDetails['error'][0]."\n"; $error[] = $className.$topicDetails['error'][0]; continue; }else{ if ($subjectId == 8) { $tempDetials = array(); if($examInfo['qxk_paper_id']){ $topicDetails = $this->quanTopicDetail($topicDetails); } foreach ($topicDetails as $detail) { //范文 //语篇 $keyWords = array(); if(isset($getTopicTypeRelate[$detail['type_id']])){ $detail['type_id'] = $getTopicTypeRelate[$detail['type_id']]; } if (in_array($detail['type_id'], array(2, 3, 4, 5))) { $wordsIds = array(); $wordInfoArr = array(); if (isset($detail['key_words_levels']) && $detail['key_words_levels']) { $key_words_level = $detail['key_words_levels']; $class = array(); foreach ($key_words_level as $val) { $class[] = $val['level']; } array_multisort($class, SORT_DESC, $key_words_level); $_new_key_words = $key_words_level; $word_content = array(); foreach ($_new_key_words as $item) { $word_content[] = '"' . $item['name'] . '"'; } if ($word_content) { $wordInfoArr = $this->getWord(array('content' => $word_content, 'type_id' => array(1, 2), 'core_words' => 1,'status'=>1)); $topic_word_level = array(); foreach ($wordInfoArr as $word_id => $word_info) { $level = isset($word_info['levels']) ? $word_info['levels'] : 0; $topic_word_level[$word_id] = $level; } arsort($topic_word_level); foreach ($topic_word_level as $word_id => $level) { if (count($wordsIds) <= 10) { $wordsIds[] = $word_id; } } } } if ($wordsIds) { foreach ($wordsIds as $w_id) { if (isset($wordInfoArr[$w_id])) { $keyWords[] = $wordInfoArr[$w_id]; } } $keyWords = $this->handleWordClass($keyWords); } } $detail['key_words'] = $keyWords; if($examInfo['qxk_paper_id']){ $detail['key_words'] = isset($detail['new_key_words'])?$detail['new_key_words']:array(); } //替换序号 // if (in_array($detail['type_id'], array(2,4,5,6,9, 10, 11, 12, 14))) { // $this->replaceTitle($detail['title'],$detail['id'],$topicRelLarge,$smallTopicNo); // } $detail['title'] = str_replace(' ',' ',$detail['title']); $tempDetials[(string)$detail['id']] = $detail; } $topicDetails = $tempDetials; unset($tempDetials); //大题分数 foreach ($topicRelLarge as $small_id => $large_id) { if (!isset($largeTopicScore[$large_id])) { $largeTopicScore[$large_id] = 0; } $largeTopicScore[$large_id] += $topicScore[$small_id]; } } } $diff_id_arr = array_diff($topicIds, array_keys($topicDetails)); if ($diff_id_arr) { //todo 发送消息到补提 echo "没有试题内容!\n"; $error[] = $className."没有试题内容!"; continue; } //1.薄弱考点统计 //2.薄弱考点掌握较差学生名单 //3.班级排名后25%学生的薄弱考点 $pramas = array($smallTopicScore,$smallTopicNo,$paperId,$topicType,$topicLogicType,$topicRelLarge,$topicRelMethod,$largeTopicMethod,$sutName,$sutOrder,$methodName); $methodCount = array(); //4.考点掌握情况变化趋势 //生成图片 if(false){ $_classRate = array(); $examDate = $this->getExamTime($examId); $sql = "select cep.exam_id,cep.add_time from class_exam_printer as cep left join exam as e on e.exam_id = cep.exam_id where e.subject_id = {$examInfo['subject_id']} and cep.add_time <= {$examDate} and e.class_id = {$examInfo['class_id']} and cep.type = 0 and e.status = 1 order by add_time desc limit 3"; $thirdExam= $this->sConn->createCommand($sql)->queryAll(); if(count($thirdExam) > 3){ $thirdExamIds = array(); $examTime = array(); foreach($thirdExam as $value){ $thirdExamIds[] = $value['exam_id']; $examTime[$value['exam_id']] = $value['add_time']; } list($paperRelExam,$exmaRelPaper) = $this->getPaperIdsByExamIds($thirdExamIds); $_topicScore = array(); $_topicMethod = array(); $_stuRs = array(); if($paperRelExam){ $sql = "select topic_id,stem_id,`no`,score,type,method_ids from paper_topic_relation where paper_id in (".implode(',',$paperRelExam).") and is_delete = 0 order by `no`"; $thirdPaperInfo=$this->sConn->createCommand($sql)->queryAll(); foreach ($thirdPaperInfo as $item) { $_topicScore[$item['topic_id']] = $item['score']; $_topicMethod[$item['topic_id']] = explode(',',$item['method_ids']); } $_stuRs = $this->getStudentRs($paperRelExam); } $_scoring = $_score = array(); foreach ($_stuRs as $stuId => $stuR) { foreach ($stuR as $tId => $item) { $pId = $item['paper_id']; $eId = isset($exmaRelPaper[$pId])?$exmaRelPaper[$pId]:0; $eTime = isset($examTime[$eId])?$examTime[$eId]:0; if(!$eTime) continue; $_tScore = isset($_topicScore[$tId])?$_topicScore[$tId]:0; if(isset($_topicMethod[$tId]) && $_topicMethod[$tId]){ foreach ($_topicMethod[$tId] as $mId){ if(!$mId){ continue; } if(!isset($_scoring[$eTime])){ $_scoring[$eTime] = array(); } if(!isset($_scoring[$eTime][$mId])){ $_scoring[$eTime][$mId] = 0; } $_scoring[$eTime][$mId] += $item['scoring']; if(!isset($_score[$eTime])){ $_score[$eTime] = array(); } if(!isset($_score[$eTime][$mId])){ $_score[$eTime][$mId] = 0; } $_score[$eTime][$mId] += $_tScore; } } } } foreach($_scoring as $eTime => $scorings){ if(!isset($_classRate[$eTime])){ $_classRate[$eTime] = array(); } foreach($scorings as $mId => $scoring){ if(isset($_score[$eTime]) && isset($_score[$eTime][$mId]) && $_score[$eTime][$mId]){ $_classRate[$eTime][$mId] = round($scoring/$_score[$eTime][$mId],4) * 100; }else{ $_classRate[$eTime][$mId] = 0; } } } } ksort($_classRate); //三次考试同一考点的得分率 $timeMethodRate = array(); foreach($_classRate as $time => $rates){ foreach($rates as $mId => $rate){ if(!isset($timeMethodRate[$mId])){ $timeMethodRate[$mId] = array(); } $timeMethodRate[$mId][] = $rate; $timeMethodRate[$mId][] = $rate; $timeMethodRate[$mId][] = $rate; } } //取出符合规则的三个考点 $rateCompare = array(); foreach ($timeMethodRate as $mId => $rates) { $rate_1 = $rates[2] - $rates[1]; $rate_2 = $rates[1] - $rates[0]; $rateCompare[$mId] = $rate_1 - $rate_2; } arsort($rateCompare); $rateCompare = array_slice($rateCompare,0,3,true); $timeMethodRate = array(); foreach($_classRate as $time => $rates){ foreach($rates as $mId => $rate){ if(isset($rateCompare[$mId])){ if(!isset($timeMethodRate[$mId])){ $timeMethodRate[$mId] = array(); } $timeMethodRate[$mId][] = $rate; } } } $imgPath = str_replace("protected", "", Yii::app()->basePath) . 'assets/temp_img/'; $urlPath = Yii::app()->request->hostInfo . '/assets/temp_img/'; $methodRatePath= $imgPath.$examId ."_rate.png"; $methodRateUrl = $urlPath.$examId ."_rate.png"; $this->imgArr[] = $methodRatePath; if(count($timeMethodRate) >= 3){ $this->getImage($methodRatePath,$timeMethodRate); } if(!file_exists($methodRatePath)){ $methodRateUrl = ''; } }else{ $methodRateUrl = ''; } /**************************** 四、试卷讲评 ***********************************/ //选择题 $choinceIds = $this->getChoiceIds($topicType,$topicLogicType,$subjectId,$examInfo['tpl_index']); //试题年级和班级得分率,答对和答错人数 $topicRateStu = $this->getTopicRateWrongPerson($stuRs,$topicScore,$paperId,$stuIdsArr,$topicRelLarge,$choinceIds,$sutName,$topicLogicType); $common_practice = array(); $commonTopicDetail = array(); $check = 1; if($subjectId == 8){ $sql = "select custom_config from product_class_relation pcr join product_setting ps on pcr.ps_id=ps.ps_id where pcr.class_id={$classId} and product_type=6 and ps.subject_id = {$subjectId}"; $config =$this->sConn->createCommand($sql)->queryRow(); if ($config) { $configArr = json_decode($config['custom_config'],true); $setting = $configArr['setting']; $check = isset($setting['variantTrainingOfCommonProblems']) ? $setting['variantTrainingOfCommonProblems'] : 1; } if ($check) { if($examInfo['academicr_common_practice']){ $common_push_all_topics = array(); $common_practice = json_decode($examInfo['academicr_common_practice'],true); foreach($common_practice as $type=>$cp_info){ if($type == 'min_rate_text' || $type == 'common_extra'){ $t_ids = _array_column($cp_info,'topic_id'); $common_push_all_topics = array_merge($common_push_all_topics,$t_ids); }else{ foreach($cp_info as $topic_type=>$t_info){ $t_ids = _array_column($t_info,'topic_id'); $common_push_all_topics = array_merge($common_push_all_topics,$t_ids); } } } }else{ //20211221新逻辑:学生提分宝不生成共性问题的话 教师讲案直接不生成 echo "没有生成共性题!\n"; $error[] = $className."没有生成共性题!"; continue; $common_wrong_topic = $this->getCommonPractice($topicDetails,$topicRateStu['large_topic_score'],$stuRs,$largeTopicType,$topicRateStu['large_contain_score']); list($common_practice,$common_push_all_topics) = $common_wrong_topic; $sql = "update exam set academicr_common_practice = '".json_encode($common_practice)."' where exam_id={$examId}"; $this->sConn->createCommand($sql)->execute(); } if($common_push_all_topics){ $commonTopicDetail = $this->apiBrainPost('/topic/batchAll', array('topicIds' => array_values($common_push_all_topics),'subjectId' => $batch_subject_id ,'params' => array('isNoReplaceLable'=>1)),25,true); if (!$commonTopicDetail) { echo "获取接口batchALL无数据!\n"; $error[] = $className."获取接口batchALL无数据!"; continue; } elseif (isset($commonTopicDetail['status']) && $commonTopicDetail['status']==0) { echo $commonTopicDetail['error'][0]."\n"; $error[] = $className.$commonTopicDetail['error'][0]; continue; }else{ $tempDetials = array(); if($examInfo['qxk_paper_id']){ $commonTopicDetail = $this->quanTopicDetail($commonTopicDetail); } foreach ($commonTopicDetail as $detail) { if(isset($getTopicTypeRelate[$detail['type_id']])){ $detail['type_id'] = $getTopicTypeRelate[$detail['type_id']]; } $tempDetials[(string)$detail['id']] = $detail; } $commonTopicDetail = $tempDetials; } } } } $topicTypeScore = array(); if($subjectId == 8){ //题型重新按照组卷顺序排序 $new_type_name_arr = array(); $new_high_rate_wrong_topic = array(); $new_class_rate = array(); $new_type_order = array_keys($topicTypeRelNo); if($new_type_order){ foreach($new_type_order as $new_type){ if(isset($this->logicTypeName) && isset($this->logicTypeName[$new_type]) && $this->logicTypeName[$new_type]){ $new_type_name_arr[$new_type] = $this->logicTypeName[$new_type]; }else{ $new_type_name_arr[$new_type] = ''; } if(isset($typeMasterData['high_rate_wrong_topic']) && $typeMasterData['high_rate_wrong_topic'] && isset($typeMasterData['high_rate_wrong_topic'][$new_type])){ $new_high_rate_wrong_topic[$new_type] = $typeMasterData['high_rate_wrong_topic'][$new_type]; } if(isset($typeMasterData['class_rate']) && $typeMasterData['class_rate'] && isset($typeMasterData['class_rate'][$new_type])){ $new_class_rate[$new_type] = $typeMasterData['class_rate'][$new_type]; } } } if($new_type_name_arr){ $typeMasterData['type_name_arr'] = $new_type_name_arr; } if($new_high_rate_wrong_topic){ $typeMasterData['high_rate_wrong_topic'] = $new_high_rate_wrong_topic; } if($new_class_rate){ $typeMasterData['class_rate'] = $new_class_rate; } //获取题型对应题目关系 $typeToTopicIds = array(); if($topicDetails){ foreach($topicDetails as $topicIdTemp=>$topicDetailTemp){ if(isset($topicDetailTemp['type_id']) && $topicDetailTemp['type_id']){ $typeToTopicIds[$topicDetailTemp['type_id']][] = (string)$topicIdTemp; } } } //增加班级题型得分表 if($topicTypeRelNo){ foreach($topicTypeRelNo as $typeTemp=>$topicNoDataTemp){ if($topicNoDataTemp){ $topicTypeScore[$typeTemp]['score'] = 0; $topicTypeScore[$typeTemp]['class_score'] = 0; $topicTypeScore[$typeTemp]['grade_score'] = 0; $topicTypeScore[$typeTemp]['diff_score'] = 0; $topicTypeScore[$typeTemp]['no'] = ''; $tempClassScore = $tempGradeScore = $tempClassCount = $tempGradeCount = 0; $tempClassStuIds = $tempGradeStuIds = array(); if(isset($topicRateStu) && $topicRateStu && isset($topicRateStu['large_topic_score']) && $topicRateStu['large_topic_score']){ foreach($topicRateStu['large_topic_score'] as $stuIdTemp=>$stuScoreTemp){ foreach($stuScoreTemp as $tempTopicIdK=>$tempTopicIdV){ if(isset($typeToTopicIds[$typeTemp]) && $typeToTopicIds[$typeTemp] && in_array((string)$tempTopicIdK,$typeToTopicIds[$typeTemp],true)){ if(isset($sutName[$stuIdTemp])){//本班 $tempClassScore += (isset($tempTopicIdV['scoring']) && $tempTopicIdV['scoring']) ? $tempTopicIdV['scoring']:0; // $tempClassCount ++; $tempClassStuIds[] = (string)$stuIdTemp; } $tempGradeScore += (isset($tempTopicIdV['scoring']) && $tempTopicIdV['scoring']) ? $tempTopicIdV['scoring']:0; // $tempGradeCount ++; $tempGradeStuIds[] = (string)$stuIdTemp; } } } } if($tempClassStuIds){ $tempClassCount = count(array_unique($tempClassStuIds)); $topicTypeScore[$typeTemp]['class_score'] = round($tempClassScore/$tempClassCount,1); } if($tempGradeStuIds){ $tempGradeCount = count(array_unique($tempGradeStuIds)); $topicTypeScore[$typeTemp]['grade_score'] = round($tempGradeScore/$tempGradeCount,1); } $topicTypeScore[$typeTemp]['diff_score'] = round($topicTypeScore[$typeTemp]['class_score'] - $topicTypeScore[$typeTemp]['grade_score'],1); if(isset($typeToTopicIds[$typeTemp]) && $typeToTopicIds[$typeTemp]){ foreach($typeToTopicIds[$typeTemp] as $bigTopicTemp){ if(isset($largeTopicScore[$bigTopicTemp]) && $largeTopicScore[$bigTopicTemp]){ $topicTypeScore[$typeTemp]['score'] += $largeTopicScore[$bigTopicTemp]; } } } $topicNoValue = array_values($topicNoDataTemp); if(count($topicNoValue) == 1){ $topicTypeScore[$typeTemp]['no'] = $topicNoValue[0]; }else{ $topicTypeScore[$typeTemp]['no'] = min($topicNoValue).'-'.max($topicNoValue); } } } } } $data = array(); $data['examInfo'] = $examInfo; $data['classAnalyData'] = $classAnalyData; $data['largeOrderData'] = $largeOrderData; $data['typeMasterData'] = $typeMasterData; $data['typeRateImg'] = $typeRateImgUrl; $data['methodCount'] = $methodCount; $data['topicDetails'] = $topicDetails; $data['paperTopicNo'] = $topicNo; $data['smallTopicNo'] = $smallTopicNo; $data['topicTypeRelNo'] = $topicTypeRelNo; $data['topicRateStu'] = $topicRateStu; $data['methodRateUrl'] = $methodRateUrl; $data['subjectId'] = $subjectId; $data['isThird'] = $isThird; $data['sutName'] = $sutName; $data['methodName'] = $methodName; $data['logicTypeName'] = $this->logicTypeName; $data['topic_score'] = $largeTopicScore; $data['topic_rel_topic_count'] = $topicRelTopicCount; $data['common_practice'] = $common_practice; $data['common_topic_detail'] = $commonTopicDetail; $data['topicTypeScore'] = $topicTypeScore; if ($subjectId == 8) { // $html_name = 'en_teach_batch'; $html_name = 'en_teach'; }else{ $html_name = 'teach_batch'; } $data['className'] = $className; $data['imgUrl'] = $file_html_url; $html = $this->viewRender($html_name, $data); unset($data); $htmlpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr/'; //存放生成的HTML路径 $pdfpath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr/' . $v_data['school_id'] . "/"; //存放生成的PDF路径 $pdfurl = '/upload/tmpDir/academicr/' . $v_data['school_id'] . "/"; if (!is_dir($htmlpath)) { if (!mkdir($htmlpath, 0777, true)) { exit('Create directory fail: ' . $htmlpath); }else{ exec('chown -R www:www '.$htmlpath); } }if (!is_dir($pdfpath)) { if (!mkdir($pdfpath, 0777, true)) { exit('Create directory fail1: ' . $pdfpath); }else{ exec('chown -R www:www '.$pdfpath); } } $htmlpath.=$examId . ".html"; $f = fopen($htmlpath, "w"); fwrite($f, $html); fclose($f); $htmlurl = '/upload/tmpDir/academicr/' . $examId . ".html"; //访问HTML的路径 if (Yii::app()->basePath == "D:\wamp64\www\zsyas2\protected") {//本地的basePath $htmlurl = " http://zsyas2.com" . '/'.$examId.'.html'; $pdffname=$classId."-".$examId.".pdf"; $pdfpath = $pdfpath . $pdffname; $pdfurl = $pdfurl . $pdffname; $commond = Yii::app()->params['phantomjs'] . " " . Yii::app()->params['html2pdf'] . " " . " {$htmlurl}" . " {$pdfpath}" . " 176mm*250mm ''"; } else { $server = Yii::app()->params['phantomjs_server']; $js = 'html2pdf.js'; if ($subjectId == 8){ $server = Yii::app()->params['phantomjs_server_en']; $js = 'html2pdf_en.js'; } //$htmlurl = "http://" . $_SERVER['SERVER_NAME'] . $htmlurl; $htmlurl = $file_html_url . $htmlurl; $pdffname=$classId."-".$examId.".pdf"; $pdfpath = $pdfpath . $pdffname; $pdfurl = $pdfurl . $pdffname; $commond = $server . " " . Yii::app()->basePath . '/../js/'.$js . " " . " {$htmlurl}" . " {$pdfpath}" . " 176mm*250mm ''"; } // debug($commond); exec($commond, $res, $code); if(isset($res[0])){ $isBool = false; foreach($res as $msg){ if (strpos($msg, 'succeed') !== false){ $isBool = true; } } if ($isBool) {//命令返回成功 if (file_exists($pdfpath)) { $repdf = $examId.".pdf"; $rename = 'zsyas2/academicr/'.$v_data['school_id'].'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '.' . $repdf; $ucloud = new Qcloud(); $uploadInfo = $ucloud->putFile($rename, $pdfpath); //html路径 $htmlName = 'zsyas2/academicr/'.$v_data['school_id'].'/'. date('Y') . '/' . date('m') . '/' . date('d').'/'. uniqid() . '.' . $examId.'.html'; $uploadHtmlInfo = $ucloud->putFile($htmlName, $htmlpath); if ($uploadInfo['status'] == 0) { echo "PDF文件上传失败\n"; $error[] = $className."PDF文件上传失败"; }else{ $tmpHtmlUrl = ''; if ($uploadHtmlInfo['status'] != 0) { $tmpHtmlUrl = $uploadHtmlInfo['url']; } $pdfurl = $uploadInfo['url']; $this->sConn->createCommand()->update("exam", array("academicr_html_path"=>$tmpHtmlUrl,"academicr_pdf_path" => $pdfurl, "academicr_pdf_time" => time(), "is_academicr_pdf" => 1), "exam_id = '{$examId}'"); $pdfArr[] = $pdfpath; $pdfNames[] = $className; } @unlink($htmlpath); } else { $this->sConn->createCommand()->update("exam", array("academicr_pdf_path" => "", "academicr_pdf_time" => 0, "is_academicr_pdf" => 0), "exam_id = '{$examId}'"); @unlink($htmlpath); echo json_encode(array("status" => 1, "error" => "PDF文件未找到!")); exit; } } else { @unlink($htmlpath); echo json_encode(array("status" => 1, "error" => "PDF创建失败!",'exec_rs'=>json_encode($res))); exit; } }else{ echo "PDF创建失败!\n"; $error[] = $className."PDF创建失败!"; } }else{ $pdfArr[] = $pdfpath; $pdfNames[] = $className; } } } foreach($pdfArr as $k=>$v){ if(strpos($v,'http') !== false){ $new_dir_url = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr_batch/'.$v_data['exam_group_id']."/".$v_data['id']."/"; if (!is_dir($new_dir_url)) { if (!mkdir($new_dir_url, 0777, true)) { echo 'Create directory fail1: ' . $new_dir_url. "\n"; }else{ exec('chown -R www:www '.$new_dir_url); } } $new_file_url = $this->downImgRar($v,$new_dir_url,$k); $pdfArr[$k] = $new_file_url; // echo $new_file_url;exit; } } //var_dump($pdfArr);exit; $this->conn->active = false; $conn = $this->getDbConnection(Yii::app()->params["default_server"]['addr'], Yii::app()->params["default_db"]['name'], Yii::app()->params["default_server"]['username'], Yii::app()->params["default_server"]['password']); $this->conn = $conn; if($pdfArr){ echo "开始压缩文件\n"; if($pdfArr){ echo $examName.'pdf生成成功!'. "\n"; // $report_name = $class_name.$year."年度报告.zip"; $filepath = str_replace("protected", "", Yii::app()->basePath) . '/upload/tmpDir/academicr_batch/'.$v_data['exam_group_id']."/".$v_data['id']."/"; //存放生成的PDF路径 if (!is_dir($filepath)) { if (!mkdir($filepath, 0777, true)) { echo 'Create directory fail1: ' . $filepath. "\n"; }else{ exec('chown -R www:www '.$filepath); } } $examName = iconv("UTF-8","GBK//IGNORE",$examName); $filename = dirname(dirname(dirname(__FILE__))).'/upload/tmpDir/academicr_batch/'.$v_data['exam_group_id']."/".$v_data['id']."/".$v_data['exam_group_id'].".zip"; //最终生成的文件名(含路径) $zip = new ZipArchive();//使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释 if ($zip->open($filename, ZIPARCHIVE::OVERWRITE)!==TRUE) { echo $examName.'zip生成失败!'. "\n"; }else{ foreach ($pdfArr as $k=>$val) { // $pdfNames[$k] = iconv("UTF-8","GBK//IGNORE",$pdfNames[$k]); $pdfname = '-'.$pdfNames[$k].'-教师讲案'; $pdfname = iconv("UTF-8","GBK//IGNORE",$pdfname); $res=$zip->addFile($val,$examName.$pdfname.'.pdf'); //@unlink($pdfArr[$k]); } $zip->close();//关闭 foreach($pdfArr as $k=>$val){ @unlink($val); } //生成完成 // $filename = addslashes($filename); $time = time(); $filename = $this->characet($filename); $ucloud = new Qcloud(); $filename = iconv("UTF-8","GBK//IGNORE",$filename); $examName = $this->characet($examName); $meg = $ucloud->putFile('zsyas2/academicr_batch/'.$v_data['exam_group_id'].'/'.$v_data['id'].'/'.$examName.'.zip',$filename); if($meg['status'] == 0){ $error[] = $className.$meg['msg']; }else{ $url = $meg['url']; $url = str_replace("%2F","/",$url); $sql = "update download_table_setting set status = 2,zip_url = '{$url}',update_time = {$time} where id = {$v_data['id']}"; $this->conn->createCommand($sql)->execute(); $is_success = 1; echo $examName.'zip生成成功!'. "\n"; } @unlink($filename); } }else{ echo 'pdf生成失败!'. "\n"; } } }else{ echo '连接学校ID'.$v_data['school_id']."失败\n"; continue; } }else{ echo '暂无学校ID'.$v_data['school_id']."的信息\n"; continue; } $this->sConn->active = false; } if(!$is_success){ if($error){ $time = time(); $sql = "update download_table_setting set error_msg='".implode(",",$error)."',update_time = {$time},status=3 where id = {$v_data['id']}"; $this->conn->createCommand($sql)->execute(); echo $examName.'zip生成失败!'. "\n"; }else{ $time = time(); $sql = "update download_table_setting set update_time = {$time},status=3 where id = {$v_data['id']}"; $this->conn->createCommand($sql)->execute(); echo $examName.'zip生成失败!'. "\n"; } }else{ if($error){ $time = time(); $sql = "update download_table_setting set error_msg='".implode(",",$error)."',update_time = {$time} where id = {$v_data['id']}"; $this->conn->createCommand($sql)->execute(); } } // $this->conn->active = false; }catch(Exception $e){ // $sql = "update download_table_setting set status=3,error_msg='系统异常' where id = {$v_data['id']}"; //$this->conn->createCommand($sql)->execute(); echo $e->getMessage(); } } }else{ echo "暂无要生成的数据\n"; } $this->conn->active = false; }else{ echo "连接业务库失败\n"; } } function characet($data){ if( !empty($data) ){ $fileType = mb_detect_encoding($data , array('UTF-8','GBK','LATIN1','BIG5')) ; if( $fileType != 'UTF-8'){ $data = mb_convert_encoding($data ,'utf-8' , $fileType); } } return $data; } public function apiPost($path, $arr, $type = 0) { $ch = @curl_init(); $result = FALSE; if ($ch) { $data = json_encode($arr); $url = Yii::app()->params['api'][$type]['prefix'] . $path; $username = Yii::app()->params['api'][$type]['username']; $password = Yii::app()->params['api'][$type]['password']; // Digest认证 curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password); // 不输出头部 curl_setopt($ch, CURLOPT_HEADER, 0); // curl_exec 获取到的内容不直接输出, 而是返回 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 请求重启路由器的地址 传参 进行重启 curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, 'Api Client/1.0.0 (chengfei@liancaitech.com)'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($data), )); if (!curl_errno($ch)) { $result = json_decode(curl_exec($ch)); } // 释放资源 curl_close($ch); } return $result; } /** * 处理接口返回的数据 * @param $res * @return array */ public function handleRes($res){ $result = array( 'status' => 0, 'data' => array(), 'msg' => '暂无数据', ); if($res){ $res = json_decode($res,true); if(isset($res['errCode']) && $res['errCode'] == '00'){ $result['status'] = 1; $result['data'] = isset($res['data'])?$res['data']:array(); $result['msg'] = $res['errMsg']; }else{ if(isset($res['errMsg'])){ $result['msg'] = $res['errMsg']; } } } unset($res); return $result; } function file_exists($url) { $ch = curl_init(); $timeout = 10; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $contents = curl_exec($ch); if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 404) { return false; } return true; // $ch = curl_init(); // curl_setopt ($ch, CURLOPT_URL, $url); // //不下载 // curl_setopt($ch, CURLOPT_NOBODY, 1); // //设置超时 // curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 3); // curl_setopt($ch, CURLOPT_TIMEOUT, 3); // //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // curl_exec($ch); // $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); // if($http_code == 200) { // return true; // } // return false; } public function viewRender($viewName, $data) { extract($data, EXTR_PREFIX_SAME,'data'); ob_start(); ob_implicit_flush(0); $filePath=dirname(dirname(dirname(__FILE__))).'/protected/views/teaching/'.$viewName . '.php'; require($filePath); return ob_get_clean(); } public function getDbConnection($database_host,$database_name,$database_user,$database_password) { if($database_host && $database_name && $database_user && $database_password){ $myDbDsn = 'mysql:host=' . $database_host . ';dbname=' . $database_name; $my_connection = new CDbConnection($myDbDsn, $database_user, $database_password); $my_connection->emulatePrepare = true; $my_connection->enableProfiling = true; $my_connection->enableParamLogging = true; $myDbDsn = null; return $my_connection; }else{ return null; } } private function img_process($img) { $widthArr = array(); $heightArr = array(); $width = ''; $height = ''; if (preg_match('/[\s\'"]width\s*:\s*(\d+\.*\d*)\s*([a-zA-Z]+)*/si',$img,$widthArr)) { $width = $this->length_process($widthArr); } else { if (preg_match('/[\s\'"]width\s*=\s*[\'"]\s*(\d+\.*\d*)\s*([a-zA-Z]+)*;?[\'"]/si',$img,$widthArr)) { $width = $this->length_process($widthArr); } } if ($width) { $width = "width=".$width; } if (preg_match('/[\s\'"]height\s*:\s*(\d+\.*\d*)\s*([a-zA-Z]+)*/si',$img,$heightArr)) { $height = $this->length_process($heightArr); } else { if (preg_match('/[\s\'"]height\s*=\s*[\'"]\s*(\d+\.*\d*)\s*([a-zA-Z]+)*;?[\'"]/si',$img,$heightArr)) { $height = $this->length_process($heightArr); } } if ($height) { $height = "height=".$height; } $return_img = preg_replace('/]*[\s]+(src[\s]*=[\s]*(([\"]([^\"]*)[\"])|([\']([^\']*)[\'])|([^\s]*)))([^>]*>)/si',"",$img); return $return_img; } private function length_process($length_arr){ $length = 0.6*$length_arr[1]; $unit_keys = array_keys($this->units); if (isset($length_arr[2])) { //将直接连接单位改为 单位换算 if(in_array($length_arr[2],$unit_keys)){ $length = $length*$this->units[$length_arr[2]]; }else { $length .= $length_arr[2]; } } return $length; } public function getCodeByExamId($examId){ $code = 0; $sql = "select s.status,s.refer_code from exam e join semester s on e.semester_id = s.semester_id where e.exam_id = '{$examId}'"; $data_sem = $this->sConn->createCommand($sql)->queryRow(); if($data_sem && $data_sem['status'] != 1){ $code = $data_sem['refer_code']?$data_sem['refer_code']:0; } return $code; } private function check_pdf($pdf_path) { if (substr($pdf_path, strlen($pdf_path) - 4, 4) == ".pdf") { if (file_exists($pdf_path)) { return true; } } return false; } function get_version($class_id) { if($class_id){ $sql = 'select show_level,pcr.set_type from product_class_relation pcr join class c on pcr.class_id=c.class_id join product_setting ps on pcr.ps_id=ps.ps_id where c.class_id='.$class_id; $product_res = $this->sConn->createCommand($sql)->queryRow(); if (!$product_res) { //没有找到班级与设置的关系表 $sql = 'select wb_isp_version from class where class_id='.$class_id; $res = $this->sConn->createCommand($sql)->queryRow(); return $res['wb_isp_version']; } else { if ($product_res['set_type'] == 1) { //如果是错题本,还是找以前的配置 $sql = 'select wb_isp_version from class where class_id='.$class_id; $res = $this->sConn->createCommand($sql)->queryRow(); return $res['wb_isp_version']; } else{ return $product_res['show_level']; } } } return 0; } function get_level_rule($class_id) { if($class_id){ $sql = 'select level_rule,pcr.set_type from product_class_relation pcr join class c on pcr.class_id=c.class_id join product_setting ps on pcr.ps_id=ps.ps_id where c.class_id='.$class_id; $product_res = $this->sConn->createCommand($sql)->queryRow(); if (!$product_res) { //没有找到班级与设置的关系表 return 0; } else { return $product_res['level_rule']; } } return 0; } function transferOrders($paperIds) { $sql = 'select paper_id,topic_id,type,`order` from paper_topic_relation where paper_id in ('.implode(',',$paperIds).') order by paper_id, type asc,`order` asc'; $paper_topcic_relation_res = $this->sConn->createCommand($sql)->queryAll(); $sql = 'select tpl_index,tpl_data,paper_id from exam e join paper p on e.exam_id = p.exam_id where p.paper_id in ('.implode(',',$paperIds).')' ; $tpl_index_res = $this->sConn->createCommand($sql)->queryAll(); $tpl_index_arr = array(); $tpl_data_arr = array(); foreach ($tpl_index_res as $v) { $tpl_index_arr[$v['paper_id']] = $v['tpl_index']; if($v['tpl_data']){ $tplData = json_decode($v['tpl_data'],true); if($tplData){ $tplstatus = 0; if(isset($tplData['tplstatus'])){ $tpl_data_arr[$v['paper_id']] = $tplData['tplstatus']; }else{ $tpl_data_arr[$v['paper_id']] = 0; } } } } $paper_topcic_relation_arr = array(); foreach ( $paper_topcic_relation_res as $v) { $paper_id = $v['paper_id']; $type = $v['type']; $order = $v['order']; $topic_id = $v['topic_id']; if (!isset($paper_topcic_relation_arr[$paper_id])) { $paper_topcic_relation_arr[$paper_id] = array(); } $paper_topcic_relation_arr[$paper_id][] = array( 'type' => $type, 'order' => $order, 'topic_id'=>$topic_id ); } $paper_topic_no_arr = array(); foreach ($paper_topcic_relation_arr as $paper_id => $paper_topic_relation) { $tpl_index = $tpl_index_arr[$paper_id]; $tplstatus = isset($tpl_data_arr[$paper_id])?$tpl_data_arr[$paper_id]:0; $paper_topic_no_arr[$paper_id] =$this->topic_number($paper_topic_relation,$tpl_index,$tplstatus); } return $paper_topic_no_arr; } function topic_number($paper_topcic_relation_arr, $tpl_index,$tplstatus) { $topic_no_arr = array(); //每道题的序号 if ($tpl_index == 10 || $tpl_index == 1010 || $tplstatus == 3 || $tplstatus == 4) { //10,1010 表示江苏那个有a,b,c,d选做题的模板,编号不能按表里的编号来 $prefix_no = 0; $num = 0; $index_arr = array('A','B','C','D','E'); $_order = 0; foreach($paper_topcic_relation_arr as $v) { if (!$prefix_no && $v['type'] == 17) { $_order += 1; //序号加1 $prefix_no = $_order; $topic_no_arr[$v['topic_id']] = $prefix_no.'A'; } elseif ($prefix_no && $v['type'] == 17) { $num += 1; $topic_no_arr[$v['topic_id']] = $prefix_no.$index_arr[$num]; } if ($v['type'] == 27) { $prefix_no += 1; $topic_no_arr[$v['topic_id']] = $prefix_no; } if ($v['type'] != 17 && $v['type'] != 27){ $_order += 1; $topic_no_arr[$v['topic_id']] = $_order; } } } else { //其他模板都是根据order就行 $_order = 0; foreach ($paper_topcic_relation_arr as $v) { $_order += 1; $topic_no_arr[$v['topic_id']] = $_order; } } return $topic_no_arr; } private function topicProcess($html) { if (preg_match_all('/(]*[\s]+)((src)[\s]*=[\s]*(([\"]([^\"]*)[\"])|([\']([^\']*)[\'])|([^\s]*)))([^>]*>)/si', $html, $arr)) { foreach ($arr[0] as $v) { $process_str = $this->img_process($v); ; $html = str_replace($v, $process_str, $html); } } $html = preg_replace('/style\s*=\s*(([\"]([^\"]*)[\"])|([\']([^\']*)[\']))/si', '', $html); $html = preg_replace('//', '', $html); $html = preg_replace('/<\/p>/', '', $html); $html = preg_replace('//', '', $html); $html = preg_replace('//', '', $html); $html = preg_replace('/<\/big>/', '', $html); $html = str_replace(" ", '', $html); return $html; } public function formatDetails($topicBatches) { $optionIndex = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'); $topicDetails = array(); foreach ($topicBatches AS $topic) { $topic = (object) $topic; $type = $topic->type_id; 6 == $type && $type = 5; //6表示多空题,多空题也是5 $topicDetails[$topic->id] = array(); $topicDetails[$topic->id]['type'] = $type; $topicDetails[$topic->id]['methods'] = ''; //考点 $topicDetails[$topic->id]['method_id_arr'] = ''; //考点id数组 $topicDetails[$topic->id]['kps'] = ''; //知识点 $topicDetails[$topic->id]['queBody'] = $this->topicProcess($topic->title); //题目详情 $topicDetails[$topic->id]['options'] = ''; $topicDetails[$topic->id]['parse_video_qrcode'] = isset($topic->parse_video_qrcode) ? $topic->parse_video_qrcode : ''; $topicDetails[$topic->id]['answer'] = ''; //每题的正确答案 $topicDetails[$topic->id]['analysis'] = $this->topicProcess($topic->parse_content); //答题解析 $topicDetails[$topic->id]['teacher_tips'] = $this->topicProcess($topic->teacher_tips); //名师点评 $topicDetails[$topic->id]['difficulty_degree'] = isset($topic->difficulty_degree) ? $topic->difficulty_degree : null; $topicDetails[$topic->id]['difficulty'] = $topic->difficulty; $_methods = array(); $_method_id_arr = array(); if ($topic->specials) { foreach ($topic->specials AS $_method) { $_method = (object) $_method; if ($_method->method_name) { $_methods[] = $_method->method_name; } if (isset($_method->method_id)) { $_method_id_arr[] = $_method->method_id; } } $topicDetails[$topic->id]['methods'] = implode('|', array_unique($_methods)); //考点 $topicDetails[$topic->id]['method_id_arr'] = $_method_id_arr; } $_kps = array(); if (isset($topic->kps) && $topic->kps) { foreach ($topic->kps as $_kp) { $_kp = (object) $_kp; if ($_kp->kp_name) { $_kps[$_kp->kp_id] = $_kp->kp_name; } } $topicDetails[$topic->id]['kps'] = $_kps; //考点 } if ($topic->type_id == 1) { //选择题有选项 if ($topic->items) { if (isset($topic->items[0])) { $topic->items[0] = (object) $topic->items[0]; if (isset($topic->items[0]->options)) { $options = $topic->items[0]->options; if ($options) { $_tmp_options = array(); foreach ($options AS $_optionIndex => $_option) { $_option = (object) $_option; $_tmp_options[$_optionIndex] = $this->topicProcess($_option->option_content); if ($_option->option_correct) { $topicDetails[$topic->id]['answer'] = $this->topicProcess($optionIndex[$_optionIndex]); } } $_list_type = (int) $topic->items[0]->list_type; $topicDetails[$topic->id]['options'] = $this->option_process($_tmp_options, $_list_type); } } } } } else { if ($topic->items) { if (isset($topic->items[0])) { $topic->items[0] = (object) $topic->items[0]; if (isset($topic->items[0]->options)) { $options = $topic->items[0]->options; if ($options) { $_answer = ''; foreach ($options as $v) { $_option = (object) $v; if (trim($_answer) != '') { $_answer .= ' ; '; } $_answer .= $_option->option_content; } $topicDetails[$topic->id]['answer'] = $this->topicProcess($_answer); } } } } } } return $topicDetails; } private function option_process($options, $list_type) { $option_index = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'); if ($list_type == 0) { //纵向排列,即1行1个 $option_str = ""; foreach ($options as $key => $option) { $option_str.="
  • $option_index[$key].$option
  • "; } } elseif ($list_type == 1) { //横向排列,即1行4个 $option_str = ""; foreach ($options as $key => $option) { $option_str.="
  • $option_index[$key].$option
  • "; } } elseif ($list_type == 2) { //1行2个 $option_str = ""; foreach ($options as $key => $option) { if ($key % 2 == 0) { $option1 = $options[$key]; $option_str2 = "
  • $option_index[$key].$option1
  • "; $key1 = $key + 1; if (isset($options[$key1])) { $option2 = $options[$key1]; $option_str2.="
  • $option_index[$key1].$option2
  • "; } $option_str.=$option_str2; } else { continue; } } } return $option_str; } public function numToUpper($number) { $number = substr($number, 0, 2); $arr = array('零', '一', '二', '三', '四', '五', '六', '七', '八', '九'); if (strlen($number) == 1) { $result = $arr[$number]; } else { if ($number == 10) { $result = '十'; } else { if ($number < 20) { $result = '十'; } else { $result = $arr[substr($number, 0, 1)] .'十'; } if (substr($number, 1, 1) != '0') { $result .= $arr[substr($number, 1, 1)]; } } } return $result; } public function numToLetter($number) { $letters = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'); $number = (int)$number; $result = ''; if ($number >= 1 AND $number <= 26) { $result = $letters[$number - 1]; } return $result; } //远程路径,名称,文件后缀 function downImgRar($url,$rename,$name){ $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); $rawdata=curl_exec ($ch); curl_close ($ch); // 使用中文文件名需要转码 $fp = fopen($rename.$name.".pdf",'w'); fwrite($fp, $rawdata); fclose($fp); // 返回路径 return $rename.$name.".pdf"; } //题类型掌握情况 private function getTopicTypeAnaly(&$stuRs,$topicScore,$topicNo,$paperId,$topicLogicType,$topicRelLarge,$smallTopicNo){ $result = array(); $getTopicTypeRelate = $this->getTopicTypeRelate(); $gradeRate = $classRate = array();//班级和年级得分率 $stuTypeWrong = array();//题型答错人数 $typeTopicNo = array();//题型对应的题号 $typeMasterDegree = array();//题型掌握水平 $typeName = $this->typeName; $logicTypeName = $this->logicTypeName; $gradeScoreArr = $classScoreArr = array(); $gradeScoring = $classScoring = array(); $_gradeScore = $_classScore= array(); $_gradeScoring = $_classScoring = array(); $typeNameArr = array(); $allClassScore = $allClassScoring = array(); $paperScoreSum = array(); //优化strcmp($paperId ,$value['paper_id']) == 0 $paperIndexArr = array(); foreach($stuRs as $stuId => $rs){ foreach($rs as $value){ $paperIndexArr[$value['paper_id']] = 0; } } if ($paperIndexArr) { $paperIndexArr = array_keys($paperIndexArr); $paperIndexArr = array_flip($paperIndexArr); } //当前paper_id的索引 $curPaperIndex = isset($paperIndexArr[$paperId]) ? $paperIndexArr[$paperId] : false; foreach($stuRs as $stuId => $rs){ foreach ($rs as $k => $value){ $tId = $value['topic_id']; $t_score = isset($topicScore[$value['topic_id']])?$topicScore[$value['topic_id']]:0; if(isset($topicLogicType[$value['topic_id']]) && $topicLogicType[$value['topic_id']] > 0){ $type = $topicLogicType[$value['topic_id']]; if ($this->subjectId == 9) { $typeArr = explode('_',$type); if(count($typeArr) > 1){ $type = $typeArr[0]; } } if($this->subjectId == 8){ if(isset($getTopicTypeRelate[$type])){ $type = $getTopicTypeRelate[$type]; } } $typeNameArr[$type] = isset($logicTypeName[$type])?$logicTypeName[$type]:''; }else{ $type = $value['type']; $typeNameArr[$type] = isset($typeName[$type])?$typeName[$type]:''; } if(!isset($gradeScoring[$type])){ $gradeScoring[$type] = array(); } $gradeScoring[$type][] = $value['scoring']; if(!isset($gradeScoreArr[$type])){ $gradeScoreArr[$type] = 0; } $gradeScoreArr[$type] += $t_score; if(!isset($_gradeScoring[$tId])){ $_gradeScoring[$tId] = 0; } $_gradeScoring[$tId] += $value['scoring']; if(!isset($_gradeScore[$tId])){ $_gradeScore[$tId] = 0; } $_gradeScore[$tId] += $t_score; //当前班级 // if(strcmp($paperId ,$value['paper_id']) == 0){ if(isset($paperIndexArr[$value['paper_id']]) && $paperId !== false && $paperIndexArr[$value['paper_id']] == $curPaperIndex){ if(!isset($classScoring[$type])){ $classScoring[$type] = 0; } $classScoring[$type] += $value['scoring']; if(!isset($classScoreArr[$type])){ $classScoreArr[$type] = 0; } $classScoreArr[$type] += $t_score; if(!isset($stuTypeWrong[$type])){ $stuTypeWrong[$type] = array(); } if(!isset($stuTypeWrong[$type][$stuId])){ $stuTypeWrong[$type][$stuId] = array( 'scoring' => 0, 'score' => 0, ); } $stuTypeWrong[$type][$stuId]['scoring'] += $value['scoring']; $stuTypeWrong[$type][$stuId]['score'] += $t_score; if(!isset($typeTopicNo[$type])){ $typeTopicNo[$type] = array(); } //小题得分率 if(!isset($_classScoring[$tId])){ $_classScoring[$tId] = 0; } $_classScoring[$tId] += $value['scoring']; if(!isset($_classScore[$tId])){ $_classScore[$tId] = 0; } $_classScore[$tId] += $t_score; if(!isset($typeTopicNo[$type])){ $typeTopicNo[$type] = array(); } // if(isset($topicNo[$value['topic_id']])){ // $typeTopicNo[$type][] = $topicNo[$value['topic_id']]; // } } //所以班级 $pId = $value['paper_id']; if(!isset($allClassScoring[$pId])){ $allClassScoring[$pId] = array(); } if(!isset($allClassScoring[$pId][$type])){ $allClassScoring[$pId][$type] = 0; } $allClassScoring[$pId][$type] += $value['scoring']; if(!isset($allClassScore[$pId])){ $allClassScore[$pId] = array(); } if(!isset($allClassScore[$pId][$type])){ $allClassScore[$pId][$type] = 0; } $allClassScore[$pId][$type] += $t_score; if(!isset($paperScoreSum[$pId])){ $paperScoreSum[$pId] = 0; } $paperScoreSum[$pId] += $t_score; } } //年级得分率 foreach($gradeScoring as $type => $scorings){ if(isset($gradeScoreArr[$type]) && $gradeScoreArr[$type]){ $gradeRate[$type] = round(array_sum($scorings)/$gradeScoreArr[$type],2) * 100; }else{ $gradeRate[$type] = 0; } } //班级得分率 foreach ($classScoring as $type => $scoring){ if(isset($classScoreArr[$type]) && $classScoreArr[$type] > 0){ $classRate[$type] = round($scoring/$classScoreArr[$type],2) * 100; }else{ $classRate[$type] = 0; } } //小题 //年级得分率 $_gradeRate = array(); foreach($_gradeScoring as $tId => $scoring){ if(isset($_gradeScore[$tId]) && $_gradeScore[$tId]){ $_gradeRate[$tId] = round($scoring/$_gradeScore[$tId],2) * 100; }else{ $_gradeRate[$tId] = 0; } } //班级得分率 $_classRate = array(); foreach ($_classScoring as $tId => $scoring){ if(isset($_classScore[$tId]) && $_classScore[$tId] > 0){ $_classRate[$tId] = round($scoring/$_classScore[$tId],2) * 100; }else{ $_classRate[$tId] = 0; } } //题型对应题号排序 foreach($typeTopicNo as $type => $nos){ asort($nos); $typeTopicNo[$type] = array_unique($nos); } //题型掌握水平: 85%包括85%以上,5星;75%-85%,包括75%,4星。65%-75%,包括65%,3星;55%-65%,包括55%,2星;55%以下1星。 foreach($classRate as $type => $rate){ if($rate >= 85){ $typeMasterDegree[$type] = 5; }elseif($rate < 85 && $rate >= 75){ $typeMasterDegree[$type] = 4; }elseif($rate < 75 && $rate >= 65){ $typeMasterDegree[$type] = 3; }elseif($rate < 65 && $rate >= 55){ $typeMasterDegree[$type] = 2; }else{ $typeMasterDegree[$type] = 1; } } //所有班级得分率 $allClassRate = array(); foreach ($allClassScoring as $pId => $scoringArr){ foreach ($scoringArr as $type => $scoring){ if(isset($allClassScore[$pId]) && isset($allClassScore[$pId][$type]) && $allClassScore[$pId][$type] > 0){ $allClassRate[$pId][$type] = round($scoring/$allClassScore[$pId][$type],4) * 100; }else{ $allClassRate[$pId][$type] = 0; } } } //班级题型/试卷总分 $typePaperRate = array(); foreach ($allClassScoring as $pId => $scoringArr){ foreach ($scoringArr as $type => $scoring){ $paperScore = isset($paperScoreSum[$pId])?$paperScoreSum[$pId]:0; if($paperScore > 0){ $typePaperRate[$pId][$type] = round($scoring/$paperScore,4) * 100; }else{ $typePaperRate[$pId][$type] = 0; } } } //题型答错人数 foreach ($stuTypeWrong as $type => $stuScore){ $wrongNum = 0; foreach ($stuScore as $stuId => $score){ if($score['score'] != $score['scoring']){ $wrongNum++; } } $stuTypeWrong[$type] = $wrongNum; } $result['class_rate'] = $classRate; $result['grade_rate'] = $gradeRate; $result['all_class_rate'] = $allClassRate; $result['type_paper_rate'] = $typePaperRate; $result['stu_type_wrong'] = $stuTypeWrong; $result['type_topic_no'] = $typeTopicNo; $result['type_master_degree'] = $typeMasterDegree; $result['type_name_arr'] = $typeNameArr; $result['topic_grade_rate'] = $_gradeRate; $result['topic_class_rate'] = $_classRate; return $result; } //共性问题变式训练 protected function getCommonPractice($paper_topic_detail,$stu_score_info,$stu_topic_rs,$large_topic_type_arr,$large_contain){ $class_wrong_topic = array(); $cls_grammar_topic = array(); $texturl_topic = array(); $common_push_topic = array(); $topic_method_arr = array(); $_push_all_topics = array(); $paper_topics = array_keys($large_topic_type_arr); foreach($paper_topic_detail as $topic_id=>$detail){ if(in_array($detail['type_id'],array(2,3,4,5,6,7,18,19))){ $topic_method_arr[$topic_id] = isset($detail['specials']) ? _array_column($detail['specials'],'method_id') : array(); if(isset($detail['slave'])){ foreach($detail['slave'] as $slave){ if(isset($slave['topic_slave_id'])){ $topic_method_arr[$slave['topic_slave_id']] = isset($slave['method_names']) ? _array_column($slave['method_names'],'method_id') : array(); } } } } } foreach($stu_score_info as $stu_id=>$score_info){ foreach($score_info as $large_topic_id=>$scoring){ if(isset($large_topic_type_arr[$large_topic_id])){ if(in_array($large_topic_type_arr[$large_topic_id],array(2,3,4,5))){ if(!isset($class_wrong_topic[$large_topic_id])){ $class_wrong_topic[$large_topic_id] = array('scoring'=>0,'score'=>0); } $_scoring = $class_wrong_topic[$large_topic_id]['scoring']; $_score = $class_wrong_topic[$large_topic_id]['score']; $class_wrong_topic[$large_topic_id] = array('scoring'=>($scoring['scoring']+$_scoring),'score'=>($scoring['score']+$_score)); }elseif(in_array($large_topic_type_arr[$large_topic_id],array(18,19))){ $small_topic = $large_contain[$large_topic_id]; $stu_topic_info = isset($stu_topic_rs[$stu_id]) ? $stu_topic_rs[$stu_id] : array(); if($stu_topic_info){ foreach($small_topic as $small_topic_id=>$score){ if(!isset($cls_grammar_topic[$large_topic_type_arr[$large_topic_id]][$small_topic_id])){ $cls_grammar_topic[$large_topic_type_arr[$large_topic_id]][$small_topic_id] = array('scoring'=>0,'score'=>0); } $stu_scoring = $stu_topic_info[$small_topic_id]; $_scoring = $cls_grammar_topic[$large_topic_type_arr[$large_topic_id]][$small_topic_id]['scoring']; $_score = $cls_grammar_topic[$large_topic_type_arr[$large_topic_id]][$small_topic_id]['score']; $cls_grammar_topic[$large_topic_type_arr[$large_topic_id]][$small_topic_id] = array('scoring'=>($stu_scoring['scoring']+$_scoring),'score'=>($score+$_score)); } } }elseif(in_array($large_topic_type_arr[$large_topic_id],array(6,7))){ $texturl_topic[] = $large_topic_id; } } } } $class_score_rate = array(); foreach($class_wrong_topic as $large_topic_id=>$score_info){ $score_rate = $this->scoreRate($score_info['scoring'],$score_info['score']); $class_score_rate[$large_topic_id] = $score_rate; } if ($class_score_rate) { asort($class_score_rate); reset($class_score_rate); $push_text_topic = key($class_score_rate); $text_detail = $paper_topic_detail[$push_text_topic]; $kps = _array_column($text_detail['specials'],'method_id'); $text_level = isset($text_detail['text_level']) ? $text_detail['text_level'] : 5; $cloze_type = 0; if ($text_detail['type_id'] == 2) { $cloze_type = count($text_detail['slave']) == 15 ? 1 : 2; } $rules = array(); $rules[] = array( 'type' => $text_detail['type_id'], 'size' => 600, 'cloze_type' => $cloze_type ); $params_eng = array(); $params_eng['subjectId'] = 10; $params_eng['rules'] = $rules; $params_eng['inMethodIds'] = $kps; $params_eng['isAudit'] = 2; $params_eng['notInTopicIds'] = $paper_topics; $type_topic_arr = $this->apiBrainPost('/relation_english/extract', $params_eng,25,true); if(isset($type_topic_arr[$text_detail['type_id']])){ $all_topic = array(); $extract_topics = $type_topic_arr[$text_detail['type_id']]; while($text_level>0){ if ($extract_topics[$text_level]) { $all_topic = $extract_topics[$text_level]; break; } $text_level--; } if($all_topic){ $push_topic_key = array_rand($all_topic,1); $common_push_topic['min_rate_text'][$text_detail['type_id']] = array('topic_id'=>$all_topic[$push_topic_key],'topic_type'=>$text_detail['type_id']); $_push_all_topics[$all_topic[$push_topic_key]] = $all_topic[$push_topic_key]; } } } $grammar_rules = array(); //班级错误率在50%及以上的 $grammar_score_rate = array(); $grammar_method = array(); foreach($cls_grammar_topic as $type=>$cgt_info){ foreach($cgt_info as $small_topic_id=>$score_info){ $score_rate = $this->scoreRate($score_info['scoring'],$score_info['score'],true); if($score_rate<50){ $grammar_score_rate[$type][$small_topic_id] = isset($topic_method_arr[$small_topic_id]) ? $topic_method_arr[$small_topic_id] : array(); } } } $topic_count = array('19'=>10,'18'=>0); foreach($grammar_score_rate as $type=>$gsr){ if($type == 6 || $type == 19){ $type = 19; } $grammar_rules[$type] = array( 'type' => 19, 'size' => 600 ); if(!isset($grammar_method[$type])){ $grammar_method[$type] = array(); } foreach($gsr as $item){ if($type == 18){ $topic_count[18] ++; } $grammar_method[$type] = array_merge($grammar_method[$type],$item); } } //$read_base_obj = new ReadBase(); foreach($grammar_rules as $type=>$gr){ $rules = array(); $rules[] = array( 'type' => $type, 'size' => 600 ); $params_eng = array(); $params_eng['subjectId'] = 10; $params_eng['rules'] = $rules; $params_eng['inMethodIds'] = isset($grammar_method[$type]) ? $grammar_method[$type] : array(); $params_eng['notInTopicIds'] = $paper_topics; $type_topic_arr = $this->apiBrainPost('/relation_english/extract', $params_eng,25,true); if($type_topic_arr){ if(isset($type_topic_arr[$type]) && $type_topic_arr[$type]){ $topics = reset($type_topic_arr[$type]); $push_topic_key = array_rand($topics,$topic_count[$type]); foreach($push_topic_key as $key){ $_push_all_topics[$topics[$key]] = $topics[$key]; $common_push_topic['common_grammar_topic'][$type][] = array('topic_id'=>$topics[$key],'topic_type'=>$type); } } } } $texturl_topic = array_unique($texturl_topic); foreach($texturl_topic as $t_id){ $rules = array(); $rules[] = array( 'type' => $paper_topic_detail[$t_id]['type_id'], 'size' => 600 ); $params_eng = array(); $params_eng['subjectId'] = 10; $params_eng['rules'] = $rules; $params_eng['inMethodIds'] = isset($topic_method_arr[$t_id]) ? $topic_method_arr[$t_id] : array(); $params_eng['notInTopicIds'] = $paper_topics; $type_topic_arr = $this->apiBrainPost('/relation_english/extract', $params_eng,25,true); if($type_topic_arr){ if(isset($type_topic_arr[$paper_topic_detail[$t_id]['type_id']]) && $type_topic_arr[$paper_topic_detail[$t_id]['type_id']]){ $topics = reset($type_topic_arr[$paper_topic_detail[$t_id]['type_id']]); if($topics){ $push_topic_key = array_rand($topics,1); $_push_all_topics[$topics[$push_topic_key]] = $topics[$push_topic_key]; $common_push_topic['common_extra'][$paper_topic_detail[$t_id]['type_id']] = array('topic_id'=>$topics[$push_topic_key],'topic_type'=>$paper_topic_detail[$t_id]['type_id']); } } } } return array($common_push_topic,$_push_all_topics); } /** * 班级排名得分率人数等数据 * @param $examId * @param $ptrInfo * @param $paperScore * @param $preExamId * @param $prePtrInfo * @param $prePaperScore * @return array */ private function getClassAnalyse($examId,&$ptrInfo,$paperScore,$preExamId,&$prePtrInfo,$prePaperScore,&$stuIdsArr,&$preStuIdsArr){ $result = array(); $gradePerson = $classPerson = 0;//参考人数 $gradeAbsentPerson = $classAbsentPerson = 0;//缺考人数 $gradeOrder = $classOrder = 0; //排名 $gradeAvgScore = $classAvgScore = 0; //平均分 $gradeScoreRate = $classScoreRate = 0; //得分率 $gradeFineRate = $classFineRate = 0; //优秀率 80% $gradePassRate = $classPassRate = 0; //合格率 60% $gradeLowRate = $classLowRate = 0; //低分率 30% $angData = array( 'class_num' => 0,//班级数量 'order' => 0, 'absent_person' => 0, 'exam_person' => 0, 'avg_score' => 0, 'score_rate' => 0, 'fine_rate' => 0, 'pass_rate' => 0, 'low_rate' => 0, ); $result['grade'] = $result['class'] = $angData; $gradeScoring = $classScoring = array(); $gradeScoringSum = array();//年级中每个考试的得分和 // $classScoringSum = 0;//考试得分和 $gradeStuScoringRate = $classStuScoringRate = array();//学生得分率 foreach($ptrInfo as $value){ $stuIds = isset($stuIdsArr[$value['exam_id']])?$stuIdsArr[$value['exam_id']]:array(); if(!isset($gradeScoringSum[$value['exam_id']])){ $gradeScoringSum[$value['exam_id']] = 0; } if(inArray($value['student_id'],$stuIds)){ $gradeScoringSum[$value['exam_id']] += $value['scoring']; $gradeScoring[] = $value['scoring']; $gradeStuScoringRate[] = round($value['scoring']/$paperScore,4)*100; $gradePerson++; } if(!inArray($value['student_id'],$stuIds)){ $gradeAbsentPerson++; } // if($examId == $value['exam_id']){ if(strcmp($examId ,$value['exam_id']) == 0){ if(inArray($value['student_id'],$stuIds)){ // $classScoringSum += $value['scoring']; $classScoring[] = $value['scoring']; $classStuScoringRate[] = round($value['scoring']/$paperScore,4)*100; $classPerson++; } if(!inArray($value['student_id'],$stuIds)){ $classAbsentPerson++; } } } unset($ptrInfo); $result['class']['class_num'] = count($gradeScoringSum); $result['grade']['exam_person'] = $gradePerson; $result['grade']['absent_person'] = $gradeAbsentPerson; $result['class']['exam_person'] = $classPerson; $result['class']['absent_person'] = $classAbsentPerson; //排名 if($gradeScoringSum){ $scoringArr = array(); foreach($gradeScoringSum as $eId => $scoring){ $stuCount = isset($stuIdsArr[$eId])?count($stuIdsArr[$eId]):0; if($stuCount){ $scoringArr[$eId] = round($scoring/$stuCount,2); } } if(isset($scoringArr[$examId])){ $classOrder = $this->getOrder($scoringArr[$examId],$scoringArr); }else{ $classOrder = 0; } } $result['class']['order'] = $classOrder; //平均分,得分率 $count = count($gradeScoring); if($count > 0){ $gradeAvgScore = round(array_sum($gradeScoring)/$count,2);//平均分 $gradeScoreRate = round(array_sum($gradeScoring)/($paperScore*$count),4)*100;//得分率 }else{ $gradeAvgScore = 0; $gradeScoreRate = 0; } $result['grade']['avg_score'] = $gradeAvgScore; $result['grade']['score_rate'] = $gradeScoreRate; $count = count($classScoring); if($count > 0){ $classAvgScore = round(array_sum($classScoring)/$count,2); $classScoreRate = round(array_sum($classScoring)/($paperScore*$count),4)*100;//得分率 }else{ $classAvgScore = 0; $classScoreRate = 0; } $result['class']['avg_score'] = $classAvgScore; $result['class']['score_rate'] = $classScoreRate; //优秀率,合格率,低分率 // $gradeFineRate = $classFineRate = 0; //优秀率 85% // $gradePassRate = $classPassRate = 0; //合格率 60% // $gradeLowRate = $classLowRate = 0; //低分率 30% $tempFineNum = $tempPassNum = $tempLowNum = 0; $rateCount = count($gradeStuScoringRate); foreach($gradeStuScoringRate as $scoringRate){ if($scoringRate >= 85){ $tempFineNum++; } if($scoringRate >= 60){ $tempPassNum++; } if($scoringRate <= 30){ $tempLowNum++; } } $gradeFineRate = round($tempFineNum/$rateCount,4) * 100; $gradePassRate = round($tempPassNum/$rateCount,4) * 100; $gradeLowRate = round($tempLowNum/$rateCount,4) * 100; $result['grade']['fine_rate'] = $gradeFineRate; $result['grade']['pass_rate'] = $gradePassRate; $result['grade']['low_rate'] = $gradeLowRate; $tempFineNum = $tempPassNum = $tempLowNum = 0; $rateCount = count($classStuScoringRate); foreach($classStuScoringRate as $scoringRate){ if($scoringRate >= 85){ $tempFineNum++; } if($scoringRate >= 60){ $tempPassNum++; } if($scoringRate <= 30){ $tempLowNum++; } } if($rateCount){ $classFineRate = round($tempFineNum/$rateCount,4) * 100; $classPassRate = round($tempPassNum/$rateCount,4) * 100; $classLowRate = round($tempLowNum/$rateCount,4) * 100; }else{ $classFineRate = 0; $classPassRate = 0; $classLowRate = 0; } $result['class']['fine_rate'] = $classFineRate; $result['class']['pass_rate'] = $classPassRate; $result['class']['low_rate'] = $classLowRate; /**************** 提升数据 ******************/ $result['class']['order_increase'] = 0; $result['class']['rate_increase'] = 0; $result['class']['fine_rate_increase'] = 0; if($prePtrInfo){ $preClassStuScoringRate = array(); $preGradeScoringSum = array(); $preClassScoringSum = 0; $preClassScoring = array(); if($prePtrInfo){ foreach($prePtrInfo as $value){ $stuIds = isset($preStuIdsArr[$value['exam_id']])?$preStuIdsArr[$value['exam_id']]:array(); if(!isset($preGradeScoringSum[$value['exam_id']])){ $preGradeScoringSum[$value['exam_id']] = 0; } if(inArray($value['student_id'],$stuIds)){ $preGradeScoringSum[$value['exam_id']] += $value['scoring']; } // if($preExamId == $value['exam_id']){ if(strcmp($preExamId ,$value['exam_id']) == 0){ if(inArray($value['student_id'],$stuIds)){ $preClassScoringSum += $value['scoring']; $preClassScoring[] = $value['scoring']; $preClassStuScoringRate[] = round($value['scoring']/$prePaperScore,4)*100; } } } } //上一次考试排名 if($gradeScoringSum){ $scoringArr = array(); foreach($preGradeScoringSum as $eId => $scoring){ $stuCount = isset($preStuIdsArr[$eId])?count($preStuIdsArr[$eId]):0; if($stuCount){ $scoringArr[$eId] = round($scoring/$stuCount,2); } } if(isset($scoringArr[$preExamId])){ $preClassOrder = $this->getOrder($scoringArr[$preExamId],$scoringArr); }else{ $preClassOrder = 0; } $result['class']['order_increase'] = -($classOrder - $preClassOrder); } $count = count($preClassScoring); if($count > 0){ $preClassScoreRate = round(array_sum($preClassScoring)/($prePaperScore*$count),4)*100;//得分率 $result['class']['rate_increase'] = $classScoreRate - $preClassScoreRate; } $tempFineNum = 0; $rateCount = count($preClassStuScoringRate); foreach($preClassStuScoringRate as $scoringRate){ if($scoringRate >= 85){ $tempFineNum++; } } if($rateCount){ $preClassFineRate = round($tempFineNum/$rateCount,4) * 100; }else{ $preClassFineRate = 0; } $result['class']['fine_rate_increase'] = $classFineRate - $preClassFineRate; } return $result; } /** * 大幅进步,大幅退步,前5名和后5名 * @param $examId * @param $ptrInfo * @param $paperScore * @param $preExamId * @param $prePtrInfo * @param $prePaperScore */ private function getLargeOrder($examId,&$ptrInfo,$preExamId,&$prePtrInfo,&$stuIdsArr,&$preStuIdsArr){ $result = array(); $stuOrderArr = $this->getStudentOrder($examId,$ptrInfo,$stuIdsArr); $diffNum = ceil(count($stuOrderArr)*0.2); if($prePtrInfo){ $preStuOrderArr = $this->getStudentOrder($preExamId,$prePtrInfo,$preStuIdsArr); }else{ $preStuOrderArr = array(); } if($preStuOrderArr){ $interOrderArr = array_intersect_key($stuOrderArr,$preStuOrderArr); if(!$interOrderArr){ $interOrderArr = $stuOrderArr; } }else{ $interOrderArr = array(); } //大幅进步,退步 $increaseArr = $reduceArr = array(); $stuDiffOrder = array(); if($interOrderArr){ foreach($stuOrderArr as $stuId => $order){ if(isset($interOrderArr[$stuId]) && isset($preStuOrderArr[$stuId])){ $stuDiffOrder[$stuId] = -($order - $preStuOrderArr[$stuId]); }else{ $stuDiffOrder[$stuId] = 0; } } arsort($stuDiffOrder); foreach($stuDiffOrder as $stuId => $num){ if($num >= $diffNum){ $increaseArr[] = $stuId; } } $increaseArr = array_slice($increaseArr,0,5,true); asort($stuDiffOrder); foreach($stuDiffOrder as $stuId => $num){ if($num <= -$diffNum){ $reduceArr[] = $stuId; } } $reduceArr = array_slice($reduceArr,0,5,true); }else{ $increaseArr = array_slice($stuOrderArr,0,5,true); $reduceArr = array(); } $result['stu_diff_order'] = $stuDiffOrder; $result['stu_order'] = $stuOrderArr; $result['increase_stu'] = $increaseArr; $result['reduce_stu'] = $reduceArr; //前5名和后5名 $font5 = $back5 = array(); $i = 1; $fonrt5_order = array(); foreach($stuOrderArr as $stuId => $order){ if($i <= 5){ $font5[] = $stuId; $fonrt5_order[] = $order; }else{ break; } $i++; } $result['font_five'] = $font5; $i = 1; //删除前5排名 $_stuOrderArr = $stuOrderArr; foreach($_stuOrderArr as $k => $order){ if(in_array($order,$fonrt5_order)){ unset($_stuOrderArr[$k]); } } arsort($_stuOrderArr); foreach($_stuOrderArr as $stuId => $order){ if($i <= 5){ $back5[] = $stuId; }else{ break; } $i++; } $result['back_five'] = $back5; //学生名称 $stuName = $this->getStudentNames(array_keys($stuOrderArr)); $result['stu_name'] = $stuName; unset($stuOrderArr); return $result; } function getStudentNames($studentIds){ $result = array(); $students = $this->sConn->createCommand("select student_id,realname,id_number from student_info where student_id in(".implode(',',$studentIds).") ")->queryAll(); if ($students) { foreach ($students AS $student) { $id_str = ''; if($student['id_number']){ $id_str = substr($student['id_number'],-4,4); } $result[$student['student_id']] = $student['realname'].$id_str; } } return $result; } /** * 调题的接口 * @param $path * @param $arr * @param int $type * @return bool|mixed */ public function apiBrainPost($path, $arr, $timeout=25,$is_array = false) { $ch = @curl_init(); $result = FALSE; if ($ch) { $data = json_encode($arr); $url = Yii::app()->params['api'][0]['prefix'] . $path; $username = Yii::app()->params['api'][0]['username']; $password = Yii::app()->params['api'][0]['password']; curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password); // 不输出头部 curl_setopt($ch, CURLOPT_HEADER, 0); // curl_exec 获取到的内容不直接输出, 而是返回 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_TIMEOUT,$timeout); // 请求重启路由器的地址 传参 进行重启 curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, 'Api Client/1.0.0 (chengfei@liancaitech.com)'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: '. strlen($data), )); if( !curl_errno($ch)) { $result = json_decode(curl_exec($ch),$is_array); } // 释放资源 curl_close($ch); } return $result; } /** * 获取学生排名 * @param $examId * @param $ptrInfo * @return array */ private function getStudentOrder($examId,&$ptrInfo,&$stuIdsArr){ $stuOrderArr = array(); $stuScoring = array(); foreach($ptrInfo as $value){ // if($examId == $value['exam_id']){ if(strcmp($examId ,$value['exam_id']) == 0){ $stuIds = isset($stuIdsArr[$value['exam_id']])?$stuIdsArr[$value['exam_id']]:array(); if(inArray($value['student_id'],$stuIds)){ $stuScoring[$value['student_id']] = $value['scoring']; } } } $scoringArr = array_values($stuScoring); foreach($stuScoring as $stuId => $scoring){ $stuOrderArr[$stuId] = $this->getOrder($scoring,$scoringArr); } if($stuOrderArr){ asort($stuOrderArr); } return $stuOrderArr; } /** * 获取排名 * @param $ele * @param $arr * @return false|int|string */ private function getOrder($ele,$arr){ $orderRs = 0; if($arr){ arsort($arr); $arr = array_values($arr); $index = array_search($ele,$arr); $orderRs = $index + 1; } return $orderRs; } //替换序号 private function replaceTitle(&$title,$topicId,$topicRelLarge,$smallTopicNo) { // $str = ''; $topicNoArr = array(); foreach ($topicRelLarge as $small_id => $large_id) { if ($topicId == $large_id && isset($smallTopicNo[$small_id])) { $topicNoArr[] = $smallTopicNo[$small_id]; } } $imgArr = array(); $pattern="//"; preg_match_all($pattern,$title,$match); if (isset($match[0]) && $match[0]) { foreach ($match[0] as $img) { $pattern="/data-num=[\"|\'](\d{0,2})[\"|\']/"; preg_match_all($pattern,$img,$match); if (isset($match[0]) && isset($match[1]) && isset($match[1][0])) { $imgArr[$match[1][0]] = $img; } } } if (count($imgArr) == count($topicNoArr)) { asort($topicNoArr); $searchArr = $replaceArr = array(); foreach ($topicNoArr as $key => $no) { $searchArr[] = isset($imgArr[$key]) ? $imgArr[$key] : ''; $replaceArr[] = ' ('.$no.') '; } $title = str_replace($searchArr, $replaceArr, $title); } } //获取词汇 private function getWord($condition){ $wordsInfo = array(); // $params = array( // '_id' => array('$in' => array_values($word_ids)) // ); // // return IspMongo::selectMongo('english_single',$params); $rs = $this->apiBrainPost('/zsytk2/getIspInfo', array('condition'=>$condition,'table' => 'en_single_word' ,'isAll' => 1),25,true); if (isset($rs['status']) && $rs['status']==1 && isset($rs['data']) && $rs['data']) { foreach ($rs['data'] as $v) { $wordsInfo[$v['single_word_id']] = $v; } } return $wordsInfo; } public function getExamIsTird($examGroupId,$examId){ if(!$examGroupId){ if($examId){ $_sql = "SELECT exam_group_id FROM exam where exam_id = ".$examId; $exam_info = $this->sConn->createCommand($_sql)->queryRow(); if(isset($exam_info['exam_group_id']) && $exam_info['exam_group_id']){ $examGroupId = $exam_info['exam_group_id']; } } } $sql="SELECT `is_third` FROM `exam_group` WHERE exam_group_id = {$examGroupId}" ; $res = $this->sConn->createCommand($sql)->queryRow(); if($res && isset($res['is_third'])){ return $res['is_third']?1:0; }else{ return false; } } public function getHasScoreStu($examIds){ $studentIds = array(); $sql = "select student_id,exam_id from student_paper_topic_rs as sptr join paper as p on sptr.paper_id = p.paper_id where p.exam_id in (".implode(',',$examIds).") and handlerIndex = 1"; $info = $this->sConn->createCommand($sql)->queryAll(); if($info){ foreach($info as $value){ if(!isset($studentIds[$value['exam_id']])){ $studentIds[$value['exam_id']] = array(); } $studentIds[$value['exam_id']][$value['student_id']] = $value['student_id']; } foreach($studentIds as $eId => $stuIds){ $studentIds[$eId] = array_keys($stuIds); } unset($info); } return $studentIds; } /** * 获取试卷题信息 * @param $examIds * @return array|CDbDataReader */ public function getStudentExamInfo($examIds){ $info = array(); if($examIds){ $sql = "select student_id,is_del,paper_id,exam_id,scoring,is_feedback,is_three_isp_download,is_two_isp_download from student_paper_relation where exam_id in (".implode(',',$examIds).") "; $info = $this->sConn->createCommand($sql)->queryAll(); if($info){ return $info; } } return $info; } public function getPaperScore($paperIds){ $score = 0; if($paperIds && is_array($paperIds)){ $paperIds = array_values($paperIds); $sql = "select score from paper where paper_id = {$paperIds[0]}"; $score = $this->sConn->createCommand($sql)->queryScalar(); } return $score; } public function getPreExamId($examId,$subjectId,$classId){ $examDate = $this->getExamTime($examId); $sql = "select cep.exam_id,e.exam_group_id from class_exam_printer as cep left join exam as e on e.exam_id = cep.exam_id where e.subject_id = {$subjectId} and cep.add_time < {$examDate} and e.class_id = {$classId} and cep.type = 0 and e.status = 1 order by add_time desc"; return $this->sConn->createCommand($sql)->queryRow(); } public function getExamTime($examId){ $sql = "select add_time from class_exam_printer where exam_id = {$examId} and type = 0"; return $this->sConn->createCommand($sql)->queryScalar(); } /** * 获取多个试卷学生做题记录 * @param $paperIds * @return array */ public function getStudentRs($paperIds){ $newInfo = array(); $_countSql = "select count(0) AS count from student_paper_topic_rs where paper_id in (".implode(',',$paperIds).") and handlerIndex = 1"; $counTinfo = $this->sConn->createCommand($_countSql)->queryRow(); $count = 0; if(isset($counTinfo['count'])){ $count = $counTinfo['count']; }else{ return $newInfo; } $limit = 20000; $page = ceil($count/$limit); $__sql = "select student_id,paper_id,`topic_id`,`type`,is_right,handlerIndex,answer,answer_url,scoring from student_paper_topic_rs where paper_id in (".implode(',',$paperIds).") and handlerIndex = 1"; for($i = 0;$i < $page ;$i++){ $offset = $i * $limit; $sql = $__sql." limit {$offset},{$limit}"; $info = $this->sConn->createCommand($sql)->queryAll(); if($info){ foreach($info as $value){ $temp['paper_id'] = $value['paper_id']; $temp['topic_id'] = $value['topic_id']; $temp['type'] = $value['type']; $temp['is_right'] = $value['is_right']; $temp['handlerIndex'] = $value['handlerIndex']; if($value['type'] == 1 || $value['type'] == 11){ $temp['answer'] = $value['answer']; }else{ $temp['answer'] = $value['answer_url']; } $temp['scoring'] = $value['scoring']; $newInfo[$value['student_id']][$value['topic_id']] = $temp; } } unset($info); } return $newInfo; } /** * 获取试卷大题题信息 * @param $paperId * @return array */ public function getPaperLargeTopicInfo($paperId){ $sql = "select large_topic_id,logic_type,logic_type_second,method_ids from paper_topic_large where paper_id = {$paperId}"; $info = $this->sConn->createCommand($sql)->queryAll(); $logicType = array(); $largeTopicMethod = array(); if($info){ foreach($info as $value){ if($value['logic_type_second'] > 0){ $value['logic_type'] .= '_'.$value['logic_type_second']; } $logicType[$value['large_topic_id']] = $value['logic_type']; $largeTopicMethod[$value['large_topic_id']] = explode(',',$value['method_ids']); } unset($info); } return array($logicType,$largeTopicMethod); } /** * 获取试卷题信息 * @param $paperId * @return array|CDbDataReader */ public function getPaperInfo($paperId){ $sql = "select topic_id,stem_id,`no`,score,`type`,method_ids,`order` from paper_topic_relation where paper_id = {$paperId} and is_delete = 0 order by `no`"; return $this->sConn->createCommand($sql)->queryAll(); } /** * 获取试卷题信息 * @param $paperId * @param $largeTopicType * @return array */ public function getPaperTopicInfo2($paperId,$largeTopicType,$subjectId,$examInfo){ if($paperId){ $info = $this->getPaperInfo($paperId); $aliasTopicNoArr = $this->getAliasTopicNo($info, $examInfo['tpl_data']); $topicScore = array();//题总分 $smallTopicScore = array();//小题总分 $topicNoArr = array();//题号 $smallTopicNoArr = array();//小题题号 $topicType = array();//题对应的题类型 $topicLogicType = array();//题对应的逻辑题类型 $topicRelLarge = array();//题id对应的大题id $topicRelMethod = array();//题id对应的考点 $topicTypeRelNo = array();//题型对应的题号 $topicNoSection = array();//英语和语文大题对应的区间 $paperTopicNo = array(); $topicRelTopicCount = array();//大题对应的小题数量 if($info){ $no = 0; $p_no = 1; $typeArr = array('A','B','C','D'); $typeNo = 0; $p_typeNo = 0; foreach($info as $value){ $t_id = $value['topic_id']; if (isset($aliasTopicNoArr[$t_id]) && $aliasTopicNoArr[$t_id]) { $value['no'] = $aliasTopicNoArr[$t_id]; } $smallTopicScore[$t_id] = $value['score']; $smallTopicNoArr[$t_id] = $value['no']; if($value['stem_id'] > 0){ $t_id = $value['stem_id']; } //题号 if($value['stem_id'] > 0){ if(!isset($topicNoArr[$t_id])){ $paperTopicNo[$t_id] = $p_no; $p_no++; } }else{ if($value['type'] == 17 || $value['type'] == 27){ $topicNoArr[$t_id] = $p_no.(isset($typeArr[$p_typeNo])?$typeArr[$p_typeNo]:'A'); $p_typeNo++; }else{ $topicNoArr[$t_id] = $p_no; $p_no++; } } if($value['type'] == 17 || $value['type'] == 27){ $topicNoArr[$t_id] = $no.(isset($typeArr[$typeNo])?$typeArr[$typeNo]:'A'); $typeNo++; }else{ $topicNoArr[$t_id] = $no; $no++; } //题型对应的题号 if(isset($largeTopicType[$t_id]) && $largeTopicType[$t_id]){ $t_type = (int)$largeTopicType[$t_id]; }else{ $t_type = $value['type']; } if(!isset($topicTypeRelNo[$t_type])){ $topicTypeRelNo[$t_type] = array(); } if(!inArray($no,$topicTypeRelNo[$t_type])){ $topicTypeRelNo[$t_type][$value['topic_id']] = $no; } //题分数 if(!isset($topicScore[$value['topic_id']])){ $topicScore[$value['topic_id']] = 0; } $topicScore[$value['topic_id']] += $value['score']; //题对应的题类型 $topicType[$value['topic_id']] = $value['type']; //题对应的逻辑题类型 if(isset($largeTopicType[$t_id])){ $topicLogicType[$value['topic_id']] = $largeTopicType[$t_id]; }else{ $topicLogicType[$value['topic_id']] = 0; } //题id对应的大题id $topicRelLarge[$value['topic_id']] = $value['stem_id']; //题对应的知识点 $topicRelMethod[$value['topic_id']] = explode(',',$value['method_ids']); //英语和语文大题对应的区间 if(!isset($topicNoSection[$t_id])){ $topicNoSection[$t_id] = array(); } $topicNoSection[$t_id][] = $value['no']; //小题数量 if (!isset($topicRelTopicCount[$t_id])) { $topicRelTopicCount[$t_id] = 0; } $topicRelTopicCount[$t_id]++; } } } unset($info); $tempSection = array(); foreach($topicNoSection as $t_id => $v){ $v_count = count($v); if($v_count > 1){ asort($v); $tempSection[$t_id] = $v[0].'-'.$v[$v_count - 1]; }else{ $tempSection[$t_id] = current($v); } } $topicNoArr = $tempSection; unset($tempSection); unset($topicNoSection); // if(inArray($paperType,array(0,1,2))){ // // }else{ // $topicNoArr = $paperTopicNo; // $smallTopicNoArr = array(); // } return array($smallTopicScore,$smallTopicNoArr,$topicScore,$topicNoArr,$topicType,$topicLogicType,$topicRelLarge,$topicRelMethod,$topicTypeRelNo,$topicRelTopicCount); } /** * 别名题号 * @param $paperTopicInfo * @param $tplData * @return array */ private function getAliasTopicNo($paperTopicInfo,$tplData) { $orderRelTopicId = array(); foreach ($paperTopicInfo as $info) { $orderRelTopicId[$info['order']] = strval($info['topic_id']); } $aliasTopicNoArr = array(); if ($tplData) { $tplDataArr = json_decode($tplData, true); if (isset($tplDataArr['new_items'])) { foreach ($tplDataArr['new_items'] as $item) { if (isset($item['id'])) { if(!isset($orderRelTopicId[$item['id']])) continue; $aliasTopicNoArr[$orderRelTopicId[$item['id']]] = $item['alias']; } } } } return $aliasTopicNoArr; } /** * 获取考试对应的试卷id * @param $examIds * @return array */ public function getPaperIdsByExamIds($examIds){ $paperIds = $examRelIds = array(); if($examIds && is_array($examIds)){ $sql = "select paper_id,exam_id from paper where exam_id in (".implode(',',$examIds).")"; $paperInfo = $this->sConn->createCommand($sql)->queryAll(); if($paperInfo){ foreach ($paperInfo as $item) { $paperIds[$item['exam_id']] = $item['paper_id']; $examRelIds[$item['paper_id']] = $item['exam_id']; } } } return array($paperIds,$examRelIds); } protected function getImage($ratePath,$timeMethodRate){ /* Create and populate the pData object */ $MyData = new pData(); $i = 1; foreach($timeMethodRate as $arr){ $MyData->addPoints($arr,"Probe {$i}"); $i++; if($i > 3){ break; } } // $MyData->addPoints(array(4,1,2,12,8,3),"Probe 1"); // $MyData->addPoints(array(3,12,15,8,5,5),"Probe 2"); // $MyData->addPoints(array(2,7,5,18,19,22),"Probe 3"); $MyData->setSerieTicks("Probe 2",4); $MyData->setSerieWeight("Probe 3",2); $MyData->setAxisName(0,"得分率"); $MyData->addPoints(array("上上次","上次","本次"),"Labels"); $MyData->setSerieDescription("Labels","Months"); $MyData->setAbscissa("Labels"); $MyData->setSerieShape(0,SERIE_SHAPE_TRIANGLE); /* Create the pChart object */ $myPicture = new pImage(700,230,$MyData); /* Turn of Antialiasing */ $myPicture->Antialias = FALSE; /* Add a border to the picture */ $myPicture->drawRectangle(0,0,699,229,array("R"=>0,"G"=>0,"B"=>0)); /* Write the chart title */ $myPicture->setFontProperties(array("FontName"=>str_replace("protected", "", Yii::app()->basePath)."fonts/pChart/msyh.ttf","FontSize"=>11)); $myPicture->drawText(150,35,"考点掌握情况变化趋势",array("FontSize"=>12,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); /* Set the default font */ $myPicture->setFontProperties(array("FontName"=>str_replace("protected", "", Yii::app()->basePath)."fonts/pChart/msyh.ttf","FontSize"=>8)); /* Define the chart area */ $myPicture->setGraphArea(60,40,650,200); /* Draw the scale */ $scaleSettings = array("XMargin"=>10,"YMargin"=>10,"Floating"=>TRUE,"GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE); $myPicture->drawScale($scaleSettings); /* Turn on Antialiasing */ $myPicture->Antialias = false; /* Draw the line chart */ // $myPicture->drawLineChart(); $myPicture->drawLineChart(array("ForceColor"=>true, "ForceR"=>0,"ForceG"=>0,"ForceB"=>0, "ForceAlpha"=>80)); $myPicture->drawPlotChart(array("DisplayValues"=>TRUE,"PlotBorder"=>TRUE,"BorderSize"=>2,"Surrounding"=>-60,"BorderAlpha"=>80)); /* Write the chart legend */ $myPicture->drawLegend(510,20,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL)); /* Render the picture (choose the best way) */ // $myPicture->autoOutput($ratePath);die; $myPicture->render($ratePath); } /** * 获取试卷选择题id * @param $topic_type_arr * @param $topic_logic_type_arr * @param $is_has_large */ protected function getChoiceIds($topic_type_arr,$topic_logic_type_arr,$subject_id,$paper_type) { $choice_ids = array(); $type_arr = array(); if (inArray($paper_type, array(0, 1, 2))) { if ($subject_id == 12) {//物理 $type_arr = array(1, 4, 5, 8, 9); } elseif ($subject_id == 13) {//化学 $type_arr = array(1); } elseif ($subject_id == 14) {//生物 $type_arr = array(1, 3, 4); } elseif ($subject_id == 15) {//政治 $type_arr = array(1, 3, 4, 6, 7); } elseif ($subject_id == 16) {//历史 $type_arr = array(1); } elseif ($subject_id == 17) {//地理 $type_arr = array(1, 3, 4); } } else { $type_arr = array(1, 11); } foreach ($topic_logic_type_arr as $t_id => $type) { if (inArray($type, $type_arr)) { $choice_ids[] = $t_id; } } // $diff_topic = array_diff(array_keys($topic_logic_type_arr), $choice_ids); if ($diff_topic) { foreach ($topic_type_arr as $t_id => $item) { if (inArray($t_id, $diff_topic) && inArray($item, array(1, 11))) { $choice_ids[] = $t_id; } } } return $choice_ids; } /** * 试题年级和班级得分率,答对和答错人数 * @param $stuRs * @param $topicScore * @param $paperId * @return array */ public function getTopicRateWrongPerson(&$stuRs,$topicScore,$paperId,&$stuIdsArr,$topicRelLarge,$choinceIds,$sutName,$topicLogicType){ $gradeRate = $classRate = array();//班级和年级得分率 $wrongStu = $rightStu = array();//答对答错人数 $isChoiceTopic = array(); $stuNormalIds = array(); foreach($stuIdsArr as $stuIds){ foreach ($stuIds as $stuId) { $stuNormalIds[$stuId] = 0; } } $gradeScoring = $classScoring = array(); $gradeScore = $classScore= array(); $doneTopicNum = array();//每题做题总人数 $stuScoring = $stuScore= array(); $classTopicScoring = array();//班级题得分 $choiceTopicWrong = array();//单选题答错统计 $stuLargeTopicScore = array();//学生大题得分统计 $largeContainScore = array(); $readingTopicIds = array(); $readingWrongStu = array(); //优化strcmp($paperId ,$value['paper_id']) == 0 $paperIndexArr = array(); foreach($stuRs as $stuId => $rs){ foreach($rs as $value){ $paperIndexArr[$value['paper_id']] = 0; } } if ($paperIndexArr) { $paperIndexArr = array_keys($paperIndexArr); $paperIndexArr = array_flip($paperIndexArr); } //当前paper_id的索引 $curPaperIndex = isset($paperIndexArr[$paperId]) ? $paperIndexArr[$paperId] : false; //阅读理解选项显示答错学生姓名 foreach ($topicLogicType as $tId=>$logicType) { if ($logicType == 3) { $readingTopicIds[] = $tId; } } foreach($stuRs as $stuId => $rs){ if(!isset($stuNormalIds[$stuId])){ continue; } foreach ($rs as $k => $value){ if(isset($topicRelLarge[$value['topic_id']]) && $topicRelLarge[$value['topic_id']] > 0){ $t_id = $topicRelLarge[$value['topic_id']]; }else{ $t_id = $value['topic_id']; } if(!isset($largeContainScore[$t_id])){ $largeContainScore[$t_id] = array(); } $largeContainScore[$t_id][$value['topic_id']] = $topicScore[$value['topic_id']]; if(!isset($stuLargeTopicScore[$stuId][$t_id])){ $stuLargeTopicScore[$stuId][$t_id] = array('scoring'=>0,'score'=>0); } $stuLargeTopicScore[$stuId][$t_id]['scoring'] += $value['scoring']; $stuLargeTopicScore[$stuId][$t_id]['score'] += $topicScore[$value['topic_id']]; $t_score = isset($topicScore[$value['topic_id']])?$topicScore[$value['topic_id']]:0; if(!isset($gradeScoring[$t_id])){ $gradeScoring[$t_id] = 0; } $gradeScoring[$t_id] += $value['scoring']; if(!isset($gradeScore[$t_id])){ $gradeScore[$t_id] = 0; } $gradeScore[$t_id] += $t_score; // if(strcmp($paperId,$value['paper_id']) == 0){ if(isset($paperIndexArr[$value['paper_id']]) && $paperId !== false && $paperIndexArr[$value['paper_id']] == $curPaperIndex){ if(!isset($classScoring[$t_id])){ $classScoring[$t_id] = 0; } $classScoring[$t_id] += $value['scoring']; if(!isset($classScore[$t_id])){ $classScore[$t_id] = 0; } $classScore[$t_id] += $t_score; if(!isset($wrongStu[$t_id])){ $wrongStu[$t_id] = array(); } // if($t_score != $value['scoring']){ // $wrongStu[$t_id][] = $stuId; // } if(!isset($doneTopicNum[$t_id])){ $doneTopicNum[$t_id] = array(); } $doneTopicNum[$t_id][] = $stuId; //学生得分率 if(!isset($stuScoring[$stuId])){ $stuScoring[$stuId] = array(); } if(!isset($stuScoring[$stuId][$t_id])){ $stuScoring[$stuId][$t_id] = 0; } $stuScoring[$stuId][$t_id] += $value['scoring']; if(!isset($stuScore[$stuId])){ $stuScore[$stuId] = array(); } if(!isset($stuScore[$stuId][$t_id])){ $stuScore[$stuId][$t_id] = 0; } $stuScore[$stuId][$t_id] += $t_score; //班级平均得分 if (!isset($classTopicScoring[$t_id])) { $classTopicScoring[$t_id] = array(); } $classTopicScoring[$t_id][] = $value['scoring']; //统计单选题答错人数 if (isset($topicLogicType[$t_id]) && $topicLogicType[$t_id] == 1) { if ($value['is_right'] != 1 && in_array($value['answer'],array('A','B','C','D','E'))) { if (!isset($choiceTopicWrong[$t_id])) { $choiceTopicWrong[$t_id] = array(); } if (!isset($choiceTopicWrong[$t_id][$value['answer']])) { $choiceTopicWrong[$t_id][$value['answer']] = 0; } $choiceTopicWrong[$t_id][$value['answer']]++; } } } if (in_array($value['topic_id'],$readingTopicIds)) { if (empty($value['is_right']) && $value['answer']) { if (!isset($readingWrongStu[$value['topic_id']])) { $readingWrongStu[$value['topic_id']][$value['answer']] = array(); } if (isset($sutName[$stuId])) { $readingWrongStu[$value['topic_id']][$value['answer']][] = $sutName[$stuId]; } } } } } //年级得分率 foreach($gradeScoring as $tId => $scorings){ if(isset($gradeScore[$tId]) && $gradeScore[$tId] > 0){ $gradeRate[$tId] = round($scorings/$gradeScore[$tId],4) * 100; }else{ $gradeRate[$tId] = 0; } } //班级得分率 foreach ($classScoring as $tId => $scoring){ if(isset($classScore[$tId]) && $classScore[$tId] > 0){ $classRate[$tId] = round($scoring/$classScore[$tId],4) * 100; }else{ $classRate[$tId] = 0; } } //答错人数 foreach ($stuScore as $stuId => $tScores){ if(isset($stuScoring[$stuId])){ foreach ($tScores as $tId => $score){ $_scoring = isset($stuScoring[$stuId][$tId])?$stuScoring[$stuId][$tId]:0; if($score != $_scoring){ $wrongStu[$tId][] = $stuId; } } } } if($wrongStu){ foreach($wrongStu as $key => $stuIds){ $stuIds = array_unique($stuIds); $wrongStu[$key] = count($stuIds); if(isset($doneTopicNum[$key])){ $_stuIds = array_unique($doneTopicNum[$key]); $rightStu[$key] = count($_stuIds) - $wrongStu[$key]; } } } //题得分率低于70%的学 $rateLess70 = array(); if($stuScoring){ foreach($stuScoring as $stuId => $tScoring){ $stuScoreArr = isset($stuScore[$stuId])?$stuScore[$stuId]:array(); foreach ($tScoring as $tId => $scoring){ if(!isset($rateLess70[$tId])){ $rateLess70[$tId] = array(); } if(isset($stuScoreArr[$tId]) && $stuScoreArr[$tId] > 0){ $tempRate = round($scoring/$stuScoreArr[$tId],4) * 100; }else{ $tempRate = 0; } if(inArray($tId,$choinceIds)){ if($tempRate < 100 && !inArray($stuId,$rateLess70[$tId])){ $rateLess70[$tId][] = $stuId; } $isChoiceTopic[] = $tId; }else{ if($tempRate < 70 && !inArray($stuId,$rateLess70[$tId])){ $rateLess70[$tId][] = $stuId; } } } } } foreach ($rateLess70 as $tId => $stuIds){ $nameArr = array(); foreach ($stuIds as $stuId){ $nameArr[] = isset($sutName[$stuId])?$sutName[$stuId]:''; } $rateLess70[$tId] = implode('、',$nameArr); } //大题对应的小题个数 $large_rel_count = array(); foreach ($topicRelLarge as $tId => $ltId) { if (!isset($large_rel_count[$ltId])) { $large_rel_count[$ltId] = 0; } $large_rel_count[$ltId]++; } //班级平均分 $classTopicAvg = array(); foreach ($classTopicScoring as $tId => $scorings) { if ($scorings) { $classTopicAvg[$tId] = round(array_sum($scorings) / (count($scorings)/$large_rel_count[$tId]),2); }else{ $classTopicAvg[$tId] = 0; } } unset($classTopicScoring); //低于班级平均分 $rateLessAvg = array(); if($stuScoring){ foreach($stuScoring as $stuId => $tScoring){ foreach ($tScoring as $tId => $scoring){ if(!isset($rateLessAvg[$tId])){ $rateLessAvg[$tId] = array(); } if(isset($classTopicAvg[$tId]) && $scoring < $classTopicAvg[$tId]){ $rateLessAvg[$tId][$stuId] = $scoring; } } } } foreach ($rateLessAvg as $tId => $stuScoring){ if ($stuScoring) { asort($stuScoring); $nameArr = array(); foreach ($stuScoring as $stuId => $scoring){ $nameArr[] = isset($sutName[$stuId])?$sutName[$stuId]:''; } $rateLessAvg[$tId] = implode('、',$nameArr); }else{ $rateLessAvg[$tId] = ''; } } foreach ($readingWrongStu as $tId=>$val){ foreach ($val as $option=>$stuArr) { $readingWrongStu[$tId][$option] = implode('、',$stuArr); } } $result = array(); $result['grade_rate'] = $gradeRate; $result['class_rate'] = $classRate; $result['wrong_stu'] = $wrongStu; $result['right_stu'] = $rightStu; $result['rate_less_70'] = $rateLess70; $result['rate_less_avg'] = $rateLessAvg; $result['is_choice_topic'] = $isChoiceTopic; $result['choice_topic_wrong'] = $choiceTopicWrong; $result['large_topic_score'] = $stuLargeTopicScore; $result['large_contain_score'] = $largeContainScore; $result['reading_wrong_stu'] = $readingWrongStu; $gradeScoring = $classScoring = array(); $gradeScore = $classScore= array(); $doneTopicNum = array();//每题做题总人数 unset($gradeScoring); unset($classScoring); unset($gradeScore); unset($classScore); unset($doneTopicNum); unset($stuScoring); unset($stuScore); return $result; } function scoreRate($scoring,$total_score,$is_per = false) { if ($total_score > 0) { if ($is_per) { $pre_rate = 100; $decimal = 4; }else{ $pre_rate = 1; $decimal = 2; } return round($scoring/$total_score,$decimal)*$pre_rate; }else{ return 0; } } private function handleWordClass($keyWords){ $word_ids = _array_column($keyWords,'single_word_id'); $rs = $this->apiBrainPost('/zsytk2/getIspInfo', array('condition'=>array('single_word_id'=>$word_ids),'table' => 'en_single_word_label' ,'isAll' => 1),25,true); if (isset($rs['status']) && $rs['status']==1 && isset($rs['data']) && $rs['data']) { $label_ids = array(); $swm_ids = array(); foreach ($rs['data'] as $key=>$v) { if ($v['label_type_id'] == 3) { unset($rs['data'][$key]); } if ($v['label_type_id'] == 7) { $label_ids[] = $v['label_id']; $swm_ids[] = $v['swm_id']; } } $rel = array(); if ($label_ids) { $label_rs = $this->apiBrainPost('/zsytk2/getIspInfo', array('condition'=>array('label_id'=>$label_ids),'table' => 'en_label' ,'isAll' => 1),25,true); if (isset($label_rs['status']) && $label_rs['status']==1 && isset($label_rs['data']) && $label_rs['data']) { $rel = array(); foreach ($label_rs['data'] as $v) { $rel[$v['label_id']] = $v['content']; } } } foreach ($rs['data'] as &$item) { $item['content'] = isset($rel[$item['label_id']]) ? $rel[$item['label_id']] : ''; } unset($item); $new_swm_res = array(); if ($swm_ids) { $swm_rs = $this->apiBrainPost('/zsytk2/getIspInfo', array('condition'=>array('swm_id'=>$swm_ids),'table' => 'en_single_word_mean' ,'isAll' => 1),25,true); if (isset($swm_rs['status']) && $swm_rs['status']==1 && isset($swm_rs['data']) && $swm_rs['data']) { foreach ($swm_rs['data'] as $item) { $new_swm_res[$item['swm_id']] = $item; } } } $new_res = array(); $res = $rs['data']; foreach($res as $res_val){ $s_id = $res_val['single_word_id']; if (!isset($new_res[$s_id])) { $new_res[$s_id] = array('con_str'=>'','swm_ids'=>array(),'single_word_id'=>$s_id); } $new_res[$s_id]['con_str'] .= $res_val['content']; $new_res[$s_id]['swm_ids'][] = $res_val['swm_id']; if ($res_val['swm_id']) { $new_res[$s_id]['swm_con'][$res_val['swm_id']] = $res_val['content']; } } $_tmp_res = array(); foreach ($new_res as $tmp) { $single_id = $tmp['single_word_id']; $swm_ids = array_filter($tmp['swm_ids']); if (!isset($_tmp_res[$single_id])) { $_tmp_res[$single_id] = ''; } if ($swm_ids) { foreach ($swm_ids as $_id) { if (isset($new_swm_res[$_id])){ $_tmp_res[$single_id] .= ' '.$tmp['swm_con'][$_id]." {$new_swm_res[$_id]['mean']} "; } } } } foreach($keyWords as &$val){ $val['word_class'] = isset($new_res[$val['single_word_id']]) ? $new_res[$val['single_word_id']]['con_str'] : ''; $val['new_mean'] = isset($_tmp_res[$val['single_word_id']]) ? $_tmp_res[$val['single_word_id']] : ''; } } return $keyWords; } /** * 英语题型新转老 */ public function getTopicTypeRelate(){ return array( '553'=> '1', '28'=> '1', '554'=> '2', '41'=> '2', '555'=> '3', '42'=> '3', '281'=> '4', '566'=> '4', '556'=> '5', '44'=> '5', '563'=> '6', '278'=> '6', '286'=> '7', '570'=> '7', '47'=> '8', '557'=> '8', '282'=> '9', '567'=> '9', '279'=> '10', '564'=> '10', '288'=> '11', '572'=> '11', '285'=> '12', '444'=> '13', '741'=> '13', '280'=> '14', '565'=> '14', '287'=> '15', '571'=> '15', '116' =>'17', '562' =>'17', '54' =>'18', '559' =>'18', '55' =>'19', '560' =>'19', '56' =>'20', '561' =>'20', '428'=>'21' ); } //全学科试题详情兼容 public function quanTopicDetail($data){ $result = array(); $answer_arr = array("A","B","C","D","E","F","G","H","I","J"); $getTopicTypeRelate = $this->getTopicTypeRelate(); if($data){ foreach($data as $k=>$v){ $temp_basic_type_id = isset($v['basic_type_id'])?$v['basic_type_id']:1; $result[$k]['topic_id'] = $v['id']; $result[$k]['id'] = $v['id']; if(isset($v['bank_type']) && $v['bank_type']){ $temp_type_id = $v['bank_type']; }else{ $temp_type_id = $v['type_id']; } $result[$k]['type'] = $result[$k]['type_id'] = isset($getTopicTypeRelate[$temp_type_id])?$getTopicTypeRelate[$temp_type_id]:$temp_type_id; $result[$k]['queBody'] = $v['title']; $result[$k]['title'] = $v['title']; $result[$k]['analysis'] = $v['parse_content']; $result[$k]['parse_content'] = $v['parse_content']; $result[$k]['slave'] = array(); $result[$k]['items'] = array(); $result[$k]['answer'] = ''; $result[$k]['answer_str'] =''; $result[$k]['key_words_levels'] = array(); $result[$k]['key_words'] = array(); $result[$k]['isp_ids'] = array(); $result[$k]['text_level'] = 0; $result[$k]['method_id_arr'] = array(); $result[$k]['sentences_analysis'] = ''; $result[$k]['topic_solution'] = ''; $result[$k]['model_essay_point'] = ''; $result[$k]['new_key_words'] = array(); if(isset($v['kps']) && $v['kps']){ foreach($v['kps'] as $kps){ $result[$k]['method_id_arr'][] = $kps['kp_id']; } } if(isset($v['affiliate']) && $v['affiliate']){ foreach($v['affiliate'] as $aff){ if(isset($aff['field_key']) && $aff['field_key']=='tag_8_118'){ $result[$k]['text_level'] = isset($aff['field_value'])?$aff['field_value']:0; } if(isset($aff['field_name']) && $aff['field_name']=='长难句解析'){ $result[$k]['sentences_analysis'] = $aff['field_value']; } if(isset($aff['field_name']) && $aff['field_name']=='审题思路'){ $result[$k]['topic_solution'] = $aff['field_value']; } if(isset($aff['field_name']) && $aff['field_name']=='范文亮点'){ $result[$k]['model_essay_point'] = $aff['field_value']; } if(isset($aff['field_name']) && $aff['field_name']=='词汇积累'){ if(isset($aff['field_value']) && $aff['field_value']){ $temp_chjl = strip_tags($aff['field_value']); $strPattern = "/(?<=\()[^\)]+/"; preg_match_all($strPattern, $temp_chjl,$result_words); if(isset($result_words[0]) && $result_words[0]){ $single_word_ids = $result_words[0]; $single_word_data = $this->apiBrainPost('/all_library/getSingleWords', array("single_word_id"=>$single_word_ids),25,true); if($single_word_data && $single_word_data['data']){ $temp_single_word_data = $single_word_data['data']; foreach($temp_single_word_data as $temp_single_word_data_k=>$temp_single_word_data_v){ $result[$k]['new_key_words'][] = array( "content"=>isset($temp_single_word_data_v['content'])?$temp_single_word_data_v['content']:'', "phonetic_symbol"=>isset($temp_single_word_data_v['phonetic_symbol'])?$temp_single_word_data_v['phonetic_symbol']:'', "new_mean"=>isset($temp_single_word_data_v['mean'])?$temp_single_word_data_v['mean']:'' ); } } } } } } } if(isset($v['slave']) && $v['slave']){ //七选五特殊处理 if($result[$k]['type_id'] == 5){ foreach($v['slave'] as $slave_k=>$slave_v){ if(isset($slave_v['items']) && isset($slave_v['items']['options']) && $slave_v['items']['options']){ foreach($slave_v['items']['options'] as $option_k=>$option_v){ if($option_v["option_correct"]){ $v['slave'][$slave_k]['items']['options'][$option_k] = array("option_content"=>isset($answer_arr[$option_k])?$answer_arr[$option_k]:''); } } } } } $result[$k]['slave'] = $v['slave']; }else{ $result[$k]['items'] = $v['items']; $options_arr = array(); if($v['items'] && isset($v['items'][0]) && isset($v['items'][0]['options'])){ $options_arr = $v['items'][0]['options']; if($v['items'][0]['options'] && count($v['items'][0]['options']) == 1){ foreach($v['items'][0]['options'] as $op_v){ $result[$k]['answer'] = $op_v['option_content']; } } } $result[$k]['slave'][] = array('topic_slave_id'=>$v['id'],'items'=>array('options'=>$options_arr)); } } } return $result; } }