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 = 'a_group_post_questionnaire' 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 Americans'], [2, 'Asian / Pacific Islander'], [3, 'Caucasian'],[4, 'Hispanic or Latino'],[5, 'Native American'],[6, 'I prefer not to say'],]) strategy_g = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, 'Green'], [2, 'Yellow'],]) why_g = models.LongStringField() strategy_y = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, 'Green'], [2, 'Yellow'],]) why_y = models.LongStringField() strategy_gg = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, 'Yes'], [2, 'No'], ]) why_gg = models.LongStringField() strategy_gy = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, 'Yes'], [2, 'No'], ]) why_gy = models.LongStringField() strategy_yy = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, 'Yes'], [2, 'No'], ]) why_yy = models.LongStringField() strategy_yg = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, 'Yes'], [2, 'No'], ]) why_yg = models.LongStringField() parents_politics = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, 'Multiple times per day'], [2, 'Once per day'], [3, 'Multiple times per week'], [4, 'Once per week'], [5, 'Multiple times per month'], [6, 'Once per month'], [7, 'Very Rarely'], ]) party = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, 'Republican'], [2, 'Democrat'], [3, 'Lean Republican'], [4, 'Lean Democrat'], [5, 'Independent'],]) ideology = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, 'Very conservative'], [2, 'Very liberal'], [3, 'Conservative'], [4, 'Liberal'], [5, 'Moderate'],]) parents_party = models.StringField(widget=forms.CheckboxSelectMultiple (choices=[[1, 'Republican'], [2, 'Democrat'], [3, 'Lean Republican'], [4, 'Lean Democrat'], [5, 'Independent'],],) ) parents_ideology = models.StringField(widget=forms.CheckboxSelectMultiple (choices=[[1, 'Very conservative'], [2, 'Very liberal'], [3, 'Conservative'], [4, 'Liberal'], [5, 'Moderate'], ],) ) friends_repu = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, 'Multiple times per day'], [2, 'Once per day'], [3, 'Multiple times per week'], [4, 'Once per week'], [5, 'Multiple times per month'], [6, 'Once per month'], [7, 'Very Rarely'], ]) friends_demo = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, 'Multiple times per day'], [2, 'Once per day'], [3, 'Multiple times per week'], [4, 'Once per week'], [5, 'Multiple times per month'], [6, 'Once per month'], [7, 'Very Rarely'], ]) friends_inde = models.IntegerField(widget=widgets.RadioSelect, choices=[[1, 'Multiple times per day'], [2, 'Once per day'], [3, 'Multiple times per week'], [4, 'Once per week'], [5, 'Multiple times per month'], [6, 'Once per month'], [7, 'Very Rarely'], ]) media = 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