from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, safe_json ) from django import forms from django.forms import widgets as django_widgets import math import random author = 'Nikolas Kirk' doc = """ Collect demographic info and calculate payoff """ class Constants(BaseConstants): name_in_url = 'intertemporal_choice_qn' players_per_group = None num_rounds = 1 SCALE = [(1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5'), (6, '6'), (7, '7'), (8, '8')] attention_options = [ [1, "Extremely interested"], [2, "Very interested"], [3, "A little bit interested"], [4, "Very little interested"], [5, "Not at all interested"] ] choices_buckets = [ [1, 'in the lowest 5%'], [2, 'in the lowest 5% to lowest 15%'], [3, 'in the lowest 15% to lowest 25%'], [4, 'in the lowest 25% to lowest 35%'], [5, 'in the lowest 35% to lowest 45%'], [6, 'in the middle 10%'], [7, 'in the highest 45% to highest 35%'], [8, 'in the highest 35% to highest 25%'], [9, 'in the highest 25% to highest 15%'], [10, 'in the highest 15% to highest 5%'], [11, 'in the highest 5%'], ] class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): get_paid = models.BooleanField(initial=False) income_guess = models.FloatField(min=0, max=10000000, label="", blank=False) percentile_ranking = models.IntegerField( widget=widgets.RadioSelect, label="", blank=False, choices=Constants.choices_buckets, ) certainty = models.IntegerField() payoff_relevant_part = models.IntegerField() # paying_task = models.StringField() fixed_bonus = models.CurrencyField() additional_bonus = models.CurrencyField() overall_bonus_incl_reward = models.CurrencyField() pay_today = models.CurrencyField() pay_later = models.CurrencyField() pay_date = models.StringField() failed_comprehension = models.BooleanField() possible_payoffs =models.StringField() gender_spec = models.StringField() gender_performance_pref = models.IntegerField(label="", blank="False") age = models.IntegerField( max=100, min=16, label="Your age:", blank=False, ) attention_check = models.StringField( widget=django_widgets.CheckboxSelectMultiple(choices=Constants.attention_options), blank=False, label="" ) education = models.IntegerField( choices=[ [1, 'No high school graduation'], [2, 'Currently in high school'], [3, 'High school graduate'], [4, 'Currently in college or graduate school'], [5, 'Some college, but no degree'], [6, "Associate's degree"], [7, "Bachelor's degree"], [8, "Graduate or professional degree"], ], label="Your highest educational attainment:", blank=False ) willingness_risk = models.IntegerField( widget=widgets.RadioSelectHorizontal, choices=range(11), label="""How do you see yourself: are you a person who is generally willing to take risks, or do you try to avoid taking risks? Please use a scale from 0 to 10, where a 0 means you are \"completely unwilling to take risks\" and a 10 means you are \"very willing to take risks\". You can also use the values in-between to indicate where you fall on the scale.""", blank=False, ) income = models.IntegerField( choices=[ [1, 'Below $10,000'], [2, '$10,000 - $14,999'], [3, '$15,000 - $24,999'], [4, '$25,000 - $34,999'], [5, '$35,000 - $49,999'], [6, '$50,000 - $74,999'], [7, '$75,000 - $99,999'], [8, '$100,000 - $149,999'], [9, '$150,000 - $199,999'], [10, '$200,000 or more'], ], label="Your approximate annual household income:", blank=False ) gender = models.IntegerField( choices=[ [1, 'male'], [2, 'female'], ], label="Your sex:" ) def set_payoff(self): self.failed_comprehension = self.participant.vars['failed_comprehension'] if not self.failed_comprehension: if 'possible_payoffs' in self.participant.vars: parts = len(self.participant.vars['possible_payoffs']) self.payoff_relevant_part = random.randint(1, parts) self.possible_payoffs = str(self.participant.vars['possible_payoffs']) self.fixed_bonus = c(6 * self.session.config['fixed_round_bonus']) x = self.participant.vars['possible_payoffs'][self.payoff_relevant_part - 1] self.payoff += c(x) self.additional_bonus = c(x) y = self.participant.vars['delayed_payment'] if y == 'yes': self.pay_today = c(self.fixed_bonus + self.session.config['participation_fee']) self.pay_later = c(self.additional_bonus) else: self.pay_later = c(0) self.pay_today = c(self.fixed_bonus + self.session.config['participation_fee'] + self.additional_bonus) self.pay_date = self.participant.vars['payment_timeframe'] else: self.additional_bonus = 0 self.fixed_bonus = 0 self.pay_today = c(self.session.config['participation_fee']) self.pay_later = c(0) self.overall_bonus_incl_reward = self.pay_today def set_comprehension(self): self.failed_comprehension = self.participant.vars['failed_comprehension'] def draw_gender_spec(self): self.gender_spec = random.choice(["3rd", "4th", "5th", "6th", "7th"])