from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) #from django_countries.fields import CountryField from math import floor # ws May from random import randint class Constants(BaseConstants): name_in_url = 'survey6' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): q_gender = models.StringField( choices=['Male', 'Female'], label='What is your gender?', widget=widgets.RadioSelect(), blank=True ) q_country = models.StringField( label='What is your country of citizenship?', blank=True ) q_age = models.IntegerField( label='What is your age?', blank=True) q_risk = models.IntegerField( label='How do you see yourself: Are you generally a person who is fully prepared to take risks or do you try to avoid taking risks? Please select on a scale of 0 - 10, where the value 0 means “not at all willing to take risks” and the value 10 means “very willing to take risks”', choices=range(0, 11), initial=None, blank=True, ) q_major = models.StringField( verbose_name='What is your major?', blank=True, ) q_exp = models.StringField( choices=[ 'None at all', 'Basic; self-taught', 'Intermediate; 1 year of undergraduate studies', 'Advanced; 2 years or more of undergraduate studies', 'Expert; Post-graduate level' ], label='What is your level of understanding of Game Theory?', widget=widgets.RadioSelect(), blank=True, ) q_strategy = models.LongStringField( label='What strategy, if any, did you employ while participating in the Experiment?', blank=True, ) def set_payoff(self): """Calculate payoff, which is zero for the survey""" self.payoff = c(0) #draw = randint(0, 1) #if draw: # payoffT2 = self.participant.vars['PayoffT2a'] # self.participant.payoff -= self.participant.vars['PayoffT2b'] #else: # payoffT2 = self.participant.vars['PayoffT2b'] # self.participant.payoff -= self.participant.vars['PayoffT2a'] #self.participant.vars['PayoffT2'] = payoffT2 #draw = randint(0, 1) #if draw: # payoffT4 = self.participant.vars['PayoffT4a'] # self.participant.payoff -= self.participant.vars['PayoffT4b'] #else: # payoffT4 = self.participant.vars['PayoffT4b'] # self.participant.payoff -= self.participant.vars['PayoffT4a'] #self.participant.vars['PayoffT4'] = payoffT4 # For Treatment 6 # self.participant.payoff += self.participant.vars['PayoffT2a'] + self.participant.vars['PayoffT4a'] self.participant.payoff = self.participant.vars['PayoffT1'] + self.participant.vars['PayoffT2a'] + \ self.participant.vars['PayoffT2a'] + self.participant.vars['T3payoff'] + \ self.participant.vars['PayoffT4a'] + self.participant.vars['PayoffT4a'] + \ self.participant.vars['PayoffT5'] + self.participant.vars['PayoffT6'] + \ self.participant.vars['PayoffT7'] conversion = self.session.config['real_world_currency_per_point'] my_payoff = self.participant.payoff * conversion if my_payoff - floor(my_payoff) >= 0.5: self.participant.payoff = (floor(my_payoff) + 1) / conversion else: self.participant.payoff = floor(my_payoff) / conversion