from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import random def vars_for_all_templates(self): return { 'amount_example_deal_p': self.player.participant.vars['amount_example_deal_p'], 'amount2_example_deal_p': self.player.participant.vars['amount2_example_deal_p'], 'round_number' : self.round_number, 'rand_number': self.player.Random_number, 'Letter': self.player.Letter } class Static(Page): form_model = 'player' form_fields = ['Choice'] def vars_for_template(self): return { 'list': self.player.participant.vars['amount_example_deal_p'][self.round_number-1], 'money1': self.player.participant.vars['amount_example_deal_p'][self.round_number - 1][0], 'money2': self.player.participant.vars['amount_example_deal_p'][self.round_number - 1][1], 'money3': self.player.participant.vars['amount_example_deal_p'][self.round_number - 1][2], } def before_next_page(self): self.player.lottery = ' '.join(str(e) for e in self.player.participant.vars['amount_example_deal_p'][self.round_number - 1]) self.player.Random_number = random.randint(0, 100) if self.player.Choice==3: self.player.Choice= random.randint(1,2) self.player.Dontcare=1 if self.player.Choice==2: self.player.Deleted = random.choice(self.player.participant.vars['amount_example_deal_p'][self.round_number-1]) if self.player.Choice==1: self.player.Payoff = random.choice(self.player.participant.vars['amount_example_deal_p'][self.round_number-1]) if self.player.Payoff >= self.player.Random_number: self.player.Letter= 100 else: self.player.Letter=0 class Static2(Page): def is_displayed(self): return self.player.Choice == 2 def vars_for_template(self): return { 'dontcare': self.player.Dontcare, 'choice': self.player.Dontcare * self.player.Choice, 'list': self.player.participant.vars['amount_example_deal_p'][self.round_number-1], 'money1': self.player.participant.vars['amount_example_deal_p'][self.round_number - 1][0], 'money2': self.player.participant.vars['amount_example_deal_p'][self.round_number - 1][1], 'money3': self.player.participant.vars['amount_example_deal_p'][self.round_number - 1][2], 'Deleted': self.player.Deleted } def before_next_page(self): self.player.participant.vars['amount_example_deal_p'][self.round_number - 1].remove(self.player.Deleted) self.player.Payoff = random.choice(self.player.participant.vars['amount_example_deal_p'][self.round_number - 1]) if self.player.Payoff >= self.player.Random_number: self.player.Letter = 100 else: self.player.Letter = 0 class Static_result(Page): def vars_for_template(self): return { 'dontcare': self.player.Dontcare, 'choice': self.player.Dontcare * self.player.Choice, 'money1': self.player.participant.vars['amount_example_deal_p'][self.round_number - 1][0], 'money2': self.player.participant.vars['amount_example_deal_p'][self.round_number - 1][1], 'money3': self.player.participant.vars['amount_example_deal_p'][self.round_number - 1][-1], 'payoff': self.player.Payoff, 'Deleted': self.player.Deleted, 'Deleted2': [i for i in self.player.participant.vars['amount_example_deal_p'][self.round_number - 1] if i != self.player.Payoff][0], 'Deleted3': [i for i in self.player.participant.vars['amount_example_deal_p'][self.round_number - 1] if i != self.player.Payoff][-1], } page_sequence = [Static, Static2, Static_result]