from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class WelcomePage(Page): # welcome page only on first round def is_displayed(self): return self.round_number == 1 def vars_for_template(self): num_players = len(self.subsession.get_players()) return dict( num_players = num_players ) class IntroRound(Page): # contains the info type of round, therefore displayed only before the # first token mkt, the first time mkt and decision of the binding mkt def vars_for_template(self): round_number = self.round_number num_rounds = Constants.num_rounds token_rounds = Constants.token_rounds time_rounds = Constants.time_rounds return dict( round_number = round_number, num_rounds = num_rounds, token_rounds = token_rounds, time_rounds = time_rounds ) def is_displayed(self): return self.round_number == 1 or self.round_number == Constants.token_rounds + 1 or self.round_number == Constants.num_rounds class PrepareRound(WaitPage): # assign the token value randomly to each participants after_all_players_arrive = 'prepare_round' wait_for_all_groups = True # this of course only for the rounds in which there is a mkt def is_displayed(self): return self.round_number <= Constants.token_rounds + Constants.time_rounds class Decision(Page): # page in which buyers take their decision form_model = 'player' form_fields = ['decision'] # displayed only to buyers and in rounds in which they have decide, # that is all but the last one in which the binding round is determined def is_displayed(self): return self.round_number <= Constants.token_rounds + Constants.time_rounds def vars_for_template(self): round_number = self.round_number token_rounds = Constants.token_rounds time_rounds = Constants.time_rounds token_value = self.player.token_value side = self.player.side if self.round_number <= Constants.token_rounds: sub_round = self.round_number else: sub_round = self.round_number - Constants.token_rounds return dict( round_number = round_number, token_rounds = token_rounds, time_rounds = time_rounds, sub_round = sub_round, token_value = token_value, side = side ) def before_next_page(self): if self.timeout_happened: self.player.auto_submitted = True class Equilibrium(WaitPage): # determine the outcome of the round, necessary even if there is no mkt # because th equilibrium method determine also the binding mkt after_all_players_arrive = 'equilibrium' wait_for_all_groups = True class ResultsMkt(Page): def vars_for_template(self): round_number = self.round_number num_rounds = Constants.num_rounds token_rounds = Constants.token_rounds time_rounds = Constants.time_rounds number_of_trades = self.subsession.number_of_trades has_traded = self.player.has_traded mkt_chosen = self.subsession.binding_mkt - Constants.token_rounds side = self.player.side excess_demand = self.subsession.excess_demand excess_supply = - 1 * self.subsession.excess_demand willing_to_trade = self.player.willing_to_trade return dict( round_number = round_number, num_rounds = num_rounds, token_rounds = token_rounds, time_rounds = time_rounds, number_of_trades = number_of_trades, has_traded = has_traded, mkt_chosen = mkt_chosen, side = side, excess_demand = excess_demand, excess_supply = excess_supply, willing_to_trade = willing_to_trade ) class ExtraPart(Page): # final irrelevant part timeout_seconds = 300 # displayed only to those who have to remain for that def is_displayed(self): return self.player.remain_last_part == True and self.round_number == Constants.num_rounds class FinalPage(Page): # final page with total points earned def is_displayed(self): return self.round_number == Constants.num_rounds page_sequence = [WelcomePage, IntroRound, PrepareRound, Decision, Equilibrium, ResultsMkt, ExtraPart, FinalPage]