from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import math # from settings import * # --- FinLit ------------------------------------------------------------------ class FinLit(Page): form_model = 'player' form_fields = ['finlit_1', 'finlit_2', 'finlit_3', 'finlit_4', 'finlit_5', ] def vars_for_template(self): # specify info for task progress task = self.player.participant.vars['task_sequence'].index('Allocation') + 1 task_total = self.player.participant.vars['task_total'] task_progress = int(task / task_total * 100) # specify info for page progress page = self.subsession.round_number total = Constants.num_rounds progress = int(page / total * 100) return { 'page': page, 'total': total, 'progress': progress, 'task': task, 'task_total': task_total, 'task_progress': task_progress, } # --- Risk -------------------------------------------------------------------- class Risk(Page): form_model = 'player' form_fields = ['risk_aversion1', 'risk_aversion2' ] def vars_for_template(self): # specify info for task progress task = self.player.participant.vars['task_sequence'].index('Allocation') + 1 task_total = self.player.participant.vars['task_total'] task_progress = int(task / task_total * 100) # specify info for page progress page = self.subsession.round_number total = Constants.num_rounds progress = int(page / total * 100) return { 'page': page, 'total': total, 'progress': progress, 'task': task, 'task_total': task_total, 'task_progress': task_progress, } # --- Pref1 ------------------------------------------------------------------- class Pref1(Page): form_model = 'player' form_fields = ['pref1_1', 'pref1_2', 'pref1_3', 'pref1_4'] def vars_for_template(self): # specify info for task progress task = self.player.participant.vars['task_sequence'].index('Allocation') + 1 task_total = self.player.participant.vars['task_total'] task_progress = int(task / task_total * 100) # specify info for page progress page = self.subsession.round_number total = Constants.num_rounds progress = int(page / total * 100) return { 'page': page, 'total': total, 'progress': progress, 'task': task, 'task_total': task_total, 'task_progress': task_progress, } # --- Pref2 ------------------------------------------------------------------- class Pref2(Page): form_model = 'player' form_fields = ['pref2_1', 'pref2_2', 'pref2_3'] def vars_for_template(self): # specify info for task progress task = self.player.participant.vars['task_sequence'].index('Allocation') + 1 task_total = self.player.participant.vars['task_total'] task_progress = int(task / task_total * 100) # specify info for page progress page = self.subsession.round_number total = Constants.num_rounds progress = int(page / total * 100) return { 'page': page, 'total': total, 'progress': progress, 'task': task, 'task_total': task_total, 'task_progress': task_progress, } # --- CRT --------------------------------------------------------------------- class CRT(Page): form_model = 'player' form_fields = ['crt4', 'crt5', 'crt6', 'crt7' ] def vars_for_template(self): # specify info for task progress task = self.player.participant.vars['task_sequence'].index('Allocation') + 1 task_total = self.player.participant.vars['task_total'] task_progress = int(task / task_total * 100) # specify info for page progress page = self.subsession.round_number total = Constants.num_rounds progress = int(page / total * 100) return { 'page': page, 'total': total, 'progress': progress, 'task': task, 'task_total': task_total, 'task_progress': task_progress, } # --- Demographics ------------------------------------------------------------ class Demographics(Page): form_model = 'player' form_fields = ['age', 'female', 'income', 'education', 'jobfunction', 'jobfunctiongp', 'investment', 'whichinvestment', 'finnews', 'comments', 'matrikelnr', 'rate', 'understanding1', 'understanding2', 'understanding3' ] def vars_for_template(self): # specify info for task progress task = self.player.participant.vars['task_sequence'].index('Allocation') + 1 task_total = self.player.participant.vars['task_total'] task_progress = int(task / task_total * 100) # specify info for page progress page = self.subsession.round_number total = Constants.num_rounds progress = int(page / total * 100) return { 'page': page, 'total': total, 'progress': progress, 'task': task, 'task_total': task_total, 'task_progress': task_progress, # 'social': self.player.participant.vars['social'], 'investor': 'gp', 'currency_name': Constants.currency1, 'currency_symbol': Constants.currency2 } def before_next_page(self): self.player.set_random_code() self.player.set_payout() class ResultsWaitPage(WaitPage): def after_all_players_arrive(self): pass class ResultsTask(Page): def vars_for_template(self): return { 'rand_code': self.player.participant.vars['rand_code'], 'participant_label': self.participant.label, 'history': self.player.participant.vars['history'], 'history1': self.player.participant.vars['history'][0:6], 'history2': self.player.participant.vars['history'][6:12], 'history3': self.player.participant.vars['history'][12:], 'payoff_block': self.player.payoff_block, 'payoff_month': self.player.payoff_month, 'payoff_return': self.player.participant.vars['history'][6 * self.player.payoff_block - 6 + self.player.payoff_month][7], 'payoff': self.player.payoff } class Results(Page): form_model = 'player' form_fields = [ 'PaymentType', 'BANKname', 'BANKiban' ] def vars_for_template(self): return { 'rand_code': self.player.participant.vars['rand_code'], 'investor': 'prof', 'participant_label': self.participant.label, 'page': None, 'history': self.player.participant.vars['history'], 'payoff_taler': math.ceil(self.player.participant.vars['history'][6][3]), 'payoff_usd': math.ceil(self.player.participant.vars['history'][6][3]) / 5000, 'payoff': self.player.payoff } class Feedback(Page): pass # --- Page Sequence ----------------------------------------------------------- page_sequence = [ Risk, # Pref1, # Pref2, # FinLit, CRT, Demographics, ResultsTask, Results, # Feedback ]