public function getRightProgramCount($user_id, $eid, $start_timeC, $end_timeC) { $questionArr = QuestionBaseModel::instance()->getQuestionIds4ExamByType($eid, ProblemService::PROGRAM_PROBLEM_TYPE); $questionIds = array(); foreach ($questionArr as $_q) { $questionIds[] = $_q['question_id']; } if (empty($questionIds)) { return 0; } $questionIdStr = implode('\',\'', $questionIds); $questionIdStr = '\'' . $questionIdStr . '\''; $count = 0; // oj的pass_rate对于正确的时候不准, 添加这个作为容错处理 $rightProgramQuery = "select distinct(problem_id) as problem_id from solution where problem_id in ({$questionIdStr}) and " . "user_id='{$user_id}' and result=4 and in_date>'{$start_timeC}' and in_date<'{$end_timeC}'"; $rightIdAns = M()->query($rightProgramQuery); $rightIds = array(); foreach ($rightIdAns as $p) { $rightIds[] = $p['problem_id']; $count = $count + 1; } $otherIds = array_diff($questionIds, $rightIds); if (empty($otherIds)) { return $count; } $otherIdStr = implode('\',\'', $otherIds); $questionIdStr = '\'' . $otherIdStr . '\''; $query = "select max(pass_rate) as rate from solution where problem_id in ({$questionIdStr}) and " . "user_id='{$user_id}' and in_date>'{$start_timeC}' and in_date<'{$end_timeC}' group by problem_id"; $data = M()->query($query); foreach ($data as $d) { if ($d['rate'] >= 0.98) { $count = $count + 1; } else { $count = $count + $d['rate']; } } return $count; }
public function programRank() { $this->isCanWatchInfo($this->eid); $where = array('exam_id' => $this->eid, 'type' => 4, 'answer_id' => 1); $field = array('user_id', 'question_id', 'answer'); $programRank = M('ex_stuanswer')->field($field)->where($where)->select(); $userRank = array(); $users = array(); $unames = array(); $programCount = array(); $query = "select user_id, count(distinct question_id) as cnt" . " from ex_stuanswer where exam_id = " . $this->eid . " and type = 4 and answer_id = 1 and answer = 4 group by user_id order by cnt desc"; $acCount = M()->query($query); foreach ($acCount as $ac) { $programCount[$ac['user_id']] = $ac['cnt']; $users[] = $ac['user_id']; } foreach ($programRank as $p) { $userRank[$p['user_id']][$p['question_id']] = $p['answer']; if (!in_array($p['user_id'], $users)) { $users[] = $p['user_id']; } } $userIds_chunk = array_chunk($users, 50); foreach ($userIds_chunk as $_userIds) { $where = array('user_id' => array('in', $_userIds)); $field = array('user_id', 'nick'); $_unames = M('users')->field($field)->where($where)->select(); foreach ($_unames as $_uname) { $unames[$_uname['user_id']] = $_uname['nick']; } usleep(10000); } $query = array('exam_id' => $this->eid, 'type' => ProblemService::PROGRAM_PROBLEM_TYPE, 'order' => 'exp_qid'); $programs = QuestionBaseModel::instance()->queryData($query, array('question_id')); $this->zadd('unames', $unames); $this->zadd('userIds', $users); $this->zadd('programIds', $programs); $this->zadd('userRank', $userRank); $this->zadd('programCount', $programCount); $this->auto_display('ranklist'); }
public function addProgramProblem() { if (IS_POST && I('post.eid')) { if (!check_post_key()) { $this->echoError('发生错误!'); } else { if (!$this->isCreator()) { $this->echoError('You have no privilege of this exam'); } else { $eid = I('post.eid', 0, 'intval'); $flag = ProblemService::instance()->addProgram2Exam($eid); if ($flag === true) { $this->success('程序题添加成功', U('Teacher/Problem/addProgramProblem', array('eid' => $eid, 'type' => 4)), 2); } else { $this->echoError('Invaild Path'); } } } } else { $ansrow = QuestionBaseModel::instance()->getQuestionIds4ExamByType($this->eid, ProblemService::PROGRAM_PROBLEM_TYPE); $answernumC = count($ansrow); $key = set_post_key(); $widgets = array('mykey' => $key, 'ansrow' => $ansrow, 'answernumC' => $answernumC); $this->ZaddWidgets($widgets); $this->auto_display('program'); } }
protected function initExamQuestionCount() { $this->chooseCount = QuestionBaseModel::instance()->getQuestionCntByType($this->examId, ChooseBaseModel::CHOOSE_PROBLEM_TYPE); $this->judgeCount = QuestionBaseModel::instance()->getQuestionCntByType($this->examId, JudgeBaseModel::JUDGE_PROBLEM_TYPE); $this->fillCount = QuestionBaseModel::instance()->getQuestionCntByType($this->examId, FillBaseModel::FILL_PROBLEM_TYPE); $this->programCount = QuestionBaseModel::instance()->getQuestionCntByType($this->examId, ProblemService::PROGRAM_PROBLEM_TYPE); }
public function copyOneExam() { $eid = I('get.eid', 0, 'intval'); $row = ExamBaseModel::instance()->getExamInfoById($eid); if (empty($row)) { $this->echoError("No Such Exam!"); } if (!$this->isOwner4ExamByUserId($row['creator'])) { $this->echoError('You have no privilege!'); } else { // copy exam's base info unset($row['exam_id']); $row['creator'] = $this->userInfo['user_id']; $examId = ExamBaseModel::instance()->insertData($row); if (empty($examId)) { $this->echoError("复制考试失败,请刷新页面重试"); } // copy exam's problem $field = array('exam_id', 'question_id', 'type'); $res = QuestionBaseModel::instance()->getQuestionByExamId($eid, $field); foreach ($res as &$r) { $r['exam_id'] = $examId; } unset($r); QuestionBaseModel::instance()->insertQuestions($res); $this->success('考试复制成功!', U('/Teacher'), 1); } }