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 = '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() paying_task = models.StringField() total_payoff = models.FloatField() age = models.IntegerField( max=100, min=16, label="Ihr Alter:", 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 # ) 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): total_choices = self.participant.vars['total_number_of_choices'] total_beliefs = self.participant.vars['num_choices_beliefs'] if random.random() <= self.session.config['prob_belief_paid_out']: weight_list = [ (self.participant.vars['num_choices_beliefs'] / total_beliefs, 'payoff_beliefs') ] else: weight_list = [ (self.participant.vars['num_choices_lists']/total_choices, 'payoff_lists'), # (self.participant.vars['num_choices_allais']/total_choices, 'payoff_allais'), # (self.participant.vars['num_choices_load']/total_choices, 'payoff_load'), ] l = sorted((random.random() * x[0], x[1]) for x in weight_list) self.paying_task = l[0][1] # draw = random.randint(0, self.session.config['every_xth_person_paid']) # if draw == 1: self.payoff = math.ceil(float(self.participant.vars[self.paying_task])) # self.get_paid = True # else: # self.payoff = 0 # self.get_paid = False self.total_payoff = float(self.session.config['participation_fee'] + self.payoff) # if self.participant.vars['condition_load']: # self.total_payoff = c(self.session.config['participation_fee'] + self.payoff + self.participant.vars['memory_payoff']) # else: # self.total_payoff = c(self.session.config['participation_fee'] + self.payoff)