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 = 'mturk_calc_payoff' 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 college degree'], [2, 'Currently in college'], [3, 'College degree'], [4, 'Masters degree'], [5, 'PhD'], ], label="Your highest educational attainment:", 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 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)