from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, safe_json ) import random import numpy as np from django import forms from django.forms import widgets as django_widgets import math author = 'Zheng Li' doc = """ Calculate payoff for study """ class Constants(BaseConstants): """Contains constants of the current experiment app.""" name_in_url = 'risk_uncertainty_goodbye_rep' players_per_group = None num_rounds = 1 attention_options = [ [1, "Extremely interested"], [2, "Very interested"], [3, "A little bit interested"], [4, "Very little interested"], [5, "Not at all interested"] ] # to generate the certainty-uncertainty spectrum bar list1 = np.arange(1 * 20, - 1, -1) list2 = [] list2.append(0) for x in range(20): list2.append((x + 1) * 5) class Subsession(BaseSubsession): pass class Group(BaseGroup): """Contains group-level objects of the current experiment app.""" pass class Player(BasePlayer): """Contains player-level objects of the current experiment app.""" # total payment bonus_amount = models.CurrencyField() failed_comprehension = models.BooleanField() gender_spec = models.StringField() # additional question add_qn_1 = models.IntegerField() add_qn_2 = models.IntegerField() add_qn_3 = models.IntegerField() attention_check = models.FloatField( blank=False, label="" ) age = models.IntegerField( max=100, min=16, label="Your age:", blank=False, ) 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 ) 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'], [3, 'other'] ], label="Your sex:" ) income_guess = models.IntegerField( label="Please provide your best guess of your annual household income:", blank=False ) def set_payoff(self): self.failed_comprehension = self.participant.vars['failed_comprehension'] self.bonus_amount = c(self.participant.payoff) 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"])