from ._builtin import Page, WaitPage import time, random from .models import Constants # variables for all templates # -------------------------------------------------------------------------------------------------------------------- def vars_for_all_templates(self): return { 'total_letters': Constants.total_letters, 'd_total': Constants.d_total, 'b_total': Constants.d_total, 'num_rounds': Constants.num_rounds, 'treatment': self.player.participant.vars['treatment'], 'completion_url': Constants.completion_url } # ******************************************************************************************************************** # # *** CHOICE OF THE TOOL *** # # ********************************************************************************************************* class Choice(Page): form_model = 'player' form_fields = ['tool'] # only display instruction in round 1 # ---------------------------------------------------------------------------------------------------------------- def is_displayed(self): return self.subsession.round_number == 1 # start measuring time of a trial round # ---------------------------------------------------------------------------------------------------------------- def vars_for_template(self): self.player.get_treatment() print(self.participant.vars['treatment'], self.player.treatment) return{ 'time': time.time() + self.player.my_page_timeout_seconds, 'treatment': self.player.participant.vars['treatment']} # ******************************************************************************************************************** # # *** Affect *** # # ******************************************************************************************************************** # class Affect(Page): form_model = 'player' form_fields = ['affect'] def is_displayed(self): return self.subsession.round_number == 1 def vars_for_template(self): self.player.get_treatment() print(self.participant.vars['treatment'], self.player.treatment) return{ 'treatment': self.player.participant.vars['treatment']} # ******************************************************************************************************************** # # *** Fairness *** # # ******************************************************************************************************************** # class FrQ(Page): form_model = 'player' form_fields = ['fair_1', 'fair_2', 'fair_3'] def vars_for_template(self): self.player.get_treatment() print(self.participant.vars['treatment'], self.player.treatment) return{ 'treatment': self.player.participant.vars['treatment']} def is_displayed(self): return self.subsession.round_number == 1 # ******************************************************************************************************************** # # *** Quality *** # # ******************************************************************************************************************** # class Quality(Page): form_model = 'player' form_fields = ['quality_1', 'quality_2'] def vars_for_template(self): self.player.get_treatment() print(self.participant.vars['treatment'], self.player.treatment) return{ 'treatment': self.player.participant.vars['treatment']} def is_displayed(self): return self.subsession.round_number == 1 # ******************************************************************************************************************** # # *** Start Task *** # # ******************************************************************************************************************** # class Start_task(Page): form_model = 'player' def is_displayed(self): return self.subsession.round_number == 1 def before_next_page(self): self.participant.vars['tool'] = self.player.tool self.participant.vars['expiry_timestamp'] = time.time() + self.player.task_timer # ******************************************************************************************************************** # # *** TASK PAGE WITH TOOL *** # # ******************************************************************************************************************** # class TaskPaidPremiumTool(Page): # set Display Time and Conditional on the tool chosen # ---------------------------------------------------------------------------------------------------------------- def get_timeout_seconds(self): return self.participant.vars['expiry_timestamp'] - time.time() def is_displayed(self): return self.participant.vars['expiry_timestamp'] - time.time() > 0 and self.participant.vars['tool'] == 1 # form model # ---------------------------------------------------------------------------------------------------------------- form_model = 'player' # time text # ---------------------------------------------------------------------------------------------------------------- timer_text = 'Time left to complete as many matrices as possible:' # form fields # ---------------------------------------------------------------------------------------------------------------- def get_form_fields(self): # unzip list of form_fields from list random.shuffle(self.participant.vars['letters_choices']) form_fields = [list(t) for t in zip(*self.participant.vars['letters_choices'])][1] return form_fields def vars_for_template(self): return { 'choices1': self.player.participant.vars['letters_choices'][:][0:9], 'choices2': self.player.participant.vars['letters_choices'][:][10:19], 'choices3': self.player.participant.vars['letters_choices'][:][20:29], 'choices4': self.player.participant.vars['letters_choices'][:][30:39], 'choices5': self.player.participant.vars['letters_choices'][:][40:49], 'choices6': self.player.participant.vars['letters_choices'][:][50:59], 'choices7': self.player.participant.vars['letters_choices'][:][60:69], 'choices8': self.player.participant.vars['letters_choices'][:][70:79], 'round_number': self.subsession.round_number } # get the choice made in a given round # ---------------------------------------------------------------------------------------------------------------- def before_next_page(self): # unzip indices and form fields from list round_number = self.subsession.round_number form_fields = [list(t) for t in zip(*self.participant.vars['letters_choices'])][1] indices = [list(t) for t in zip(*self.participant.vars['letters_choices'])][0] for j, choice in zip(indices, form_fields): choice_i = getattr(self.player, choice) self.participant.vars['letters_choices_made'][j - 1] = choice_i if self.participant.vars['letters_choices_made'] is not None: self.player.count_effort() self.player.check_correctness() if self.player.round_number == 1: self.player.total_correct = self.player.correct elif self.player.round_number > 1: self.player.total_correct = self.player.in_round( self.round_number - 1).total_correct + self.player.in_round(self.round_number).correct # ******************************************************************************************************************** # # *** TASK PAGE WITHOUT THE TOOL *** # # ********************************************************************************************************* class TaskPaidNoTool(Page): # set Display Time and Conditional on the tool chosen # ---------------------------------------------------------------------------------------------------------------- def get_timeout_seconds(self): return self.participant.vars['expiry_timestamp'] - time.time() def is_displayed(self): return self.participant.vars['expiry_timestamp'] - time.time() > 0 and self.participant.vars['tool'] == 0 # form model # ---------------------------------------------------------------------------------------------------------------- form_model = 'player' # time text # ---------------------------------------------------------------------------------------------------------------- timer_text = 'Time left to complete as many matrices as possible:' # form fields # ---------------------------------------------------------------------------------------------------------------- def get_form_fields(self): # unzip list of form_fields from list random.shuffle(self.participant.vars['letters_choices']) form_fields = [list(t) for t in zip(*self.participant.vars['letters_choices'])][1] return form_fields def vars_for_template(self): return { 'choices1': self.player.participant.vars['letters_choices'][:][0:9], 'choices2': self.player.participant.vars['letters_choices'][:][10:19], 'choices3': self.player.participant.vars['letters_choices'][:][20:29], 'choices4': self.player.participant.vars['letters_choices'][:][30:39], 'choices5': self.player.participant.vars['letters_choices'][:][40:49], 'choices6': self.player.participant.vars['letters_choices'][:][50:59], 'choices7': self.player.participant.vars['letters_choices'][:][60:69], 'choices8': self.player.participant.vars['letters_choices'][:][70:79], 'round_number': self.subsession.round_number } # get the choice made in a given round # ---------------------------------------------------------------------------------------------------------------- def before_next_page(self): # unzip indices and form fields from list round_number = self.subsession.round_number form_fields = [list(t) for t in zip(*self.participant.vars['letters_choices'])][1] indices = [list(t) for t in zip(*self.participant.vars['letters_choices'])][0] for j, choice in zip(indices, form_fields): choice_i = getattr(self.player, choice) self.participant.vars['letters_choices_made'][j - 1] = choice_i if self.participant.vars['letters_choices_made'] is not None: self.player.count_effort() self.player.check_correctness() if self.player.round_number == 1: self.player.total_correct = self.player.correct elif self.player.round_number > 1: self.player.total_correct = self.player.in_round( self.round_number - 1).total_correct + self.player.in_round(self.round_number).correct # ******************************************************************************************************************** # # *** RESULTS *** # # ********************************************************************************************************* class ResultsPaid(Page): def is_displayed(self): return self.participant.vars['expiry_timestamp'] - time.time() < 0 \ and self.participant.vars['endgame_second'] != 1 def before_next_page(self): self.participant.vars['total_correct'] = self.player.total_correct self.player.get_treatment() self.player.calculate_payoff() self.participant.vars['payoff'] = self.player.payoff self.participant.vars['reward_task'] = self.participant.vars['total_correct'] * Constants.matrix_rate self.player.participant_vars_dump = str(self.participant.vars) print(self.player.participant_vars_dump) def vars_for_template(self): table_rows = [] for prev_player in self.player.in_all_rounds(): row = { 'round_number': prev_player.round_number, 'd_crossed': round(prev_player.d_crossed), 'b_crossed': round(prev_player.b_crossed), 'is_correct': round(prev_player.is_correct), } table_rows.append(row) self.participant.vars['t1_results'] = table_rows return { 'table_rows': table_rows, } # ******************************************************************************************************************** # # *** Suspisciousness *** # # ********************************************************************************************************* class Suspicious(Page): form_model = 'player' form_fields = ['suspicious_1', 'suspicious_2', 'suspicious_3', 'suspicious_4', 'suspicious_5', 'suspicious_6', 'suspicious_7', 'suspicious_8', 'suspicious_9', ] def is_displayed(self): return self.participant.vars['expiry_timestamp'] - time.time() < 0 \ and self.participant.vars['endgame_second'] != 1 # ******************************************************************************************************************** # # *** SELF-EFFICACY, CONCENTRATION, MOTIVATION *** # # ********************************************************************************************************* class AdditionalQuestions(Page): form_model = 'player' form_fields = [ 'mot_alert1', 'mot_alert2', 'mot_alert3'] def is_displayed(self): return self.participant.vars['expiry_timestamp'] - time.time() < 0 \ and self.participant.vars['endgame_second'] != 1 # ******************************************************************************************************************** # # *** RECIPROCITY AVERSION *** # # ********************************************************************************************************* class RecAver(Page): form_model = 'player' form_fields = ['reciprocity_1', 'reciprocity_2', 'reciprocity_3', 'reciprocity_4', 'reciprocity_5', 'reciprocity_6', 'reciprocity_7', 'reciprocity_8', 'reciprocity_9', 'reciprocity_10', 'reciprocity_11', ] def is_displayed(self): return self.participant.vars['expiry_timestamp'] - time.time() < 0 \ and self.participant.vars['endgame_second'] != 1 # ******************************************************************************************************************** # # *** REASONS *** # # ********************************************************************************************************* class Reasons(Page): form_model = 'player' form_fields = ['reasons'] def is_displayed(self): return self.participant.vars['expiry_timestamp'] - time.time() < 0 \ and self.participant.vars['endgame_second'] != 1 def vars_for_template(self): self.player.get_treatment() print(self.participant.vars['treatment'], self.player.treatment) return{ 'treatment': self.player.participant.vars['treatment']} # ******************************************************************************************************************** # # *** COMMENTS *** # # ********************************************************************************************************* class Comments(Page): form_model = 'player' form_fields = ['comments'] def is_displayed(self): return self.participant.vars['expiry_timestamp'] - time.time() < 0 \ and self.participant.vars['endgame_second'] != 1 # ******************************************************************************************************************** # # *** LAST SCREEN *** # # ********************************************************************************************************* class FinalScreen(Page): def is_displayed(self): return self.participant.vars['expiry_timestamp'] - time.time() < 0 \ and self.participant.vars['endgame_second'] != 1 def vars_for_template(self): self.player.get_treatment() print(self.participant.vars['treatment'],) return { 'fixed_payoff': Constants.fixed_payoff, 'completion_url': Constants.completion_url, 'final_payoff': self.participant.vars['payoff'], 'final_total_correct': self.participant.vars['total_correct'], 'final_reward_task': self.participant.vars['reward_task'], } page_sequence = [Choice, Affect, FrQ, Quality, Start_task, TaskPaidPremiumTool, TaskPaidNoTool, ResultsPaid, Suspicious, RecAver, AdditionalQuestions, Reasons, Comments, FinalScreen, ]