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 = 'Thomas Graeber' doc = """ Calculate payoff for study """ class Constants(BaseConstants): """Contains constants of the current experiment app.""" name_in_url = 'risk_uncertainty_goodbye' players_per_group = None num_rounds = 1 SCALE = [(1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5'), (6, '6'), (7, '7'), (8, '8')] no_raven_matrices = 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): """Contains group-level objects of the current experiment app.""" pass class Player(BasePlayer): """Contains player-level objects of the current experiment app.""" 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() failed_comprehension = models.BooleanField() possible_payoffs =models.StringField() raven_payoff = models.CurrencyField() correct_answers = models.PositiveIntegerField() 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 ) # math = models.IntegerField( # widget=widgets.RadioSelectHorizontal, # choices=range(11), # label="On a scale from 0='very bad' to 10='very good', how good are you at math?", # 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 ) # browser = models.IntegerField( # choices=[ # [1, 'Chrome'], # [2, 'Edge / Internet Explorer'], # [3, 'Firefox'], # [4, 'Safari'], # [5, 'Opera'], # [6, 'Mobile phone'], # [7, 'Other'], # ], # label="Which browser did you use to work on this HIT?", # blank=False # ) raven_1 = models.PositiveIntegerField( initial=None, choices=Constants.SCALE, verbose_name='', blank=False, widget=widgets.RadioSelectHorizontal() ) raven_2 = models.PositiveIntegerField( initial=None, choices=Constants.SCALE, verbose_name='', blank=False, widget=widgets.RadioSelectHorizontal() ) raven_3 = models.PositiveIntegerField( initial=None, choices=Constants.SCALE, verbose_name='', blank=False, widget=widgets.RadioSelectHorizontal() ) raven_4 = models.PositiveIntegerField( initial=None, choices=Constants.SCALE, verbose_name='', blank=False, widget=widgets.RadioSelectHorizontal() ) raven_5 = models.PositiveIntegerField( initial=None, choices=Constants.SCALE, verbose_name='', blank=False, widget=widgets.RadioSelectHorizontal() ) raven_6 = models.PositiveIntegerField( initial=None, choices=Constants.SCALE, verbose_name='', blank=False, widget=widgets.RadioSelectHorizontal() ) raven_7 = models.PositiveIntegerField( initial=None, choices=Constants.SCALE, verbose_name='', blank=False, widget=widgets.RadioSelectHorizontal() ) raven_8 = models.PositiveIntegerField( initial=None, choices=Constants.SCALE, verbose_name='', blank=False, widget=widgets.RadioSelectHorizontal() ) # education = models.IntegerField( # choices=[ # [1, 'Kein Universitätsabschluss'], # [2, 'Derzeit im Bachelorstudium'], # [3, 'Bachelorabschluss (oder gleichwertig)'], # [4, 'Derzeit im Masterstudium'], # [5, 'Masterabschluss (oder gleichwertig)'], # [6, 'Promotion'], # ], # label="Ihr höchster Bildungsabschluss:", # blank=False # ) # study_field = models.IntegerField( # choices=[ # [1, 'Wirtschaftswissenschaften'], # [2, 'Andere Sozialwissenschaften'], # [3, 'Natur- und Ingenieurswissenschaften'], # [4, 'Geisteswissenschaften'], # [5, 'Anderes Studienfach'], # [6, 'Kein Student'], # ], # label="Ihr Studienfach:", # blank=False # ) # how_comprehensible = models.IntegerField( # choices=[ # [1, 'Sehr unverständlich'], # [2, 'Eher unverständlich'], # [3, 'Weder noch'], # [4, 'Eher verständlich'], # [5, 'Sehr verständlich'], # ], # label="Wie verständlich fanden Sie diese Studie?" # ) gender = models.IntegerField( choices=[ [1, 'male'], [2, 'female'], ], label="Your sex:" ) # free_form = models.LongStringField( # label="Haben Sie weitere Kommentare zu dieser Studie?" # ) 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']) x = self.participant.vars['possible_payoffs'][self.payoff_relevant_part - 1] self.payoff += c(x) self.additional_bonus = c(x) # for x in self.participant.vars['possible_payoffs']: # draw = random.randint(1, self.session.config['every_xth_person_paid']) # if draw == 1: # self.payoff += c(x) # if self.payoff > 0: # self.get_paid = True self.fixed_bonus = c(6 * self.session.config['fixed_round_bonus']) else: self.additional_bonus = 0 self.fixed_bonus = 0 self.overall_bonus_incl_reward = self.participant.payoff_plus_participation_fee() def set_comprehension(self): self.failed_comprehension = self.participant.vars['failed_comprehension'] def set_payoff_raven(self): """ Calculate the player's payoff for the raven task. """ iq_solution = [5, 6, 5, 3, 2, 6, 6, 4] pp_solutions = [ self.raven_1, self.raven_2, self.raven_3, self.raven_4, self.raven_5, self.raven_6, self.raven_7, self.raven_8, ] list_correct = [x for x, y in zip(iq_solution, pp_solutions) if x == y] self.correct_answers = len(list_correct) self.raven_payoff = self.correct_answers * self.session.config['raven_incentive'] possible_payoff = self.session.config['raven_incentive'] * self.correct_answers if 'possible_payoffs' in self.participant.vars: self.participant.vars['possible_payoffs'].append(round(possible_payoff, 2)) else: self.participant.vars['possible_payoffs'] = [round(possible_payoff, 2)] # draw = random.randint(1, self.session.config['every_xth_person_paid']) # if draw == 1: # self.payoff += self.session.config['raven_incentive'] * self.correct_answers def draw_gender_spec(self): self.gender_spec = random.choice(["3rd", "4th", "5th", "6th", "7th"])