/** * 生成测试报告 */ public function general_report() { $this->load->model('demo/report/subject_question_model', 'sq_model'); $this->load->model('demo/report/subject_suggest_model', 'ss_model'); $now = time(); //考试期次 $userdata = $this->session->all_userdata(); //检查该考试是否已经考完 && 作弊 if (!isset($userdata['report_mark'])) { return false; } list($exam_pid, $subject_id, $uid, $exam_id) = explode('_', $userdata['report_mark']); $subject_name = C('subject/' . $subject_id); $filepath = $this->_get_cache_root_path() . "/html/demo_report/{$exam_pid}/{$uid}/{$subject_id}.html"; if (file_exists($filepath)) { return true; } try { //生成成绩 //require_once ('exam.php'); //$exam_cron = new Exam(); //$exam_cron->cal_test_score($exam_pid, $uid); $result = ExamstatModel::calStudentResults($exam_pid, $uid); if (!$result) { return false; } //统计报告所需数据 $result = SummaryModel::summary_demo($exam_pid, $uid); if (!$result) { return false; } //检查该学生是否作弊 & 正在考中 $sql = "select etp_flag, full_score, test_score \n\t\t\t from {pre}exam_test_paper \n\t\t\t where exam_pid={$exam_pid} and subject_id={$subject_id} and uid={$uid}"; $result = $this->db->query($sql)->row_array(); if (isset($result['etp_flag']) && $result['etp_flag'] != '2') { return false; } $data = array(); $data['subject_name'] = $subject_name; $data['test_score'] = $result['test_score']; $data['full_score'] = $result['full_score']; //试题分析及与之对应的评价 $data['sq_all'] = $this->sq_model->get_all($exam_id, $uid); //知识点 //诊断及建议 $data['ss_summary'] = $this->ss_model->module_summary($exam_id, $uid); //总体水平等级和排名 $data['ss_application_situation'] = $this->ss_model->module_application_situation($exam_id, $uid); //总体水平等级和排名 $output = $this->load->view('../demo/report/subject', $data, true); //保存html模板 $res = $this->_put_html_content($exam_pid, $subject_id, $uid, $output); return $res; } catch (Exception $e) { return false; } }
public function get_outside_exam_student_result() { set_time_limit(0); $this->load->model('cron/cron_exam_result_model', 'cer_model'); $exam_list = $this->cer_model->get_task_exam_list(); if ($exam_list) { foreach ($exam_list as $item) { $result = ExamstatModel::calOutsideExamResults($item['exam_pid']); if ($result) { $this->cer_model->set_task_exam_result_status(array('status' => 1), $item['id']); } } } }
/** * 将阅卷系统成绩同步到测评系统中 * @param int $er_examid 考试id * @param int $er_zmoss_examid 阅卷考试id * @return bool true|false */ public static function syncZmossExamResults($er_examid, $er_zmoss_examid) { if (!Validate::isInt($er_examid) || $er_examid <= 0 || !Validate::isInt($er_zmoss_examid) || $er_zmoss_examid <= 0) { return false; } $db = Fn::db(); $examrelate = self::examRelateInfo($er_examid, $er_zmoss_examid); if (!$examrelate || !$examrelate['er_exampid']) { return false; } $examrelatequestion = self::examRelateQuestionInfo($er_examid, $er_zmoss_examid); if (!$examrelatequestion) { return false; } $sql = "SELECT COUNT(*) FROM rd_exam_test_result\n WHERE exam_id = ?"; if (!$db->fetchOne($sql, array($er_examid))) { return false; } $questionrelate = array(); foreach ($examrelatequestion as $item) { $questionrelate[$item['erq_paperid']] = json_decode($item['erq_relate_data'], true); } $psql = Fn::db_pg(); $zmoss_examid = $examrelate['er_zmoss_examid']; //检查考试阅卷是否已完成 $sql = "SELECT exam_id FROM t_exam\n WHERE exam_id = ? AND exam_flag = 6"; if (!$psql->fetchRow($sql, array($zmoss_examid))) { return false; } //查询所有学生客观题得分 $sql = "SELECT stu_exam_ticket, soqa_quesid, soqa_testscore, ques_fullscore\n FROM t_student\n LEFT JOIN v_student_objective_question_answer ON soqa_stuid = stu_id\n WHERE soqa_examid = ? AND soqa_flag = 1"; $stmt = $psql->query($sql, array($zmoss_examid)); $list = array(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $list[trim($row['stu_exam_ticket'])][$row['soqa_quesid']] = array('full_score' => $row['ques_fullscore'], 'test_score' => $row['soqa_testscore']); } if (!$list) { return false; } //查询所有学生主观题得分 $sql = "SELECT stu_exam_ticket, ques_id, ques_fullscore, etsq_testscore\n FROM t_student\n LEFT JOIN t_evaluation_task_student_question ON etsq_stuid = stu_id\n LEFT JOIN t_question ON ques_id = etsq_quesid\n WHERE ques_examid = ?"; $stmt = $psql->query($sql, array($zmoss_examid)); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $list[trim($row['stu_exam_ticket'])][$row['ques_id']] = array('full_score' => $row['ques_fullscore'], 'test_score' => $row['etsq_testscore']); } if (!$db->beginTransaction()) { return false; } $sql = "SELECT etp.etp_id, etp.paper_id, s.external_account, etp.uid\n FROM rd_exam_test_paper etp\n LEFT JOIN rd_student s ON s.uid = etp.uid\n WHERE etp.exam_id = ?"; $stmt = $db->query($sql, array($er_examid)); $uids = array(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { @(list($etp_id, $paper_id, $exam_ticket, $uid) = array_values($row)); $uids[] = $uid; $exam_ticket = trim($exam_ticket); $ques_score = $list[$exam_ticket]; if (!$ques_score) { continue; } $question = $questionrelate[$paper_id]; if (!$question) { continue; } foreach ($question as $ques_id => $zmoss_quesid) { $bind = array('full_score' => $ques_score[$zmoss_quesid]['full_score'], 'test_score' => $ques_score[$zmoss_quesid]['test_score']); $db->update('rd_exam_test_result', $bind, 'etp_id = ? AND (ques_id = ? OR sub_ques_id = ?)', array($etp_id, $ques_id, $ques_id)); } } if ($uids) { foreach ($uids as $uid) { ExamstatModel::calculatePaperScore($examrelate['er_exampid'], $uid); //计算试卷得分 } } $sql = "SELECT COUNT(*) FROM t_exam_relate\n WHERE er_exampid = ? AND er_flag < 3"; if (!$db->fetchOne($sql, array($examrelate['er_exampid']))) { //所有考场均已完成成绩导入计算 ExamstatModel::updateQuestionScore($examrelate['er_exampid'], 0, true); //更新试题分数 ExamstatModel::updateExamQuestionstat($examrelate['er_exampid']); //更新试卷试题答题情况 $bind = array('exam_pid' => $examrelate['er_exampid'], 'status' => 1, 'c_time' => time()); $db->replace('rd_cron_task_exam_result', $bind); } $flag = $db->commit(); if (!$flag) { $db->rollBack(); } return $flag; }
public function calculate() { $db = Fn::db(); $sql = "SELECT * FROM tmp_table9700 \n WHERE uid = 0 AND s = 0"; $stmt = $db->query($sql); $place_list = array(); while ($item = $stmt->fetch(PDO_DB::FETCH_ASSOC)) { $place_list[$item['place_id']][$item['subject_id']][] = $item; } if ($place_list && $db->beginTransaction()) { $start = time(); foreach ($place_list as $place_id => $data_subject) { $sql = "SELECT COUNT(*) FROM rd_exam_test_paper \n WHERE place_id = ?"; if (!$db->fetchOne($sql, array($place_id))) { continue; } foreach ($data_subject as $subject_id => $item) { //每次执行2分钟 if (time() - $start >= 120) { break 2; } $ques_id = array_slice(json_decode($item[0]['k'], true), 5); $full_score = array_slice(json_decode($item[1]['k'], true), 5); if (!$ques_id || !$full_score) { continue; } //修改状态为正在处理中 $db->update('tmp_table9700', array('s' => 3), 'place_id = ? AND subject_id = ? AND uid = 0', array($place_id, $place_id)); $sql = "SELECT * FROM tmp_table9700 \n WHERE place_id = ? AND subject_id = ? \n AND s = 0 AND uid > 0 limit 10000"; $stmt = $db->query($sql, array($place_id, $subject_id)); while ($val = $stmt->fetch(PDO_DB::FETCH_ASSOC)) { $data = array_slice(json_decode($val['k'], true), 5); $sql = "SELECT etp_id FROM rd_exam_test_paper\n WHERE place_id = ? AND uid = ? AND subject_id = ?"; $etp_id = $db->fetchOne($sql, array($place_id, $val['uid'], $subject_id)); if (!$etp_id) { continue; } foreach ($ques_id as $k => $q_id) { if (!$q_id || !Validate::isInt($q_id) || !$full_score[$k]) { continue; } $bind = array('full_score' => $full_score[$k], 'test_score' => $data[$k] > $full_score[$k] ? $full_score[$k] : $data[$k]); $db->update('rd_exam_test_result', $bind, 'etp_id = ? AND (ques_id = ? OR sub_ques_id = ?)', array($etp_id, $q_id, $q_id)); } } //修改正在进行状态为计算已完成 $db->update('tmp_table9700', array('s' => 1), 'place_id = ? AND subject_id = ?', array($place_id, $subject_id)); } } if (!$db->commit()) { $db->rollBack(); } } //计算已经更新完成的所有考试的学生成绩 $sql = "SELECT DISTINCT(a.exam_pid) FROM rd_exam_place a\n LEFT JOIN tmp_table9700 b ON a.place_id = b.place_id\n WHERE uid = 0 AND s IN (0, 3)\n "; $exam_pids = $db->fetchCol($sql); if ($db->beginTransaction()) { $sql = "SELECT DISTINCT(a.exam_pid) FROM rd_exam_place a\n LEFT JOIN tmp_table9700 b ON a.place_id = b.place_id\n WHERE uid = 0 AND s = 1\n "; $exam_pids2 = $db->fetchCol($sql); foreach ($exam_pids2 as $exam_pid) { if ($exam_pids && in_array($exam_pid, $exam_pids)) { continue; } $sql = "UPDATE tmp_table9700 SET s = 2 \n WHERE place_id IN (\n SELECT place_id FROM rd_exam_place \n WHERE exam_pid = {$exam_pid}\n )"; $db->query($sql); //所有考场均已完成成绩导入计算 ExamstatModel::calculatePaperScore($exam_pid); //计算试卷得分 ExamstatModel::updateQuestionScore($exam_pid, 0, true); //更新试题分数 ExamstatModel::updateExamQuestionstat($exam_pid); //更新试卷试题答题情况 $bind = array('exam_pid' => $exam_pid, 'status' => 1, 'c_time' => time()); $db->replace('rd_cron_task_exam_result', $bind); } } if (!$db->commit()) { $db->rollBack(); } }