Beispiel #1
0
 def get_question_scores(self, result, total_results, max_allowed_wrong, max_allowed_duration):
 
     percentage = TestManager.score_percentage(result.correctly_answered,
                                                  result.wrong_attempts,
                                                  max_allowed_wrong,
                                                  total_results,
                                                  result.duration,
                                                  max_allowed_duration
                                                  )
     competitive = TestManager.score_competitive(result.correctly_answered,
                                                  result.wrong_attempts,
                                                  max_allowed_wrong,
                                                  total_results,
                                                  result.duration,
                                                  max_allowed_duration
                                                  )
                                                  
     answer_help = None
     try:
         try:
             # if questionset was removed, this will still allow people to view old tests.
             answer_help = QuestionSets.by(result.question_sets_id).first().answer_help
         except exc.SQLAlchemyError as e:
             pass # defensive
     except Exception as e:
         pass # defensive
             
     return { 'question' : str(result.question),
              'question_textonly' : RemoveImages(result.question),
              'correctly_answered' : result.correctly_answered,
              'wrong_attempts' : result.wrong_attempts,
              'duration' : result.duration,
              'duration_passed_fmt' : Seconds2Str((max_allowed_duration-result.duration)),
              'duration_remaining_fmt' : Seconds2Str(result.duration),
              'percentage' : percentage,
              'competitive' : competitive,             
              'answer_help': str(answer_help),           
              'attempted': result.attempted,    
              'answer_choices': str(result.get_answers()),
              'had_wrong_attempts': (result.wrong_attempts!=0 and result.attempted),
              'had_more_than_one_wrong': (result.wrong_attempts>1),
              'had_no_time_remaining': (result.duration<1 and result.attempted),
             }
Beispiel #2
0
 def _test_calculator(self,test,results,result):
     percentage = TestManager.score_percentage(result.correctly_answered,
                                                 result.wrong_attempts,
                                                 test.max_wrong_answer_allowed,
                                                 len(results),
                                                 result.duration,
                                                 test.question_time_allowed
                                                 )
     competitive = TestManager.score_competitive(result.correctly_answered,
                                                 result.wrong_attempts,
                                                 test.max_wrong_answer_allowed,
                                                 len(results),
                                                 result.duration,
                                                 test.question_time_allowed
                                                 )
     
     test.total_percentage += percentage
     test.base_competitive += competitive['score']
     test.bonus_competitive += competitive['bonus']
     test.total_competitive += competitive['combined']
     test.time_remaining += result.duration
     test.time_spent += (test.question_time_allowed - result.duration)
     DBSession.flush()
     return { 'competitive': competitive, 'percentage': percentage }