from ._builtin import Page, WaitPage from .models import Constants import random class TetrisPay(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 = ['task_answers','timePlayed','games_played','f_open','timeSpent'] timer_text = 'Time remaining:' timeout_submission = {'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='Task/ImagQuestions1/{}.PNG'.format(self.group.question_id), tetris_instructions='Tetris_Instructions/Tetris_Instructions.png', tetris_keys='Tetris_Instructions/Tetris_Keys.png', round_number = self.round_number ) if self.player.role() == 'Player 2': return dict( image_path_1='Task/ImagQuestions2/{}.PNG'.format(self.group.question_id), tetris_instructions='Tetris_Instructions/Tetris_Instructions.png', tetris_keys='Tetris_Instructions/Tetris_Keys.png', round_number = self.round_number ) if self.player.role() == 'Player 3': return dict( image_path_1='Task/ImagQuestions3/{}.PNG'.format(self.group.question_id), tetris_instructions='Tetris_Instructions/Tetris_Instructions.png', tetris_keys='Tetris_Instructions/Tetris_Keys.png', round_number = self.round_number ) def before_next_page(self): import time self.player.check_correct() class Waiting_Room(WaitPage): template_name = '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.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.team_check_correct() #class Results(Page): #def is_displayed(self): #return self.round_number == Constants.num_rounds #def before_next_page(self): #self.player.participant.vars['player_payoff'] = self.player.player_payoff #def vars_for_template(self): #team_in_all_rounds = self.group.in_all_rounds() #filterT = [g.team_is_correct for g in team_in_all_rounds if g.team_is_correct !=-1] #self.group.team_total_correct = sum(filterT) #self.group.team_total_incorrect = len(filterT) - sum(filterT) #all_in_group = self.subsession.get_groups() #filterG = [g.team_total_correct for g in all_in_group if g.team_total_correct !=-1] #self.subsession.group_total_correct = sum(filterG) #self.subsession.shared_income = round((self.subsession.group_total_correct*0.20),2) #player_in_all_rounds = self.player.in_all_rounds() #filter_time = [p.timePlayed for p in player_in_all_rounds if p.timePlayed !=0] #self.player.total_time_played = round(sum(filter_time),2) #self.player.total_game_income = round((self.player.total_time_played*(0.18/60)),2) #sum_payoff = (self.subsession.shared_income + self.player.total_game_income) - (self.group.team_total_incorrect*0.01) #self.player.player_payoff = round(sum_payoff,2) #self.player.other_teams_correct = sum(filterG) - self.group.team_total_correct #return { #'team_questions_answered': len(filterT), #'team_penalty': self.group.team_total_incorrect*0.01, #} page_sequence = [TetrisPay, Pre_Task, Task, Waiting_Room]