from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, safe_json ) from django import forms 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 = 'beliefs_goodbye' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): """Contains subsession-level objects of the current experiment app.""" 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) paying_task = models.StringField() total_payoff = models.FloatField() age = models.IntegerField( max=100, min=16, label="Your age:", blank=False, ) education = models.IntegerField( choices=[ [1, 'No high school graduation'], [2, 'High school graduate'], [3, 'Some college, but no degree'], [4, "Associate's degree"], [5, "Bachelor's degree"], [6, "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, ) 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 ) # 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, 'männlich'], # [2, 'weiblich'], # ], # label="Ihr Geschlecht:" # ) # free_form = models.LongStringField( # label="Haben Sie weitere Kommentare zu dieser Studie?" # ) def set_payoff(self): draw = random.randint(0, self.session.config['every_xth_person_paid']) if draw == 1: self.get_paid = True if 'possible_payoffs' in self.participant.vars: self.payoff = c(random.choice(self.participant.vars['possible_payoffs'])) else: self.payoff = 0 self.total_payoff = float(self.session.config['participation_fee'] + self.payoff)