from ._builtin import Page, WaitPage from .models import Constants import random class Task4(Page): def is_displayed(self): return self.round_number == 1 def before_next_page(self): import time # user has 10 minutes to complete as many pages as possible self.participant.vars['expiry'] = time.time() + 1 * 6 class Task5(Page): form_model = 'player' form_fields = ['task_answers'] timer_text = 'Time left to complete this task round:' def get_timeout_seconds(self): import time return self.participant.vars['expiry'] - time.time() def is_displayed(self): return self.get_timeout_seconds() > 2 def vars_for_template(self): return dict( image_path_1='Part4/ImagQuestions/{}.jpg'.format(self.round_number), image_path_2='Part4/ImagAnswers/{}.jpg'.format(self.round_number), round_number = self.round_number ) def before_next_page(self): import time self.player.check_correct() class Results(Page): def is_displayed(self): return self.round_number == Constants.num_rounds def vars_for_template(self): player_in_all_rounds = self.player.in_all_rounds() # Need to filter out the none types where the player didn't get a chance to answer the questions filtered1 = [p.is_correct for p in player_in_all_rounds] filtered2 = [p.task_answers for p in player_in_all_rounds if p.task_answers != ""] self.participant.payoff=2*sum(filtered1) self.player.attempts_R2 = len(filtered2) self.player.success_R2 = sum(filtered1) #Add participant variable for noisyfeedback self.participant.correctanswer_R2 = sum(filtered1) self.participant.questionsattempted_R2 = len(filtered2) return { 'player_in_all_rounds': player_in_all_rounds, 'question_answered': len(filtered2), 'questions_correct': sum(filtered1) } # Pass on the variable qustion_correct (or score) to next app sequence, this is needed to calculate final payments page_sequence = [Task4, Task5, Results]