from ._builtin import Page, WaitPage from .models import Constants import random class StartWaitPage(WaitPage): def is_displayed(self): return self.subsession.round_number == 1 group_by_arrival_time = True title_text = "Waiting for other participants." body_text = "Pay attention to this screen: The timer for the next page could start any second." class MatchingFailWaitPage(WaitPage): def is_displayed(self): return self.subsession.round_number == 1 and self.participant.vars['time'] == 1 def after_all_players_arrive(self): for p in self.group.get_players(): p.failed_matching = 1 class MatchingFail(Page): def is_displayed(self): return self.subsession.round_number == 1 and self.participant.vars['time'] == 1 class TreatmentWaitPage(WaitPage): title_text = "Please Wait" body_text = "Waiting for the other participants." wait_for_all_groups = False def after_all_players_arrive(self): for p in self.group.get_players(): if p.id_in_group == 1: rand = random.randint(0, 6) p.group.treatment = rand class Intro(Page): def is_displayed(self): return self.subsession.round_number == 1 def vars_for_template(self): return { 'rate': Constants.rate, } def before_next_page(self): if self.player.id_in_group == 1: self.group.treatment = self.subsession.session.config['treatment'] class Instruction_Accounts(Page): def is_displayed(self): return self.subsession.round_number == 1 class Instruction_contribution(Page): def is_displayed(self): return self.subsession.round_number == 1 class Instruction_information(Page): def is_displayed(self): return self.subsession.round_number == 1 def vars_for_template(self): return { 'treatment': self.group.treatment, } class Instruction_enforcement(Page): def is_displayed(self): return self.subsession.round_number == 1 def vars_for_template(self): return { 'treatment': self.group.treatment, } class Instruction_feedback(Page): def is_displayed(self): return self.subsession.round_number == 1 def vars_for_template(self): return { 'treatment': self.group.treatment, } class Instruction_procedure(Page): def is_displayed(self): return self.subsession.round_number == 1 class Instruction_summary(Page): def is_displayed(self): return self.subsession.round_number == 1 def vars_for_template(self): return { 'treatment': self.group.treatment, } class Contribution(Page): # def is_displayed(self): # return self.participant.vars['time'] == 0 and self.session.config['treatment'] == 0 #timeout_seconds = 40 #timer_text = 'Time remaining on this page:' form_model = 'player' form_fields = ['contribution'] # def get_timeout_seconds(self): # if self.round_number == 1: # timer = 90 # else: # timer = 60 # # if self.participant.vars.get('is_dropout'): # return 1 # instant timeout, 0 second # else: # return timer def vars_for_template(self): return { 'endowment': Constants.endowment, 'current_round': self.round_number, 'nb_round': Constants.num_rounds, 'treatment': self.group.in_round(1).treatment } def before_next_page(self): # if self.player.id_in_group == 1: # self.group.treatment = self.subsession.session.config['treatment'] # if self.group.treatment == 0: # self.player.see_info = 1 self.group.treatment = self.group.in_round(1).treatment if self.group.treatment == 4 or self.group.treatment == 5 or self.group.treatment == 6: self.player.pay_fee = 1 self.player.see_info = 1 if self.player.contribution >= Constants.threshold: self.player.compliant = 1 else: self.player.compliant = 0 # pre_round = self.round_number - 1 # # if self.timeout_happened: # self.player.failed_take = 1 # self.player.is_dropout = True # self.player.participant.vars['is_dropout'] = True # if self.round_number == 1: # self.player.take = 20 # if self.round_number > 1: # self.player.take = self.player.in_round(pre_round).take class AuditWaitPage(WaitPage): def after_all_players_arrive(self): for p in self.group.get_players(): rand = random.randint(1, 3) if rand < 3: audit = 1 else: audit = 0 p.audit = audit if p.id_in_group == 1: p.group.die_p1 = rand p.group.audit_p1 = audit elif p.id_in_group == 2: p.group.die_p2 = rand p.group.audit_p2 = audit elif p.id_in_group == 3: p.group.die_p3 = rand p.group.audit_p3 = audit else : p.group.die_p4 = rand p.group.audit_p4 = audit class PGWaitPage(WaitPage): # def is_displayed(self): # return self.participant.vars['time'] == 0 # title_text = "Waiting for the other group members." # body_text = "Pay attention to this screen: The timer for the next page could start any second. If you decide to withdraw from the study now, you will NOT receive your bonus payment." def after_all_players_arrive(self): for p in self.group.get_players(): players = p.group.get_players() if p.id_in_group == 1: p.group.contribution_p1 = p.contribution p.group.compliant_p1 = p.compliant contributions = [p.contribution for p in players] p.group.sum_contribution = sum(contributions) elif p.id_in_group == 2: p.group.contribution_p2 = p.contribution p.group.compliant_p2 = p.compliant elif p.id_in_group == 3: p.group.contribution_p3 = p.contribution p.group.compliant_p3 = p.compliant else: p.group.contribution_p4 = p.contribution p.group.compliant_p4 = p.compliant class TPMonitoring(Page): def is_displayed(self): return self.group.treatment == 4 or self.group.treatment == 5 or self.group.treatment == 6 def vars_for_template(self): return { 'current_round': self.round_number, 'nb_round': Constants.num_rounds, } class PMonitoring(Page): def is_displayed(self): return self.group.treatment == 1 or self.group.treatment == 2 or self.group.treatment == 3 form_model = 'player' form_fields = ['pay_fee'] def vars_for_template(self): return { 'current_round': self.round_number, 'nb_round': Constants.num_rounds, } def before_next_page(self): if self.player.pay_fee == 1: self.player.see_info = 1 class SM_Info(Page): def is_displayed(self): return self.group.treatment == 0 # return self.participant.vars['time'] == 0 and self.session.config['treatment'] == 0 #timeout_seconds = 60 # timer_text = 'Time remaining on this page:' # # def get_timeout_seconds(self): # if self.participant.vars.get('is_dropout'): # return 1 # instant timeout, 0 second # else: # return 60 def vars_for_template(self): return { 'id': self.player.id_in_group, 'contribution': self.player.contribution, 'sum_contribution': self.group.sum_contribution, 'compliant': self.player.compliant, 'current_round': self.round_number, 'nb_round': Constants.num_rounds, } class PM_Info(Page): def is_displayed(self): return self.group.treatment == 1 or self.group.treatment == 2 or self.group.treatment == 3 # return self.participant.vars['time'] == 0 and self.session.config['treatment'] == 0 #timeout_seconds = 60 # timer_text = 'Time remaining on this page:' # # def get_timeout_seconds(self): # if self.participant.vars.get('is_dropout'): # return 1 # instant timeout, 0 second # else: # return 60 def vars_for_template(self): return { 'id': self.player.id_in_group, 'sum_contribution': self.group.sum_contribution, 'contribution': self.player.contribution, 'compliant': self.player.compliant, 'compliant_p1': self.group.compliant_p1, 'compliant_p2': self.group.compliant_p2, 'compliant_p3': self.group.compliant_p3, 'compliant_p4': self.group.compliant_p4, 'contribution_p1': self.group.contribution_p1, 'contribution_p2': self.group.contribution_p2, 'contribution_p3': self.group.contribution_p3, 'contribution_p4': self.group.contribution_p4, 'audit_p1': self.group.audit_p1, 'audit_p2': self.group.audit_p2, 'audit_p3': self.group.audit_p3, 'audit_p4': self.group.audit_p4, 'die_p1': self.group.die_p1, 'die_p2': self.group.die_p2, 'die_p3': self.group.die_p3, 'die_p4': self.group.die_p4, 'current_round': self.round_number, 'nb_round': Constants.num_rounds, 'pay_fee': self.player.see_info, } class TPM_Info(Page): def is_displayed(self): return self.group.treatment == 4 or self.group.treatment == 5 or self.group.treatment == 6 # return self.participant.vars['time'] == 0 and self.session.config['treatment'] == 0 #timeout_seconds = 60 # timer_text = 'Time remaining on this page:' # # def get_timeout_seconds(self): # if self.participant.vars.get('is_dropout'): # return 1 # instant timeout, 0 second # else: # return 60 def vars_for_template(self): return { 'id': self.player.id_in_group, 'sum_contribution': self.group.sum_contribution, 'contribution': self.player.contribution, 'compliant': self.player.compliant, 'compliant_p1': self.group.compliant_p1, 'compliant_p2': self.group.compliant_p2, 'compliant_p3': self.group.compliant_p3, 'compliant_p4': self.group.compliant_p4, 'contribution_p1': self.group.contribution_p1, 'contribution_p2': self.group.contribution_p2, 'contribution_p3': self.group.contribution_p3, 'contribution_p4': self.group.contribution_p4, 'audit_p1': self.group.audit_p1, 'audit_p2': self.group.audit_p2, 'audit_p3': self.group.audit_p3, 'audit_p4': self.group.audit_p4, 'die_p1': self.group.die_p1, 'die_p2': self.group.die_p2, 'die_p3': self.group.die_p3, 'die_p4': self.group.die_p4, 'current_round': self.round_number, 'nb_round': Constants.num_rounds, 'pay_fee': self.player.see_info, } class SEnforcement(Page): def is_displayed(self): return self.group.treatment == 0 or self.group.treatment == 1 or self.group.treatment == 4 form_model = 'player' form_fields = ['forfeit'] def vars_for_template(self): return { 'sum_contribution': self.group.sum_contribution, 'current_round': self.round_number, 'nb_round': Constants.num_rounds, 'pay_fee': self.player.see_info, 'id': self.player.id_in_group, 'contribution': self.player.contribution, 'contribution_p1': self.group.contribution_p1, 'contribution_p2': self.group.contribution_p2, 'contribution_p3': self.group.contribution_p3, 'contribution_p4': self.group.contribution_p4, 'audit': self.player.audit, 'audit_p1': self.group.audit_p1, 'audit_p2': self.group.audit_p2, 'audit_p3': self.group.audit_p3, 'audit_p4': self.group.audit_p4, 'compliant': self.player.compliant, 'compliant_p1': self.group.compliant_p1, 'compliant_p2': self.group.compliant_p2, 'compliant_p3': self.group.compliant_p3, 'compliant_p4': self.group.compliant_p4, 'die_p1': self.group.die_p1, 'die_p2': self.group.die_p2, 'die_p3': self.group.die_p3, 'die_p4': self.group.die_p4, 'treatment': self.group.treatment, } def before_next_page(self): self.player.punish = self.player.forfeit class PEnforcement(Page): def is_displayed(self): return self.group.treatment == 2 or self.group.treatment == 5 form_model = 'player' form_fields = ['forfeit_p1', 'forfeit_p2', 'forfeit_p3', 'forfeit_p4'] def vars_for_template(self): return { 'id': self.player.id_in_group, 'treatment': self.group.treatment, 'current_round': self.round_number, 'nb_round': Constants.num_rounds, 'sum_contribution': self.group.sum_contribution, 'contribution': self.player.contribution, 'contribution_p1': self.group.contribution_p1, 'contribution_p2': self.group.contribution_p2, 'contribution_p3': self.group.contribution_p3, 'contribution_p4': self.group.contribution_p4, 'audit': self.player.audit, 'audit_p1': self.group.audit_p1, 'audit_p2': self.group.audit_p2, 'audit_p3': self.group.audit_p3, 'audit_p4': self.group.audit_p4, 'compliant': self.player.compliant, 'compliant_p1': self.group.compliant_p1, 'compliant_p2': self.group.compliant_p2, 'compliant_p3': self.group.compliant_p3, 'compliant_p4': self.group.compliant_p4, 'die_p1': self.group.die_p1, 'die_p2': self.group.die_p2, 'die_p3': self.group.die_p3, 'die_p4': self.group.die_p4, 'pay_fee': self.player.see_info, } class TPEnforcement(Page): def is_displayed(self): return self.group.treatment == 3 or self.group.treatment == 6 def vars_for_template(self): return { 'current_round': self.round_number, 'nb_round': Constants.num_rounds, } class PEnforcementWaitPage(WaitPage): def after_all_players_arrive(self): for p in self.group.get_players(): if p.group.treatment == 2 or p.group.treatment == 5: if p.id_in_group == 1: p.punish = (self.group.get_player_by_id(2).forfeit_p1 + self.group.get_player_by_id(3).forfeit_p1 + self.group.get_player_by_id(4).forfeit_p1)/(Constants.players_per_group - 1) if p.id_in_group == 2: p.punish = (self.group.get_player_by_id(1).forfeit_p2 + self.group.get_player_by_id( 3).forfeit_p2 + self.group.get_player_by_id(4).forfeit_p2) / (Constants.players_per_group - 1) if p.id_in_group == 3: p.punish = (self.group.get_player_by_id(1).forfeit_p3 + self.group.get_player_by_id( 2).forfeit_p3 + self.group.get_player_by_id(4).forfeit_p3) / (Constants.players_per_group - 1) if p.id_in_group == 4: p.punish = (self.group.get_player_by_id(1).forfeit_p4 + self.group.get_player_by_id( 2).forfeit_p4 + self.group.get_player_by_id(3).forfeit_p4) / (Constants.players_per_group - 1) class TPEnforcementWaitPage(WaitPage): def after_all_players_arrive(self): for p in self.group.get_players(): if p.group.treatment == 3 or p.group.treatment == 6: monitoring = p.group.get_player_by_id(1).pay_fee + p.group.get_player_by_id(2).pay_fee + p.group.get_player_by_id(3).pay_fee + p.group.get_player_by_id(4).pay_fee if monitoring > 0: if p.audit == 1 and p.compliant == 0: p.punish = 1 class EnforcementWaitPage(WaitPage): def after_all_players_arrive(self): for p in self.group.get_players(): #if p.group.treatment == 0 or p.group.treatment == 1 or p.group.treatment == 3 or p.group.treatment == 4 or p.group.treatment == 6: if p.id_in_group == 1: p.group.punish_p1 = p.punish elif p.id_in_group == 2: p.group.punish_p2 = p.punish elif p.id_in_group == 3: p.group.punish_p3 = p.punish else : p.group.punish_p4 = p.punish class RoundPayoff(WaitPage): def after_all_players_arrive(self): for p in self.group.get_players(): refund = Constants.bond - (Constants.bond * p.punish) p.refund = refund if p.group.treatment == 1 or p.group.treatment == 2 or p.group.treatment == 3: if p.pay_fee == 1: p.current_pay = Constants.endowment - p.contribution + Constants.mpcr * ( p.group.contribution_p1 + p.group.contribution_p2 + p.group.contribution_p3 + p.group.contribution_p4) + refund else: p.current_pay = Constants.endowment - p.contribution + Constants.mpcr * ( p.group.contribution_p1 + p.group.contribution_p2 + p.group.contribution_p3 + p.group.contribution_p4) + refund + 1 else: p.current_pay = Constants.endowment - p.contribution + Constants.mpcr * ( p.group.contribution_p1 + p.group.contribution_p2 + p.group.contribution_p3 + p.group.contribution_p4) + refund class Feedback(Page): # def is_displayed(self): # return self.participant.vars['time'] == 0 and self.session.config['treatment'] == 0 # timeout_seconds = 60 # timer_text = 'Time remaining on this page:' # # def get_timeout_seconds(self): # if self.participant.vars.get('is_dropout'): # return 1 # instant timeout, 0 second # else: # return 60 def vars_for_template(self): return { 'id': self.player.id_in_group, 'current_round': self.round_number, 'nb_round': Constants.num_rounds, 'refund_p1': round(self.group.get_player_by_id(1).refund), 'refund_p2': round(self.group.get_player_by_id(2).refund), 'refund_p3': round(self.group.get_player_by_id(3).refund), 'refund_p4': round(self.group.get_player_by_id(4).refund), 'current_pay': round(self.player.current_pay, 2), } class ResultsWaitPage(WaitPage): # title_text = "Waiting for the other group members." # body_text = "Pay attention to this screen: The timer for the next page could start any second. If you decide to withdraw from the study now, you will NOT receive your bonus payment." def is_displayed(self): return self.subsession.round_number == Constants.num_rounds #return self.subsession.round_number == Constants.num_rounds and self.participant.vars['time'] == 0 def after_all_players_arrive(self): for p in self.group.get_players(): #rand_round = random.randint(1, 5) rand_round = random.randint(1, 2) p.rand_round = rand_round #p.rand_round = rand_round payoff = p.in_round(rand_round).current_pay/Constants.rate p.payoff = payoff p.total_pay = Constants.participation_fee + payoff # if p.is_dropout is True: # p.payoff = 0 # else: # p.payoff = p.in_round(rand_round).current_pay class Demographics(Page): def is_displayed(self): # return self.subsession.round_number == Constants.num_rounds and self.participant.vars['time'] == 0 and self.participant.vars['is_dropout'] is False return self.subsession.round_number == Constants.num_rounds form_model = 'player' form_fields = ['q_english', 'q_age', 'q_gender', 'q_risk', 'q_clarity', 'q_check', 'q_other'] class Result(Page): def is_displayed(self): return self.subsession.round_number == Constants.num_rounds # return self.subsession.round_number == Constants.num_rounds and self.participant.vars['time'] == 0 and self.participant.vars['is_dropout'] is False def vars_for_template(self): return { 'rand_round': self.player.rand_round, 'current_pay': round(self.player.in_round(self.player.rand_round).current_pay), 'contribution': self.player.in_round(self.player.rand_round).contribution, 'sum_contribution': self.group.in_round(self.player.rand_round).sum_contribution, 'compliant': self.player.in_round(self.player.rand_round).compliant, 'refund': round(self.player.in_round(self.player.rand_round).refund), 'total_pay': round(self.player.total_pay, 2), 'show_up': Constants.participation_fee, 'payoff': self.player.payoff, 'pay_fee': self.player.pay_fee, } page_sequence = [ # StartWaitPage, # MatchingFailWaitPage, # MatchingFail, Intro, Instruction_procedure, Instruction_Accounts, Instruction_contribution, Instruction_information, Instruction_enforcement, Instruction_feedback, Instruction_summary, Contribution, AuditWaitPage, PGWaitPage, PMonitoring, TPMonitoring, SM_Info, PM_Info, TPM_Info, SEnforcement, PEnforcement, TPEnforcement, TPEnforcementWaitPage, PEnforcementWaitPage, EnforcementWaitPage, RoundPayoff, Feedback, ResultsWaitPage, Demographics, Result, ]