from ._builtin import Page, WaitPage from .models import Constants import random class Intro(Page): def is_displayed(self): return self.round_number == 1 def before_next_page(self): question_id = self.group.question_id self.player.participant.vars['question_id'] = question_id class Pre_Task(WaitPage): wait_for_all_groups = True after_all_players_arrive = 'set_timer' def is_displayed(self): return self.round_number == 1 class Task(Page): form_model = 'player' form_fields = ['s1_task_answers','s1_timeSpent'] timer_text = 'Time remaining:' timeout_submission = {'s1_task_answers': -1} def get_timeout_seconds(self): import time return self.participant.vars['expiry'] - time.time() def is_displayed(self): return self.get_timeout_seconds() > 3 def js_vars(self): import time return dict( time_left=self.participant.vars['expiry'] - time.time(), ) def vars_for_template(self): if self.player.role() == 'Player 1': return dict( image_path_1='s1_Task/ImagQuestions1/{}.PNG'.format(self.group.question_id), round_number = self.round_number ) if self.player.role() == 'Player 2': return dict( image_path_1='s1_Task/ImagQuestions2/{}.PNG'.format(self.group.question_id), round_number = self.round_number ) if self.player.role() == 'Player 3': return dict( image_path_1='s1_Task/ImagQuestions3/{}.PNG'.format(self.group.question_id), round_number = self.round_number ) def before_next_page(self): import time self.player.s1_check_correct() class Waiting_Room(WaitPage): template_name = 's1_real_effort/MyWaitPage.html' timer_text = 'Time remaining:' def get_timeout_seconds(self): import time return self.participant.vars['expiry'] - time.time() def is_displayed(self): return self.get_timeout_seconds() > 3 def after_all_players_arrive(self): self.group.s1_team_check_correct() class Pre_Results_Wait(WaitPage): wait_for_all_groups = True def is_displayed(self): return self.round_number == Constants.num_rounds def after_all_players_arrive(self): for group in self.subsession.get_groups(): group.s1_team_check_correct() class Results(Page): def is_displayed(self): return self.round_number == Constants.num_rounds def before_next_page(self): s1_player_payoff = self.player.s1_player_payoff self.player.participant.vars['s1_player_payoff'] = s1_player_payoff def vars_for_template(self): team_in_all_rounds = self.group.in_all_rounds() filterT = [g.s1_team_is_correct for g in team_in_all_rounds if g.s1_team_is_correct !=-1] self.group.s1_team_total_correct = sum(filterT) s1_player_payoff = self.group.s1_team_total_correct*0.60 self.player.s1_player_payoff = s1_player_payoff return { 'team_questions_answered': len(filterT), 's1_player_payoff': s1_player_payoff } # Pass on the variable question_correct (or score) to next app sequence, this is needed to calculate final payments page_sequence = [Intro, Pre_Task, Task, Waiting_Room, Pre_Results_Wait, Results]