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_Endo' players_per_group = 2 num_rounds = 1 class Subsession(BaseSubsession): def do_my_shuffle(self): self.group_randomly() 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): share = models.IntegerField(min=0, max=10) 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_1 = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, 'More'], [2, 'Fewer'],[3, 'Neither'],]) why_1 = models.LongStringField() strategy_2 = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, 'More Likely'], [2, 'Less Likely'],[3, 'Neither'],]) why_2 = models.LongStringField() def other_player(self): return self.get_others_in_group()[0] def set_payoff(self): if self.r3 == 1 and self.risk_random <= 3: self.post_questinnaire_payoff = self.other_player().share - self.share + 10 + 20 elif self.r3 == 1 and self.risk_random >= 4: self.post_questinnaire_payoff = self.other_player().share - self.share + 10 + 16 elif self.r3 == 2 and self.risk_random <= 3: self.post_questinnaire_payoff = self.other_player().share - self.share + 10 + 38.5 elif self.r3 == 2 and self.risk_random >= 4: self.post_questinnaire_payoff = self.other_player().share - self.share + 10 + 1 self.participant.vars['Post'] = self.post_questinnaire_payoff/10