from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants def shared_vars(self): """ get variables from session configs level """ return { 'income_spec': f'{int(self.player.task_specification):,}', 'session_type': self.session.config['type'], 'prize': c(self.session.config['survey_prize']), 'fee': c(self.session.config['participation_fee']), # 'every_xth_person_paid': self.session.config['every_xth_person_paid'], 'exp_duration': self.session.config['exp_duration'], 'max_duration': self.session.config['max_duration'], 'num_rounds': Constants.num_rounds, 'invest_value': str(100 + self.player.task_specification).rstrip('0').rstrip('.'), 'abs_task_spec': abs(self.player.task_specification), 'radio_amounts': list(zip([5*x for x in range(0,21)], list(range(1,22)))), } class BeginStudy(Page): def is_displayed(self): return self.round_number == 1 and not self.participant.vars['failed_comprehension'] def vars_for_template(self): return shared_vars(self) class Instructions(Page): def is_displayed(self): return self.round_number == 1 and not self.participant.vars['failed_comprehension'] def vars_for_template(self): return shared_vars(self) class LookedUpAnswer(Page): form_model = 'player' def get_form_fields(self): if self.session.config['type']=='risk' or self.session.config['type']=='beliefs': return ['looked_up_answer', 'used_calc'] else: return['looked_up_answer'] #form_fields = ['looked_up_answer', 'used_calc'] def is_displayed(self): return self.round_number == Constants.num_rounds and not self.participant.vars['failed_comprehension'] def vars_for_template(self): return shared_vars(self) # class IncomeDist(Page): # form_model = 'player' # form_fields = ['belief'] # def is_displayed(self): # #return self.player.task_type == 'income' and not self.participant.vars['failed_comprehension'] # #We're DROPPING this question # return False # def vars_for_template(self): # return shared_vars(self) # class IncomeDistCertainty(Page): # form_model = 'player' # form_fields = ['certainty'] # def is_displayed(self): # #return self.player.task_type == 'income' and not self.participant.vars['failed_comprehension'] # #We're DROPPING this question # return False # def vars_for_template(self): # return shared_vars(self) # def before_next_page(self): # self.player.set_payoff() class Stocks(Page): form_model = 'player' form_fields = ['belief'] def is_displayed(self): return self.player.task_type == 'stocks' and not self.participant.vars['failed_comprehension'] def vars_for_template(self): return shared_vars(self) class StocksCertainty(Page): form_model = 'player' form_fields = ['certainty'] def is_displayed(self): return self.player.task_type == 'stocks' and not self.participant.vars['failed_comprehension'] def vars_for_template(self): tmp = shared_vars(self) if self.player.belief < 1: tmpl = 0 tmph = 2 elif self.player.belief > 99: tmph = 100 tmpl=98 else: tmpl = self.player.belief -1 tmph = self.player.belief +1 tmp.update(low=tmpl, high=tmph) return tmp # def before_next_page(self): # self.player.set_payoff() class Inflation(Page): form_model = 'player' form_fields = ['belief'] def is_displayed(self): return self.player.task_type == 'inflation' and not self.participant.vars['failed_comprehension'] def vars_for_template(self): return shared_vars(self) class InflationCertainty(Page): form_model = 'player' form_fields = ['certainty'] def is_displayed(self): return self.player.task_type == 'inflation' and not self.participant.vars['failed_comprehension'] def vars_for_template(self): tmp = shared_vars(self) if self.player.belief < 1: tmpl = 0 tmph = 2 elif self.player.belief > 99: tmph = 100 tmpl=98 else: tmpl = self.player.belief -1 tmph = self.player.belief +1 tmp.update(low=tmpl, high=tmph) return tmp # def before_next_page(self): # self.player.set_payoff() class Welcome(Page): def is_displayed(self): return self.round_number == 1 def vars_for_template(self): return shared_vars(self) class Consent(Page): def is_displayed(self): return self.round_number == 1 def vars_for_template(self): return shared_vars(self) class Payment(Page): def is_displayed(self): return self.round_number == 1 and not self.participant.vars['failed_comprehension'] def vars_for_template(self): return shared_vars(self) class Wait(Page): def is_displayed(self): return self.round_number != Constants.num_rounds and not self.participant.vars['failed_comprehension'] timeout_seconds = 3 def vars_for_template(self): return shared_vars(self) page_sequence = [ # Welcome, # Consent, Instructions, #Payment, #BeginStudy, Stocks, StocksCertainty, #Inflation, #InflationCertainty, LookedUpAnswer, ]