from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random from django import forms author = 'Siyu' doc = """ post-questionnaire """ class Constants(BaseConstants): name_in_url = 'b_belief_post_questionnaire_Exo' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): def creating_session(self): for player in self.get_players(): player.risk_random = random.randint(1, 10) print('player risk random is', player.risk_random) class Group(BaseGroup): pass class Player(BasePlayer): risk_random = models.IntegerField() post_questinnaire_payoff = models.CurrencyField() r1 = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1, 'A) 10% chance of 20 points and 90% of 16 points'], [2, 'B) 10% chance of 38.5 points and 90% of 1 point'], ]) r2 = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1, 'A) 20% chance of 20 points and 80% of 16 points'], [2, 'B) 20% chance of 38.5 points and 80% of 1 point'], ]) r3 = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1, 'A) 30% chance of 20 points and 70% of 16 points'], [2, 'B) 30% chance of 38.5 points and 70% of 1 point'], ]) r4 = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1, 'A) 40% chance of 20 points and 60% of 16 points'], [2, 'B) 40% chance of 38.5 points and 60% of 1 point'], ]) r5 = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1, 'A) 50% chance of 20 points and 50% of 16 points'], [2, 'B) 50% chance of 38.5 points and 50% of 1 point'], ]) r6 = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1, 'A) 60% chance of 20 points and 40% of 16 points'], [2, 'B) 60% chance of 38.5 points and 40% of 1 point'], ]) r7 = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1, 'A) 70% chance of 20 points and 30% of 16 points'], [2, 'B) 70% chance of 38.5 points and 30% of 1 point'], ]) r8 = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1, 'A) 80% chance of 20 points and 20% of 16 points'], [2, 'B) 80% chance of 38.5 points and 20% of 1 point'], ]) r9 = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1, 'A) 90% chance of 20 points and 10% of 16 points'], [2, 'B) 90% chance of 38.5 points and 10% of 1 point'], ]) r10 = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[1, 'A) 100% chance of 20 points and 0% of 16 point'], [2, 'B) 100% chance of 38.5 points and 0% of 1 point'], ]) gender = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, 'Female'], [2, 'Male'], [3, 'I prefer not to say'],]) major=models.StringField() gpa = models.FloatField(min=0, max=5) ethnicity = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, 'African American'], [2, 'Asian / Pacific Islander'], [3, 'Caucasian'],[4, 'Hispanic or Latino'],[5, 'Native American'],[6, 'I prefer not to say'],]) strategy = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, 'More Likely'], [2, 'Less Likely'],[3, 'Neither'],]) why = models.LongStringField() def set_payoff(self): if self.r3 == 1 and self.risk_random <= 3: self.post_questinnaire_payoff = 20 elif self.r3 == 1 and self.risk_random >= 4: self.post_questinnaire_payoff = 16 elif self.r3 == 2 and self.risk_random <= 3: self.post_questinnaire_payoff = 38.5 elif self.r3 == 2 and self.risk_random >= 4: self.post_questinnaire_payoff = 1 self.participant.vars['Post'] = self.post_questinnaire_payoff/10