from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class Instruction(Page): def is_displayed(self): return self.round_number == 1 class procedure(Page): def is_displayed(self): return self.round_number == 1 class Simpletest(Page): def is_displayed(self): return self.round_number == 1 form_model = 'player' form_fields = ['q11', 'q12', 'q21', 'q22'] class Experiment(Page): form_model = 'player' form_fields = ['allocation1', 'allocation2'] def before_next_page(self): p = self.player #p.shortage1 = p.allocation1 - p.order1 #p.shortage2 = p.allocation2 - p.order2 p.total_allocation = p.allocation1+p.allocation2 p.payoff = p.total_allocation * 1 def vars_for_template(self): y1 = self.round_number - 1 e = self.player.in_previous_rounds() e.reverse() return { 'x1': y1, 'player_in_previous_rounds': e, } def error_message(self, values): print('', values) if values["allocation1"] + values["allocation2"] > 100: return 'The sum of the allocation exceeds the capacity. You can allocate only up to your limited capacity (100 products).' elif values["allocation1"] > Constants.determined_order1[self.round_number-1]: return 'The allocation exceeds the retailerA\'s order' elif values["allocation2"] > Constants.determined_order2[self.round_number-1]: return 'The allocation exceeds the retailerB\'s order' class Results(Page): def vars_for_template(self): payoff_up = 0 players = self.player.in_all_rounds() for p in players: payoff_up = payoff_up + p.payoff return { 'payoff_up': payoff_up } class EndPage(Page): def is_displayed(self): return self.round_number == 30 def app_after_this_page(self, upcoming_apps): return upcoming_apps[-1] def vars_for_template(self): dollars = self.participant.payoff_plus_participation_fee() play_d = dollars-1 payoff_up = 0 players = self.player.in_all_rounds() for p in players: payoff_up = payoff_up + p.payoff return {'dollars': dollars, 'payoff_up': payoff_up, 'play_d': play_d} page_sequence = [ Instruction, Simpletest, Experiment, Results, EndPage, ]