from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random from random import randint author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'MTurk_debriefing' players_per_group = 2 num_rounds = 1 pot = c(10) showupfee = c(3) class Subsession (BaseSubsession): def before_session_starts(self): if self.round_number ==1: for p in self.get_players(): p.x3 = random.randint(0, 14) if self.round_number ==1: for p in self.get_players(): p.xp = random.randint(0, 100) def set_rand_agent(self): players = self.get_players() return [p.participant.id_in_session for p in players if p.id_in_group==2] #def set_rand_agent_new(self): #players = self.set_rand_agent() # p2 = self.get_player_by_id(2) #return [p for p in players if not p == self.p2.participant.id_in_session] def creating_session(self): for g in self.get_groups(): p2 = g.get_player_by_id(2) others = [x for x in self.set_rand_agent() if p2.participant.id_in_session!=x] g.rand_agent = random.choice(others) def rand_payoff_agent1(self): p2 = [p for p in self.get_players() if p.id_in_group == 2 ] for x in p2: all_groups = self.get_groups() match = [g for g in all_groups if x.participant.id_in_session==g.rand_agent] x.final_pay_ran = sum([g.random_payoff for g in match]) or 0 class Group(BaseGroup): def set_payoff(self): if self.round_number == 1: p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) p1.payoff = p2.profitP p2.payoff = p1.Decider_pay1 def set_beliefs(self): if self.round_number == 1: p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) p1.correctQ = p2.total def ran_pay(self): p1 = self.get_player_by_id(1) return p1.Decider_pay2 def ran_pay_final(self): if self.round_number == 1: self.random_payoff=self.ran_pay() rand_agent = models.IntegerField() class Player (BasePlayer): def role(self): if self.id_in_group == 1: return 'Decider' if self.id_in_group == 2: return 'Performer' Riskpreferences = models.IntegerField (min=0, max=100) #Overconfidence Overconfidence1 = models.IntegerField ( choices=[ [0, '51'], [1, '39'],], widget=widgets.RadioSelectHorizontal ) Overconfidence2 = models.IntegerField ( choices=[ [0, '21,305 km'], [1, '6,737 km'], ], widget=widgets.RadioSelectHorizontal ) Overconfidence3 = models.IntegerField ( choices=[ [0, '13'], [1, '17'],], widget=widgets.RadioSelectHorizontal ) Overconfidence4 = models.IntegerField ( choices=[ [0, '23'], [1, '39'], ], widget=widgets.RadioSelectHorizontal ) Overconfidence5 = models.IntegerField ( choices=[ [0, '5,872 km'], [1, '3,475 km'], ], widget=widgets.RadioSelectHorizontal ) Overconfidence6 = models.IntegerField ( choices=[ [0, '176,904 kg'], [1, '312,993 kg'], ], widget=widgets.RadioSelectHorizontal ) Overconfidence7 = models.IntegerField ( choices=[ [0, '1756'], [1, '1699'], ], widget=widgets.RadioSelectHorizontal ) Overconfidence8 = models.IntegerField ( choices=[ [0, '14 months '], [1, '22 months'], ], widget=widgets.RadioSelectHorizontal ) Overconfidence9 = models.IntegerField ( choices=[ [0, '9,588 km '], [1, '12,530 km'], ], widget=widgets.RadioSelectHorizontal ) Overconfidence10 = models.IntegerField ( choices=[ [0, '11,033 km '], [1, '4,521 km'], ], widget=widgets.RadioSelectHorizontal ) Overconfidence11 = models.IntegerField (min=0, max=10) #DemandAttribution DemandD = models.TextField( widget=widgets.Textarea (attrs={'rows': 1, 'cols': 8}), blank=True ) DemandP = models.TextField( widget=widgets.Textarea (attrs={'rows': 1, 'cols': 8}), blank=True ) AttributionP1 = models.IntegerField( choices=[ [1, 'Task 1'], [2, 'Task 2'], [3, 'Equally both'],] ) AttributionP2 = models.IntegerField( choices=[ [1, 'Mainly effort'], [2, 'Mainly ability'], [3, 'Equally both'],] ) AttributionP3 = models.IntegerField( choices=[ [1, 'Mainly effort'], [2, 'Mainly ability'], [3, 'Equally both'],] ) AttributionP4 = models.IntegerField( choices=[ [1, 'Task 1'], [2, 'Task 2'], [3, 'Equally both'],] ) AttributionP5 = models.IntegerField( choices=[ [1, 'Mainly effort'], [2, 'Mainly luck'], [3, 'Equally both'], ] ) AttributionPE = models.IntegerField( choices=[ [1, 'Yes, very much'], [2, 'Yes, a little'], [3, 'No'],] ) AttributionD1 = models.IntegerField ( choices=[ [1, 'Task 1'], [2, 'Task 2'], [3, 'Equally both'], ] ) AttributionD2 = models.IntegerField ( choices=[ [1, 'Mainly effort'], [2, 'Mainly ability'], [3, 'Equally both'], ] ) AttributionD3 = models.IntegerField ( choices=[ [1, 'Mainly effort'], [2, 'Mainly ability'], [3, 'Equally both'], ] ) AttributionD4 = models.IntegerField ( choices=[ [1, 'Task 1'], [2, 'Task 2'], [3, 'Equally both'], ] ) AttributionD5 = models.IntegerField ( choices=[1, 2, 3, 4, 5, 6, 7]) AttributionDE = models.IntegerField( choices=[ [1, 'Yes, very much'], [2, 'Yes, a little'], [3, 'No'],] ) AttributionD6 = models.IntegerField ( choices=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])