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 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() self.group.set_punishment_contribution() class Punishment_UW(Page): # def is_displayed(self): # return self.player.id_in_group in (1,5,9) form_model = 'player' form_fields = [ 'punishment_sent1', 'punishment_sent2', # 'punishment_sent3', # 'punishment_sent4', # 'punishment_sent5', # 'punishment_sent6', # 'punishment_sent7', # 'punishment_sent8', # 'punishment_sent9', # 'punishment_sent10', ] class AfterPunishment(WaitPage): def after_all_players_arrive(self): self.group.set_punishment_payoff() class AfterPunishmentResult(Page): pass class Results(Page): pass class Part1_end(Page): def is_displayed(self): return self.round_number == Constants.num_rounds 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.payoff for p in self.player.in_all_rounds()), 'part1_payoff_currency':sum(p.payoff for p in self.player.in_all_rounds()).to_real_world_currency(self.session), } page_sequence = [ Contribution_UW, Contribution_UP, Contribution_RW, Contribution_RP, ResultsWaitPage, Results, Punishment_UW, AfterPunishment, AfterPunishmentResult, Part1_end, Demographic, Comment, Results_summary ]