from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import time class Introduction(Page): def is_displayed(self): return self.round_number==1 #form_model = 'player' #form_fields = ['stock_a_buy', 'stock_b_buy', 'stock_c_buy'] #def stock_a_buy_error_message(self, value): # if value!='Buy': # return 'You must buy one unit of EACH stock before beginning the game!' #def stock_b_buy_error_message(self, value): # if value!='Buy': # return 'You must buy one unit of EACH stock before beginning the game!' #def stock_c_buy_error_message(self, value): # if value!='Buy': # return 'You must buy one unit of EACH stock before beginning the game!' #def before_next_page(self): # self.player.stock_val() def before_next_page(self): self.player.buy_in_r1() self.player.stock_val() pass class Alert(Page): def is_displayed(self): return self.round_number==11 pass class CurrentStatusR1(Page): timeout_seconds = 15 def is_displayed(self): return self.round_number==1 def vars_for_template(self): return{ 'cash': self.player.cash, 'q_a':self.player.stock_a, 'q_b':self.player.stock_b, 'q_c':self.player.stock_c, 'value_a': self.player.stock_a * self.subsession.price_a, 'value_b': self.player.stock_b * self.subsession.price_b, 'value_c': self.player.stock_c * self.subsession.price_c, 'price_ba': self.player.price_bought_a, 'price_bb': self.player.price_bought_b, 'price_bc': self.player.price_bought_c, 'total': self.player.stock_a * self.subsession.price_a+self.player.stock_b * self.subsession.price_b+ self.player.stock_c * self.subsession.price_c+self.player.cash } def before_next_page(self): # user has 5 minutes to complete as many pages as possible self.participant.vars['expiry'] = time.time() + 40 pass class CurrentStatusMidR(Page): def get_timeout_seconds(self): return self.participant.vars['expiry'] - time.time() + 10 def is_displayed(self): return self.round_number in Constants.mid_r def vars_for_template(self): return { 'cash': self.player.cash, 'q_a': self.player.stock_a, 'q_b': self.player.stock_b, 'q_c': self.player.stock_c, 'value_a': self.player.stock_a * self.subsession.price_a, 'value_b': self.player.stock_b * self.subsession.price_b, 'value_c': self.player.stock_c * self.subsession.price_c, 'price_ba': self.player.price_bought_a, 'price_bb': self.player.price_bought_b, 'price_bc': self.player.price_bought_c, 'total': self.player.stock_a * self.subsession.price_a + self.player.stock_b * self.subsession.price_b + self.player.stock_c * self.subsession.price_c + self.player.cash } def before_next_page(self): # user has 5 minutes to complete as many pages as possible self.participant.vars['expiry'] = time.time() + 40 pass class CurrentStatusLR(Page): def get_timeout_seconds(self): return self.participant.vars['expiry'] - time.time() + 10 def is_displayed(self): return self.round_number in Constants.last_r def vars_for_template(self): return { 'cash': self.player.cash, 'q_a': self.player.stock_a, 'q_b': self.player.stock_b, 'q_c': self.player.stock_c, 'value_a': self.player.stock_a * self.subsession.price_a, 'value_b': self.player.stock_b * self.subsession.price_b, 'value_c': self.player.stock_c * self.subsession.price_c, 'price_ba': self.player.price_bought_a, 'price_bb': self.player.price_bought_b, 'price_bc': self.player.price_bought_c, 'total': self.player.stock_a * self.subsession.price_a + self.player.stock_b * self.subsession.price_b + self.player.stock_c * self.subsession.price_c + self.player.cash } def before_next_page(self): # user has 5 minutes to complete as many pages as possible self.participant.vars['expiry'] = time.time() + 40 pass class Action(Page): #do they have to know the price of the stock they are buying or selling? def get_timeout_seconds(self): return self.participant.vars['expiry'] - time.time() def is_displayed(self): return self.round_number>1 and self.round_number not in Constants.blocked_r form_model = 'player' form_fields = ['stock_a_buy', 'stock_b_buy', 'stock_c_buy', 'stock_a_sell', 'stock_b_sell', 'stock_c_sell'] def vars_for_template(self): return{ 'price_ba': self.player.in_round(self.round_number-1).price_bought_a, 'price_bb': self.player.in_round(self.round_number - 1).price_bought_b, 'price_bc': self.player.in_round(self.round_number - 1).price_bought_c, 'a_up': self.subsession.stock_update == 'a', 'b_up': self.subsession.stock_update == 'b', 'c_up': self.subsession.stock_update == 'c', 'buy_a': self.player.in_round(self.round_number-1).stock_a==0, 'buy_b': self.player.in_round(self.round_number - 1).stock_b == 0, 'buy_c': self.player.in_round(self.round_number - 1).stock_c == 0, 'price_change_a': self.subsession.price_a - self.subsession.in_round(self.round_number-1).price_a, 'price_change_b': self.subsession.price_b - self.subsession.in_round(self.round_number - 1).price_b, 'price_change_c': self.subsession.price_c - self.subsession.in_round(self.round_number - 1).price_c, 'round_n': self.round_number-1, 'cash': self.player.in_round(self.round_number-1).cash, 'q_a':self.player.in_round(self.round_number-1).stock_a, 'q_b':self.player.in_round(self.round_number-1).stock_b, 'q_c':self.player.in_round(self.round_number-1).stock_c, 'value_a': self.player.in_round(self.round_number-1).stock_a * self.subsession.price_a, 'value_b': self.player.in_round(self.round_number-1).stock_b * self.subsession.price_b, 'value_c': self.player.in_round(self.round_number-1).stock_c * self.subsession.price_c, 'total': self.player.in_round(self.round_number-1).stock_a * self.subsession.price_a+self.player.in_round(self.round_number-1).stock_b * self.subsession.price_b+ self.player.in_round(self.round_number-1).stock_c * self.subsession.price_c+self.player.in_round(self.round_number-1).cash } def before_next_page(self): self.player.stock_val() pass class ActionBlocked(Page): #do they have to know the price of the stock they are buying or selling? def get_timeout_seconds(self): return self.participant.vars['expiry'] - time.time() def is_displayed(self): return self.round_number>1 and self.round_number in Constants.blocked_r def vars_for_template(self): return{ 'price_ba': self.player.in_round(self.round_number-1).price_bought_a, 'price_bb': self.player.in_round(self.round_number - 1).price_bought_b, 'price_bc': self.player.in_round(self.round_number - 1).price_bought_c, 'a_up': self.subsession.stock_update == 'a', 'b_up': self.subsession.stock_update == 'b', 'c_up': self.subsession.stock_update == 'c', 'buy_a': self.player.in_round(self.round_number-1).stock_a==0, 'buy_b': self.player.in_round(self.round_number - 1).stock_b == 0, 'buy_c': self.player.in_round(self.round_number - 1).stock_c == 0, 'price_change_a': self.subsession.price_a - self.subsession.in_round(self.round_number-1).price_a, 'price_change_b': self.subsession.price_b - self.subsession.in_round(self.round_number - 1).price_b, 'price_change_c': self.subsession.price_c - self.subsession.in_round(self.round_number - 1).price_c, 'round_n': self.round_number-1, 'cash': self.player.in_round(self.round_number-1).cash, 'q_a':self.player.in_round(self.round_number-1).stock_a, 'q_b':self.player.in_round(self.round_number-1).stock_b, 'q_c':self.player.in_round(self.round_number-1).stock_c, 'value_a': self.player.in_round(self.round_number-1).stock_a * self.subsession.price_a, 'value_b': self.player.in_round(self.round_number-1).stock_b * self.subsession.price_b, 'value_c': self.player.in_round(self.round_number-1).stock_c * self.subsession.price_c, 'total': self.player.in_round(self.round_number-1).stock_a * self.subsession.price_a+self.player.in_round(self.round_number-1).stock_b * self.subsession.price_b+ self.player.in_round(self.round_number-1).stock_c * self.subsession.price_c+self.player.in_round(self.round_number-1).cash } def before_next_page(self): self.player.stock_val() pass class CalculatingPayoff(Page): def before_next_page(self): self.player.set_payoff() pass class Results(Page): timeout_seconds = 15 def is_displayed(self): return self.round_number==Constants.num_rounds def vars_for_template(self): return{ 'cash': self.player.cash, 'q_a':self.player.stock_a, 'q_b':self.player.stock_b, 'q_c':self.player.stock_c, 'value_a': self.player.stock_a * self.subsession.price_a, 'value_b': self.player.stock_b * self.subsession.price_b, 'value_c': self.player.stock_c * self.subsession.price_c, 'total': self.player.stock_a * self.subsession.price_a+self.player.stock_b * self.subsession.price_b+ self.player.stock_c * self.subsession.price_c+self.player.cash } pass page_sequence = [ Introduction, #Alert, Action, #ActionBlocked, CurrentStatusR1, CurrentStatusMidR, CurrentStatusLR, #Update, CalculatingPayoff, # Results ]