from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class Instructions(Page): pass class Decision(Page): def gamble_choice_error_message(self, value): if str(value) == 'e': return 'The gamble choice must be a number from 1 to 6' form_model = 'player' form_fields = ['gamble_choice'] class InsertGambleWaitPage(WaitPage): wait_for_all_groups = True pass class InsertGamble(Page): def is_displayed(self): return self.player.selected def chip_error_message(self, value): if not(value == Constants.value_for_high or value == Constants.value_for_low): return 'The string typed is not valid' form_model = 'player' form_fields = ['chip'] class ResultsWaitPage(WaitPage): wait_for_all_groups = True def after_all_players_arrive(self): options = { Constants.value_for_high : 1, Constants.value_for_low : 0 } players = self.subsession.get_players() player = players[self.subsession.choosen] player.payment = Constants.gamble_choices[player.gamble_choice][options[player.chip]] task1_payment = player.participant.vars['final_payment'] player.total_payment = player.payment + task1_payment chip = player.chip for p in self.subsession.get_players(): if p != player: p.chip = chip task1_payment = p.participant.vars['final_payment'] p.payment = Constants.gamble_choices[p.gamble_choice][options[p.chip]] p.total_payment = p.payment + task1_payment class Results(Page): def vars_for_template(self): amount = { Constants.value_for_high : 'High', Constants.value_for_low : 'Low ' } round_selected = 0 if 'round_selected' in self.player.participant.vars: round_selected = self.player.participant.vars['round_selected'] return{ 'amount' : amount[self.player.chip], 'final_payment' : self.player.participant.vars['final_payment'] - 10, 'round_selected' : round_selected, 'treatment' : self.player.participant.vars['treatment'] } page_sequence = [ Instructions, Decision, InsertGambleWaitPage, InsertGamble, ResultsWaitPage, Results ]