def on_post(self): tid = self.get_argument("tid", None) t = Test.objects(id=tid).get() if len(t.answers) == 0 or isinstance( t, MockTest ): #if the user didn't start doing the test and left the page then delete the test. t.delete() return
def on_get(self): try: tid = self.get_argument("tid", None) t = Test.objects(id=tid).get() t.cursor -= 1 t.save() return (t,) except Exception,e: print e
def on_get(self): try: tid = self.get_argument("tid", None) t = Test.objects(id=tid).get() t.cursor -= 1 t.save() return (t, ) except Exception, e: print e
def on_get(self): try: tid = self.get_argument("tid", None) #Fetch the test object t = Test.objects(id=tid).get() t.update_cursor(1) return (t,) except Exception, e: self.log.warning("Error while fetching new question after wrong answer dialog: " + str(e))
def on_get(self): try: tid = self.get_argument("tid", None) #Fetch the test object t = Test.objects(id=tid).get() t.update_cursor(1) return (t, ) except Exception, e: self.log.warning( "Error while fetching new question after wrong answer dialog: " + str(e))
def on_get(self): try: #Delete the old test tid = self.get_argument("tid", None) t = Test.objects(id=tid).get() test_type = type(t) t.delete() #Create new mock test object t = test_type() t.user = str(self.current_user.id) questions = [question for question in Question.objects] shuffle(questions) t.questions = questions[:PRACTISE_TEST_SIZE] t.score = 0 t.cursor = 0 t.save() return (t,) except Exception, e: self.log.warning("Error while restarting a test: " + str(e))
def on_get(self): try: #Delete the old test tid = self.get_argument("tid", None) t = Test.objects(id=tid).get() test_type = type(t) t.delete() #Create new mock test object t = test_type() t.user = str(self.current_user.id) questions = [question for question in Question.objects] shuffle(questions) t.questions = questions[:PRACTISE_TEST_SIZE] t.score = 0 t.cursor = 0 t.save() return (t, ) except Exception, e: self.log.warning("Error while restarting a test: " + str(e))
def get_user_stats(self): ''' calculates user stats and returns a dict. ''' try: stats = {} test_history = Test.objects(user=str(self.id)) if len(test_history) != 0: no_of_correct_answers = 0 for test in test_history: no_of_correct_answers += test.score stats['correct_answers'] = no_of_correct_answers #count total questions total_questions_answered = 0 for test in test_history: if isinstance(test, MockTest): total_questions_answered += 50 elif isinstance(test, PractiseTest): total_questions_answered += 20 stats['accuracy'] = 0 if total_questions_answered != 0: stats['accuracy'] = 100 * no_of_correct_answers / float( total_questions_answered) stats['total_questions_answered'] = total_questions_answered else: stats['correct_answers'] = 0 stats['accuracy'] = 0 stats['total_questions_answered'] = 0 stats[ 'points'] = self.points #The user may receive points without completing a test. We're good people return stats except Exception, e: print e
def on_get(self): try: tid = self.get_argument("tid", None) answers = self.get_argument("answers", None) if answers: answers = tornado.escape.json_decode(answers) cursor = self.get_argument("cursor", None) timer_is_over = self.get_argument("timer_over", None) #Fetch the test object t = Test.objects(id=tid).get() #Save user answers t.save_answers(answers) #if this request is made because the timer is over evaluate the test and #end it if timer_is_over: t.cursor = 50 t.save() return (t, True) #This will only be executed for practice tests if isinstance(t, PractiseTest): result = t.evaluate_question(int(cursor)) if result == 1: correct = True t.update_cursor(1) elif result == 0: correct = False; else: #if this is a mock test jsut increase cursor and #assume it's correct t.update_cursor(1) correct = True return (t, correct) except Exception, e: self.log.warning("Error while fetching new question: " + str(e))
def on_get(self): try: tid = self.get_argument("tid", None) answers = self.get_argument("answers", None) if answers: answers = tornado.escape.json_decode(answers) cursor = self.get_argument("cursor", None) timer_is_over = self.get_argument("timer_over", None) #Fetch the test object t = Test.objects(id=tid).get() #Save user answers t.save_answers(answers) #if this request is made because the timer is over evaluate the test and #end it if timer_is_over: t.cursor = 50 t.save() return (t, True) #This will only be executed for practice tests if isinstance(t, PractiseTest): result = t.evaluate_question(int(cursor)) if result == 1: correct = True t.update_cursor(1) elif result == 0: correct = False else: #if this is a mock test jsut increase cursor and #assume it's correct t.update_cursor(1) correct = True return (t, correct) except Exception, e: self.log.warning("Error while fetching new question: " + str(e))
def get_user_stats(self): ''' calculates user stats and returns a dict. ''' try: stats = {} test_history = Test.objects(user=str(self.id)) if len(test_history) != 0: no_of_correct_answers = 0 for test in test_history: no_of_correct_answers += test.score stats['correct_answers'] = no_of_correct_answers #count total questions total_questions_answered = 0 for test in test_history: if isinstance(test, MockTest): total_questions_answered += 50 elif isinstance(test, PractiseTest): total_questions_answered += 20 stats['accuracy'] = 0 if total_questions_answered != 0: stats['accuracy'] = 100*no_of_correct_answers / float(total_questions_answered) stats['total_questions_answered'] = total_questions_answered else: stats['correct_answers'] = 0 stats['accuracy'] = 0 stats['total_questions_answered'] = 0 stats['points'] = self.points #The user may receive points without completing a test. We're good people return stats except Exception,e: print e
def get_correct_answers(self): test_history = Test.objects(user=str(self.id)) no_of_correct_answers = 0 for test in test_history: no_of_correct_answers += test.score return no_of_correct_answers
def on_post(self): tid = self.get_argument("tid", None) t = Test.objects(id=tid).get() if len(t.answers) == 0 or isinstance(t, MockTest): #if the user didn't start doing the test and left the page then delete the test. t.delete() return