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_W(Page): def is_displayed(self): return self.player.id_in_group in (1,3,5,7,9,11) form_model = 'player' form_fields = ['tokens' ] def error_message(self, values): if values['tokens'] > 15: return 'You can only purchase up to 15 tokens.' class Contribution_P(Page): def is_displayed(self): return self.player.id_in_group in (2,4, 6, 8,10,12) form_model = 'player' form_fields = ['tokens' ] def error_message(self, values): if values['tokens']>15: return 'You can only purchase up to 15 tokens.' 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 joywinning(Page): def is_displayed(self): return self.round_number == Constants.num_rounds form_model = 'player' form_fields = ['joy_winning_bids'] class joywinning_ResultsWaitPage(WaitPage): def is_displayed(self): return self.round_number == Constants.num_rounds def after_all_players_arrive(self): self.group.set_joywinning_payoffs() class joywinning_results(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 = ['attachment'] 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'], 'part2_payoff': self.player.in_round(Constants.num_rounds).joy_winning_earnings, 'part2_payoff_currency': self.player.in_round(Constants.num_rounds).joy_winning_earnings.to_real_world_currency(self.session), 'part12_payoff_currency': sum(p.round_earning for p in self.player.in_rounds(2, Constants.num_rounds)).to_real_world_currency(self.session) + self.player.in_round(Constants.num_rounds).joy_winning_earnings.to_real_world_currency(self.session), } page_sequence = [ Welcome, Practiceround_instruction, Contribution_W, Contribution_P, ResultsWaitPage, Results, Practiceround_summary, Part1_end, joywinning, joywinning_ResultsWaitPage, joywinning_results, Attachment, Riskaversion_instruction, Riskaversion_game, Demographic, Comment, Results_summary ]