Example #1
0
def make_example_page(id):
    #获取全考题列表
    problem_list_exam = ExamService.get_prolbem_list_by_id(id)
    #获取考题配置
    problem_condition_dict = ExamService.get_problem_condition_dict_byid(id)
    choice = []
    blank = []
    short_answer = []
    #生成样例试卷
    for problem in problem_list_exam:
        problem_detail = ProLibService.get_problem_detailed_info(problem)
        if problem_detail.type == Config.PROBLEM_TYPE['choice']:
            choice.append(problem_detail.pid)
        elif problem_detail.type == Config.PROBLEM_TYPE['blank']:
            blank.append(problem_detail.pid)
        elif problem_detail.type == Config.PROBLEM_TYPE['short_answer']:
            short_answer.append(problem_detail.pid)

    choice_r = random.sample(choice,problem_condition_dict['choice']['num'])
    blank_r = random.sample(blank,problem_condition_dict['blank']['num'])
    short_answer_r = random.sample(short_answer,problem_condition_dict['short_answer']['num'])

    List = choice_r + blank_r + short_answer_r

    ExamService.update_problem_list_example(List,id)

    return redirect(url_for('admin.exam_problem',id=id))
Example #2
0
def exam_finish(id,count):
    exam_answer = request.json
    ExamConditionService.save_page(id,current_user.user_id,None,exam_answer,count)
    print exam_answer
    logout_ip = request.remote_addr
    ExamConditionService.update_exam_condition(id,current_user.user_id,logout_ip,count)

    grade = 0
    problem_condition_dict = ExamService.get_problem_condition_dict_byid(id)

    for pid, answer in exam_answer['choice'].items():
        problem = ProLibService.get_problem_detailed_info(pid)
        if answer == problem.answer:
            grade += problem_condition_dict['choice']['score']

    ExamConditionService.update_user_exam_grade(id, current_user.user_id, grade, count)

    return json.dumps({'key':'success'})
Example #3
0
def exam_problem(id):
    form = ExamProblemNumForm()
    examinfo = ExamService.get_exam_detail_info(id)
    problem_list_exam = examinfo.problem_list                                                                           #考试题库题目id列表
    problem_list_example = examinfo.problem_list_example                                                                #考试样例试卷题目id列表
    problem_condition_dict = ExamService.get_problem_condition_dict_byid(id)                                            #考题情况字典
    choice = []
    blank = []
    short_answer = []
    choice_ex = []
    blank_ex = []
    short_answer_ex = []
    # 考试题目列表仅仅有id,通过循环获取
    # 题目相关信息,下一循环同理
    # 区别在于题库和样例试卷的题目不同
    for problem in problem_list_exam:
        problem_detail = ProLibService.get_problem_detailed_info(problem)
        problem_detail.belong_to_book = BookService.get_book_by_id(problem_detail.belong_to_book).book_name
        problem_detail.belong_to_unit = BookService.get_unit_by_id(problem_detail.belong_to_unit).unit_name
        problem_detail.belong_to_section = BookService.get_section_by_id(problem_detail.belong_to_section).section_name
        if problem_detail.type == Config.PROBLEM_TYPE['choice']:
            choice.append(problem_detail)
        elif problem_detail.type == Config.PROBLEM_TYPE['blank']:
            blank.append(problem_detail)
        elif problem_detail.type == Config.PROBLEM_TYPE['short_answer']:
            short_answer.append(problem_detail)

    for problem in problem_list_example:
        problem_detail = ProLibService.get_problem_detailed_info(problem)
        problem_detail.belong_to_book = BookService.get_book_by_id(problem_detail.belong_to_book).book_name
        problem_detail.belong_to_unit = BookService.get_unit_by_id(problem_detail.belong_to_unit).unit_name
        problem_detail.belong_to_section = BookService.get_section_by_id(problem_detail.belong_to_section).section_name
        if problem_detail.type == Config.PROBLEM_TYPE['choice']:
            choice_ex.append(problem_detail)
        elif problem_detail.type == Config.PROBLEM_TYPE['blank']:
            blank_ex.append(problem_detail)
        elif problem_detail.type == Config.PROBLEM_TYPE['short_answer']:
            short_answer_ex.append(problem_detail)

    problem_list_dict = dict((('choice',choice),('blank',blank),('short_answer',short_answer)))
    problem_list_example_dict = dict((('choice', choice_ex), ('blank', blank_ex), ('short_answer', short_answer_ex)))

    if request.method == 'GET':
        form.choice_num.choices = [(i, i) for i in range(len(choice) + 1)]
        form.blank_num.choices = [(i, i) for i in range(len(blank) + 1)]
        form.short_answer_num.choices = [(i, i) for i in range(len(short_answer) + 1)]
        form.choice_num.data = str(problem_condition_dict['choice']['num'])
        form.choice_score.data = str(problem_condition_dict['choice']['score'])
        form.blank_num.data = str(problem_condition_dict['blank']['num'])
        form.blank_score.data = str(problem_condition_dict['blank']['score'])
        form.short_answer_num.data = str(problem_condition_dict['short_answer']['num'])
        form.short_answer_score.data = str(problem_condition_dict['short_answer']['num'])
        form.is_random.data = str(problem_condition_dict['is_random'])
        return render_template('web/exam_manage/exam_problem.html',
                               form = form,
                               id = id,
                               is_random = problem_condition_dict['is_random'],
                               problem_num_dict = problem_condition_dict,
                               problem_list_dict = problem_list_dict,
                               problem_list_example = problem_list_example_dict,
                               status=Config.STATUS,
                               active=Config.ADMIN_PAGE_ACTIVE['exam'])

    if request.method == 'POST':
        ExamService.update_problem_number(form,id)
        return redirect(url_for('web.exam_problem',id=id))