from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants from django.views.decorators.csrf import csrf_exempt from django.utils.decorators import method_decorator import numpy as np def vars_for_all_templates(self): return { 'radio_amounts': zip(Constants.list2, Constants.list1), 'round': self.round_number, 'endowment': c(Constants.endowment), 'lottery_min': c(self.player.lottery_min), 'lottery_max': c(self.player.lottery_max), 'row_span': (Constants.choices['wta1'][1] - Constants.choices['wta1'][0]) / Constants.choices['wta1'][2] + 1, 'choice': self.player.choice_num } @method_decorator(csrf_exempt, name='dispatch') class InstructionsPart3(Page): def is_displayed(self): return (not self.participant.vars['failed_comprehension']) and self.round_number%2 == 1 class List(Page): def is_displayed(self): return not self.participant.vars['failed_comprehension'] def vars_for_template(self): min = self.player.lottery_min max = self.player.lottery_max step_size = self.player.step_size right_side_amounts = list(self.player.frange(min, max, step_size)) return { 'right_side_amounts': right_side_amounts, } def js_vars(self): return { 'fixed': self.player.lottery_max, 'choice': self.player.choice_num, 'min': self.player.lottery_min, 'max': self.player.lottery_max } form_model = 'player' form_fields = ['switching_point'] def before_next_page(self): self.player.set_switching_point_and_indicator() self.player.participant.vars[self.player.choice_name] = self.player.switching_point if self.round_number == Constants.num_rounds: self.player.set_payoff() class Valuation(Page): def is_displayed(self): return not self.participant.vars['failed_comprehension'] form_model = 'player' form_fields = ['confidence'] def vars_for_template(self): val_up = self.player.switching_point val_low = self.player.switching_point - self.player.step_size if val_up == 9999: val_up = self.player.lottery_max if val_up == 0: val_up = self.player.lottery_min return { 'val_up': c(val_up), 'val_low': c(val_low), 'left_up': c(Constants.endowment - val_up), 'left_low': c(Constants.endowment - val_low), 'switch': self.player.indicator_never_always_switcher } def js_vars(self): return { 'choice': self.player.choice_num } def before_next_page(self): self.player.confidence = 100 - 5 * (20 - self.player.confidence) page_sequence = [ InstructionsPart3, List, Valuation ]