Esempio n. 1
0
    def get_repeat(employee):
        """
    Получение вопроса среди уже отвеченных,
    в случае когда на все вопросы уже ответили,
    но по плану нужно еще задать. Т.е. вопросы задаются повторно.
    """
        result = Session.query(Result.question_n).filter(
            Result.employee_n == employee.n,
            Result.question_n == Question.n).group_by(
                Result.question_n).order_by(func.count()).first()

        question = Question.get(result.question_n)
        return question
Esempio n. 2
0
 def exam(question_n, answer_n, employee_name, time_begin, time_end):
   """
   Проверка ответа на вопрос и сохранение результата тестирования
   """
   result = Result()
   employee = EmployeeCtrl.find_by_name(employee_name)
   result.employee_n = employee.n
   result.question_n = question_n
   result.answer_n = answer_n
   result.time_begin=time_begin
   result.time_end=time_end
   question = Question.get(question_n)
   result.is_correct = (question.answer_n == int(answer_n))
   Session.add(result)
   Session.flush()
   return result
Esempio n. 3
0
 def update_question(feature, questions_params):
     # print(questions_params)
     for question_param in questions_params:
         n = question_param['n']
         if n <= 0:
             FeatureCtrl.create_question(feature, question_param)
         else:
             q = Session.query(Question).filter(Question.n == n)
             if 'txt' in question_param:
                 q.update({'txt': question_param['txt']})
             if 'answer_n' in question_param:
                 q.update({'answer_n': question_param['answer_n']})
             question = Question.get(n)
             if 'answers' in question_param:
                 FeatureCtrl.update_answer(question,
                                           question_param['answers'])
         return feature
Esempio n. 4
0
    def post(self):
        if self.context.action == 'exam':
            params = self.request.json_body
            print('-------------------------')
            print(params['time_begin'])
            time_begin = datetime.strptime(params['time_begin'],
                                           '%Y-%m-%d %H:%M:%S')
            time_end = datetime.strptime(params['time_end'],
                                         '%Y-%m-%d %H:%M:%S')
            res = ResultCtrl.exam(params['question_n'], params['answer_n'],
                                  params['employee_name'], time_begin,
                                  time_end)
            # print(res.is_correct)
            question = Question.get(params['question_n'])
            feature = question.feature

            return ResultWithFeatureJSON().dump({
                'feature': feature,
                'is_correct': res.is_correct
            }).data