from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, Page, WaitPage ) cu = c doc = '' class Constants(BaseConstants): name_in_url = 'survey' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): pass def set_earnings_data(group): players = group.get_players() import random outcomecreation = random.randint(1,3) if outcomecreation == 1: group.paid_round = 1 elif outcomecreation == 2: group.paid_round = 2 else: group.paid_round = 3 for p in players: get_earnings_data(p) if group.paid_round == 1: p.finalearnings = p.round1earnings elif group.paid_round == 3: p.finalearnings = p.round3earnings else: p.finalearnings = p.round2earnings class Group(BaseGroup): paid_round = models.IntegerField() set_earnings_data = set_earnings_data def get_earnings_data(player): participant = player.participant player.round1earnings = participant.vars['round1earnings'] player.round2earnings = participant.vars['round2earnings'] player.round3earnings = participant.vars['round3earnings'] class Player(BasePlayer): gender = models.StringField(choices=[['Male', 'Male'], ['Female', 'Female'], ['I identify differently than male or female.', 'I identify differently than male or female.'], ['Prefer not to say', 'Prefer not to say']], label='What is your gender', widget=widgets.RadioSelect) crt_bat = models.IntegerField(label='A bat and a ball cost 22 dollars in total. The bat costs 20 dollars more than the ball. How many dollars does the ball cost?') crt_widget = models.IntegerField(label='If it takes 5 machines 5 minutes to make 5 widgets, how many minutes would it take 100 machines to make 100 widgets') crt_lake = models.IntegerField(label='In a lake there is a patch of lily pads Every day the patch doubles in size If it takes 48 days for the patch to cover the entire lake how many days would it take for the patch to cover half of the lake') round1earnings = models.CurrencyField() round2earnings = models.CurrencyField() round3earnings = models.CurrencyField() finalearnings = models.CurrencyField() probabilitytest = models.IntegerField(label='Suppose someone flips a fair coin four times. The first two flips land on heads. What is the likelihood of two heads landing on the next two flips? (Answer as a probability from 0 to 100) ', max=100, min=0) expectedvaluetest = models.IntegerField(label='Consider a gamble that pays out $100 sixty percent of the time and loses $100 forty percent of the time. If someone takes the gamble many times, how much will they win on average?') lossaversion = models.StringField(choices=[['Yes', 'Yes'], ['No', 'No']], label='You have also have the choice to participate in a lottery that pays $3 half the time and loses $2 half the time. Select “Yes” if you want to participate in the lottery and select “No” if you prefer to avoid the lottery.', widget=widgets.RadioSelect) riskaversion = models.IntegerField(label='Select the row after which you prefer Option B to Option A (0 means you always prefer Option B, 10 means you always prefer Option A)', max=10, min=0) yearincollege = models.StringField(choices=[['Freshman', 'Freshman'], ['Sophomore', 'Sophomore'], ['Junior', 'Junior'], ['Senior', 'Senior'], ['Super Senior', 'Super Senior'], ['Prefer not to say', 'Prefer not to say']], label='What is your year in school?') questionsearnings = models.CurrencyField(initial=0) lossaversionearnings = models.CurrencyField(initial=0) riskaversionearnings = models.CurrencyField(initial=0) get_earnings_data = get_earnings_data