from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer ) import random author = 'Eveline Vandewal' doc = """ Part 3 """ def make_likert_field(label): return models.IntegerField( label=label, choices=[0, 1, 2, 3], widget=widgets.RadioSelect, ) class Constants(BaseConstants): name_in_url = 'GMTA1_Part3' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): def calculate_payoffs(self): for p in self.get_players(): p.paying_period = p.participant.vars.get('paying_period') p.paying_decision = p.participant.vars.get('paying_decision') p.profit_part2 = p.participant.vars.get('profit_part2') random_number = random.randint(1, 10) # random_number = 10 for p in self.get_players(): p.paying_number = random_number p.profit_part3 = 0 if random_number == 10: participants_used = random.sample(self.get_players(), k=2) for p in participants_used: paying_decision = random.randint(1, 2) for q in participants_used: if p.id_in_group != q.id_in_group: p.other = q.id_in_group if p.treatment == 1 or paying_decision == 1: for q in participants_used: if p.other == q.id_in_group: choice_other = q.choice if p.choice == 1: p.profit_part3 = 30 if p.choice == 2 and choice_other == 1: p.profit_part3 = 70 if p.choice == 2 and choice_other == 2: p.profit_part3 = 0 if p.treatment == 2 and paying_decision == 2: correct_answer = sum([q.choice - 1 for q in self.get_players() if p.id_in_group != q.id_in_group]) \ / (len([q for q in self.get_players()]) - 1) loss = (correct_answer - (p.belief / 100)) * (correct_answer - (p.belief / 100)) another_random_number = random.uniform(0, 1) if loss < another_random_number: p.profit_part3 = 50 if loss > another_random_number: p.profit_part3 = 0 for p in self.get_players(): p.total_profit = round(float(p.profit_part2) + float(p.profit_part3) + 7.50, 2) p.participant.payoff = p.total_profit - 0.50 p.participant_vars_dump = str(p.participant.vars) def vars_for_admin_report(self): total_profits = [p.total_profit for p in self.get_players()] return dict(total_profits=total_profits) class Group(BaseGroup): pass class Player(BasePlayer): statement1 = make_likert_field('1. I am always trying to figure myself out.') statement2 = make_likert_field('2. I am concerned about my style of doing things.') statement3 = make_likert_field('3. It takes me time to get over my shyness in new situations.') statement4 = make_likert_field('4. I think about myself a lot.') statement5 = make_likert_field('5. I care a lot about how I present myself to others.') statement6 = make_likert_field('6. I often daydream about myself.') statement7 = make_likert_field('7. It is hard for me to work when someone is watching me.') statement8 = make_likert_field('8. I never take a hard look at myself.') statement9 = make_likert_field('9. I get embarrassed very easily.') statement10 = make_likert_field('10. I am self-conscious about the way I look.') statement11 = make_likert_field('11. It is easy for me to talk to strangers.') statement12 = make_likert_field('12. I generally pay attention to my inner feelings.') statement13 = make_likert_field('13. I usually worry about making a good impression.') statement14 = make_likert_field('14. I am constantly thinking about my reasons for doing things.') statement15 = make_likert_field('15. I feel nervous when I speak in front of a group.') statement16 = make_likert_field('16. Before I leave my house, I check how I look.') statement17 = make_likert_field('17. I sometimes step back in my mind to examine myself from a distance.') statement18 = make_likert_field('18. I am concerned about what other people think of me.') statement19 = make_likert_field('19. I am quick to notice changes in my mood.') statement20 = make_likert_field('20. I am usually aware of my appearance.') statement21 = make_likert_field('21. I know the way my mind works when I work through a problem.') statement22 = make_likert_field('22. Large groups make me nervous.') treatment = models.IntegerField() rank1 = models.IntegerField( label='You choose Option A and the other participant chooses Option A.', choices=[1, 2, 3, 4], widget=widgets.RadioSelect ) rank2 = models.IntegerField( label='You choose Option A and the other participant chooses Option B.', choices=[1, 2, 3, 4], widget=widgets.RadioSelect ) rank3 = models.IntegerField( label='You choose Option B and the other participant chooses Option A.', choices=[1, 2, 3, 4], widget=widgets.RadioSelect ) rank4 = models.IntegerField( label='You choose Option B and the other participant chooses Option B.', choices=[1, 2, 3, 4], widget=widgets.RadioSelect ) choice = models.IntegerField( choices=[ [1, 'Option A'], [2, 'Option B'] ], widget=widgets.RadioSelect ) belief = models.IntegerField() age = models.IntegerField() gender = models.IntegerField( choices=[ [1, 'Female'], [2, 'Male'], [3, 'Other'], [4, 'Prefer Not to Answer'] ], widget=widgets.RadioSelect ) nationality = models.IntegerField( choices=[ [1, 'German'], [2, 'Dutch'], [3, 'Belgian'], [4, 'Other European'], [5, 'African'], [6, 'Asian'], [7, 'Latin American'], [8, 'North American'], [9, 'Other'], ], widget=widgets.RadioSelect ) study = models.StringField() year = models.IntegerField() paying_period = models.IntegerField() paying_decision = models.IntegerField() paying_number = models.IntegerField() other = models.IntegerField() profit_part2 = models.IntegerField() profit_part3 = models.IntegerField() total_profit = models.FloatField() participant_vars_dump = models.StringField()