from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants from otree.constants_internal import timeout_happened def vars_for_all_templates(self): return { 'num_round':self.subsession.round_number - 1, 'num_of_round': Constants.num_rounds - 1, } class Welcome (Page): def is_displayed(self): return self.round_number == 1 class Practiceround_instruction(Page): def is_displayed(self): return self.round_number == 1 class Practiceround_summary (Page): def is_displayed(self): return self.round_number == 1 class Contribution_UW(Page): def is_displayed(self): return self.player.id_in_group in (1, 5, 9) form_model = 'player' form_fields = ['tokens', 'token_U', 'token_W'] def error_message(self, values): if values['token_U'] + values['token_W'] != values['tokens']: return 'The tokens purchased for two groups should be equal to the total tokens you would like to purchase.' class Contribution_UP(Page): def is_displayed(self): return self.player.id_in_group in (2, 6, 10) form_model = 'player' form_fields = ['tokens', 'token_U', 'token_P'] def error_message(self, values): if values['token_U'] + values['token_P'] != values['tokens']: return 'The tokens purchased for two groups should be equal to the total tokens you would like to purchase.' class Contribution_RW(Page): def is_displayed(self): return self.player.id_in_group in (3, 7, 11) form_model = 'player' form_fields = ['tokens', 'token_R', 'token_W'] def error_message(self, values): if values['token_R'] + values['token_W'] != values['tokens']: return 'The tokens purchased for two groups should be equal to the total tokens you would like to purchase.' class Contribution_RP(Page): def is_displayed(self): return self.player.id_in_group in (4, 8, 12) form_model = 'player' form_fields = ['tokens', 'token_R', 'token_P'] def error_message(self, values): if values['token_R'] + values['token_P'] != values['tokens']: return 'The tokens purchased for two groups should be equal to the total tokens you would like to purchase.' class ResultsWaitPage(WaitPage): def after_all_players_arrive(self): self.group.set_payoffs() class Results(Page): pass class Part1_end(Page): def is_displayed(self): return self.round_number == Constants.num_rounds class Attachment(Page): def is_displayed(self): return self.round_number == Constants.num_rounds form_model = 'player' form_fields = ['attachment1', 'attachment2', 'attachment3', 'attachment4', 'attachment5', 'attachment6'] def error_message(self, values): if values['attachment1'] == 'Select' and (values['attachment2'] == 'Select' or values['attachment3']=='Select' or values['attachment4']=='Select' or values['attachment5']=='Select'or values['attachment6']=='Select'): return 'You can only select ONE scenario' if values['attachment2'] == 'Select' and (values['attachment1'] == 'Select' or values['attachment3']=='Select' or values['attachment4']=='Select' or values['attachment5']=='Select'or values['attachment6']=='Select'): return 'You can only select ONE scenario' if values['attachment3'] == 'Select' and (values['attachment1'] == 'Select' or values['attachment2']=='Select' or values['attachment4']=='Select' or values['attachment5']=='Select'or values['attachment6']=='Select'): return 'You can only select ONE scenario' if values['attachment4'] == 'Select' and (values['attachment1'] == 'Select' or values['attachment2']=='Select' or values['attachment3']=='Select' or values['attachment5']=='Select'or values['attachment6']=='Select'): return 'You can only select ONE scenario' if values['attachment5'] == 'Select' and (values['attachment1'] == 'Select' or values['attachment2']=='Select' or values['attachment3']=='Select' or values['attachment4']=='Select'or values['attachment6']=='Select'): return 'You can only select ONE scenario' if values['attachment6'] == 'Select' and (values['attachment1'] == 'Select' or values['attachment2']=='Select' or values['attachment3']=='Select' or values['attachment4']=='Select'or values['attachment5']=='Select'): return 'You can only select ONE scenario' class Riskaversion_instruction(Page): def is_displayed(self): return self.round_number == Constants.num_rounds class Riskaversion_game(Page): def is_displayed(self): return self.round_number == Constants.num_rounds form_model = 'player' form_fields =['HLchoice1', 'HLchoice2', 'HLchoice3', 'HLchoice4', 'HLchoice5', 'HLchoice6', 'HLchoice7', 'HLchoice8', 'HLchoice9', 'HLchoice10'] def error_message(self, values): #print(values['LTchoice1']) if values['HLchoice1'] == 'Lottery' and (values['HLchoice2'] == '$1.5 Sure amount' or values['HLchoice3']=='$1.5 Sure amount' or values['HLchoice4']=='$1.5 Sure amount' or values['HLchoice5']=='$1.5 Sure amount' or values['HLchoice6']=='$1.5 Sure amount' or values['HLchoice7']=='$1.5 Sure amount' or values['HLchoice8']=='$1.5 Sure amount' or values['HLchoice9']=='$1.5 Sure amount'or values['HLchoice10']=='$1.5 Sure amount'): return 'Since you choose Lottery in Game 1, you should stick to choosing Lottery in later games. Please refer notice 2.' if values['HLchoice2'] == 'Lottery' and (values['HLchoice3']=='$1.5 Sure amount' or values['HLchoice4']=='$1.5 Sure amount' or values['HLchoice5']=='$1.5 Sure amount'or values['HLchoice6']=='$1.5 Sure amount'or values['HLchoice7']=='$1.5 Sure amount' or values['HLchoice8']=='$1.5 Sure amount' or values['HLchoice9']=='$1.5 Sure amount'or values['HLchoice10']=='$1.5 Sure amount'): return 'Since you choose Lottery in Game 2, you should stick to choosing Lottery in later games. Please refer notice 2.' if values['HLchoice3'] == 'Lottery' and (values['HLchoice4']=='$1.5 Sure amount' or values['HLchoice5']=='$1.5 Sure amount'or values['HLchoice6']=='$1.5 Sure amount'or values['HLchoice7']=='$1.5 Sure amount' or values['HLchoice8']=='$1.5 Sure amount' or values['HLchoice9']=='$1.5 Sure amount'or values['HLchoice10']=='$1.5 Sure amount'): return 'Since you choose Lottery in Game 3, you should stick to choosing Lottery in later games. Please refer notice 2.' if values['HLchoice4'] == 'Lottery' and (values['HLchoice5']=='$1.5 Sure amount'or values['HLchoice6']=='$1.5 Sure amount'or values['HLchoice7']=='$1.5 Sure amount' or values['HLchoice8']=='$1.5 Sure amount' or values['HLchoice9']=='$1.5 Sure amount'or values['HLchoice10']=='$1.5 Sure amount'): return 'Since you choose Lottery in Game 4, you should stick to choosing Lottery in later games. Please refer notice 2.' if values['HLchoice5'] == 'Lottery' and (values['HLchoice6']=='$1.5 Sure amount'or values['HLchoice7']=='$1.5 Sure amount' or values['HLchoice8']=='$1.5 Sure amount' or values['HLchoice9']=='$1.5 Sure amount'or values['HLchoice10']=='$1.5 Sure amount'): return 'Since you choose Lottery in Game 5, you should stick to choosing Lottery in later games. Please refer notice 2.' if values['HLchoice6'] == 'Lottery' and (values['HLchoice7']=='$1.5 Sure amount' or values['HLchoice8']=='$1.5 Sure amount' or values['HLchoice9']=='$1.5 Sure amount'or values['HLchoice10']=='$1.5 Sure amount'): return 'Since you choose Lottery in Game 6, you should stick to choosing Lottery in later games. Please refer notice 2.' if values['HLchoice7'] == 'Lottery' and (values['HLchoice8']=='$1.5 Sure amount' or values['HLchoice9']=='$1.5 Sure amount'or values['HLchoice10']=='$1.5 Sure amount'): return 'Since you choose Lottery in Game 7, you should stick to choosing Lottery in later games. Please refer notice 2.' if values['HLchoice8'] == 'Lottery' and (values['HLchoice9']=='$1.5 Sure amount'or values['HLchoice10']=='$1.5 Sure amount'): return 'Since you choose Lottery in Game 8, you should stick to choosing Lottery in later games. Please refer notice 2.' if values['HLchoice9'] == 'Lottery' and (values['HLchoice10']=='$1.5 Sure amount'): return 'Since you choose Lottery in Game 9, you should stick to choosing Lottery in later games. Please refer notice 2.' class Demographic(Page): def is_displayed(self): return self.round_number == Constants.num_rounds form_model = 'player' form_fields = ['age', 'gender', 'citizenship', 'major', 'year', 'risk'] class Comment(Page): def is_displayed(self): return self.round_number == Constants.num_rounds form_model = 'player' form_fields = ['decision', 'comments'] class Results_summary(Page): def is_displayed(self): return self.round_number == Constants.num_rounds def vars_for_template(self): return { 'part1_payoff': sum(p.round_earning for p in self.player.in_rounds(2,Constants.num_rounds)), 'part1_payoff_currency': sum(p.round_earning for p in self.player.in_rounds(2,Constants.num_rounds)).to_real_world_currency( self.session), 'riskaversionchosen': self.session.vars['riskaversionchosen'], } page_sequence = [ Welcome, Practiceround_instruction, Contribution_UW, Contribution_UP, Contribution_RW, Contribution_RP, ResultsWaitPage, Results, Practiceround_summary, Part1_end, Attachment, Riskaversion_instruction, Riskaversion_game, Demographic, Comment, Results_summary ]