from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class IntroPage(Page): def is_displayed(self): return self.round_number == 1 class PL_practice(Page): form_model = 'player' form_fields = ['pl_vote_test'] def is_displayed(self): return self.round_number == 1 and Constants.treatment == 1 class IR_practice(Page): timeout_seconds = 120 form_model = 'player' form_fields = ['IR_A_pr', 'IR_B_pr', 'IR_C_pr', 'IR_D_pr'] def is_displayed(self): return self.round_number == 1 and Constants.treatment == 3 class STAR_practice(Page): form_model = 'player' form_fields = ['STAR_A_pr', 'STAR_B_pr', 'STAR_C_pr', 'STAR_D_pr'] def is_displayed(self): return self.round_number == 1 and Constants.treatment == 2 class IntroWait(WaitPage): def after_all_players_arrive(self): players = self.group.get_players() for p in players: if Constants.treatment == 1: p.votes = int(Constants.payouts_pl[Constants.preferences[(self.round_number-1)//8]][0][p.id_in_group-1]) elif Constants.treatment == 2: p.votes = int(Constants.payouts_star[Constants.preferences[(self.round_number-1)//8]][0][p.id_in_group - 1]) elif Constants.treatment == 3: p.votes = int(Constants.payouts_ir[Constants.preferences[(self.round_number-1)//8]][0][p.id_in_group - 1]) class Pl_vote(Page): form_model = 'player' form_fields = ['pl_vote'] def is_displayed(self): return Constants.treatment == 1 def vars_for_template(self): return { 'players': self.group.get_players() } class STAR_vote(Page): form_model = 'player' form_fields = ['STAR_A', 'STAR_B', 'STAR_C', 'STAR_D'] def vars_for_template(self): return { 'players': self.group.get_players(), } def is_displayed(self): return Constants.treatment == 2 class IR_vote(Page): form_model = 'player' form_fields = ['IR_A', 'IR_B', 'IR_C', 'IR_D'] def vars_for_template(self): return { 'players': self.group.get_players() } def is_displayed(self): return Constants.treatment == 3 def error_message(self, values): print('Value is', values) if values['IR_A'] in [values['IR_B'], values['IR_C'], values['IR_D']] or values['IR_B'] in [values['IR_A'], values['IR_C'], values['IR_D']]\ or values['IR_C'] in [values['IR_B'], values['IR_A'], values['IR_D']]\ or values['IR_D'] in [values['IR_B'], values['IR_C'], values['IR_A']]: return 'Each alternative must have a unique ranking' class ResultsWaitPage(WaitPage): def after_all_players_arrive(self): players = self.group.get_players() player_id = [] for p in players: player_id.append(p.id_in_group) for p in players: other_group = [] for i in player_id: if p.id_in_group != i: other_group.append(i) else: pass p.other_player_1 = other_group[0] p.other_player_2 = other_group[1] if Constants.treatment == 1: self.group.vote_winner() self.group.get_payoffs_PL() actions = [] for p in players: actions.append(p.pl_vote) for p in players: count = 1 id = p.id_in_group other_actions = [] for a in actions: if count != id: other_actions.append(a) count += 1 else: count += 1 p.other_pl_vote1 = other_actions[0] p.other_pl_vote2 = other_actions[1] elif Constants.treatment == 2: runoff_cands = self.group.get_runoff() self.group.get_star_winner(runoff_cands) self.group.get_payoffs_STAR() a_choices = [] b_choices = [] c_choices = [] d_choices = [] for p in players: a_choices.append(p.STAR_A) b_choices.append(p.STAR_B) c_choices.append(p.STAR_C) d_choices.append(p.STAR_D) for p in players: other_a = [] other_b = [] other_c = [] other_d = [] count = 1 for a in a_choices: if count != p.id_in_group: other_a.append(a) count += 1 else: count += 1 count = 1 for a in b_choices: if count != p.id_in_group: other_b.append(a) count += 1 else: count += 1 count = 1 for a in c_choices: if count != p.id_in_group: other_c.append(a) count += 1 else: count += 1 count = 1 for a in d_choices: if count != p.id_in_group: other_d.append(a) count += 1 else: count += 1 p.other_action_11 = other_a[0] p.other_action_12 = other_b[0] p.other_action_13 = other_c[0] p.other_action_14 = other_d[0] p.other_action_21 = other_a[1] p.other_action_22 = other_b[1] p.other_action_23 = other_c[1] p.other_action_24 = other_d[1] elif Constants.treatment == 3: self.group.get_ir_winner() self.group.get_payoffs_IR() a_choices = [] b_choices = [] c_choices = [] d_choices = [] for p in players: a_choices.append(p.IR_A) b_choices.append(p.IR_B) c_choices.append(p.IR_C) d_choices.append(p.IR_D) for p in players: other_a = [] other_b = [] other_c = [] other_d = [] count = 1 for a in a_choices: if count != p.id_in_group: other_a.append(a) count += 1 else: count += 1 count = 1 for a in b_choices: if count != p.id_in_group: other_b.append(a) count += 1 else: count += 1 count = 1 for a in c_choices: if count != p.id_in_group: other_c.append(a) count += 1 else: count += 1 count = 1 for a in d_choices: if count != p.id_in_group: other_d.append(a) count += 1 else: count += 1 p.other_action_11 = other_a[0] p.other_action_12 = other_b[0] p.other_action_13 = other_c[0] p.other_action_14 = other_d[0] p.other_action_21 = other_a[1] p.other_action_22 = other_b[1] p.other_action_23 = other_c[1] p.other_action_24 = other_d[1] class Results_PL(Page): def is_displayed(self): return Constants.treatment == 1 def vars_for_template(self): return { 'players': self.group.get_players(), 'others_in_group': self.player.get_others_in_group(), } class Results_IR(Page): timeout_seconds = 30 def vars_for_template(self): return { 'players': self.group.get_players(), 'others_in_group': self.player.get_others_in_group(), } def is_displayed(self): return Constants.treatment == 3 class Results_STAR(Page): def vars_for_template(self): return { 'players': self.group.get_players(), 'others_in_group': self.player.get_others_in_group(), } def is_displayed(self): return Constants.treatment == 2 class new_block(Page): def is_displayed(self): return self.round_number in [9, 17, 25, 33] page_sequence = [ IntroPage, new_block, PL_practice, STAR_practice, IR_practice, IntroWait, Pl_vote, STAR_vote, IR_vote, ResultsWaitPage, Results_PL, Results_IR, Results_STAR, ]