from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random import numpy doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'identity2' players_per_group = 3 # None for single player game num_rounds = 1 total_number = 6 # total participants, it should be the common divisor for 2 & 3 rate = 2/3 # discrimination rate, it should be 2/3 class Subsession(BaseSubsession): DM = models.IntegerField() def creating_session(self): if self.round_number == 1: self.DM = numpy.random.randint(1, 3) print("subsession DM:", self.DM) class Group(BaseGroup): #DM = models.IntegerField() recipient_1 = models.IntegerField() recipient_2 = models.IntegerField() allocation_1 = models.FloatField() allocation_2 = models.FloatField() # def assign_DM(self): # self.DM = random.randint(1, 3) class Player(BasePlayer): CQ1 = models.IntegerField( label="1. How many titles are you going to get in Part 1?", choices=[ [1, 'Depends on my performance, if I’m a top performer, I will get two titles, otherwise, one title.'], [2, 'One, top performer or bottom performer.'], [3, 'Two, one is top performer or bottom performer, and the other is prize owner or no prize.'], [4, 'Two, either top performer and prize owner, or bottom performer and no prize.'] ], widget=widgets.RadioSelect ) CQ2 = models.IntegerField( label="2. Who will get the prize owner in Part 1?", choices=[ [1, 'All top performers.'], [2, '2/3 of top performers.'], [3, '1/2 of top performers and 1/2 of bottom performers.'], [4, '2/3 of top performers and 1/3 of bottom performers.'] ], widget=widgets.RadioSelect ) CQ3 = models.IntegerField( label="3. What information can the allocator choose to learn?", choices=[ [1, 'Who is a top performer (for both group members), or who received a prize (for both group members).'], [2, 'The allocator can learn different titles (performance or prize) of different group members.'], [3, 'Both information of performance title and prize title.'], [4, 'Whether the group member (only this group member) is a top performer.'] ], widget=widgets.RadioSelect ) CQ4 = models.IntegerField( label="4. If you are one of the group members, and you want to reveal both titles to the allocator,\ what will you do?", choices=[ [1, 'Pay $0.25, and the allocator earns $1.'], [2, 'Pay $0.25, and the other group member earns $1.'], [3, 'Pay $0.25, and both titles of the other group member will also be revealed.'], [4, 'Pay $0.25, and the other group member’s information is independent of your decision.'], ], widget=widgets.RadioSelect ) choices = models.StringField() correctN = models.IntegerField() rank = models.IntegerField() top_p = models.StringField(initial='low') # initial is low performance prize = models.StringField(initial='no prize') # initial is no prize selection = models.StringField( label="What do you want to know about recipients?", choices=[ ['performance', 'Performance'], ['prize', 'Prize'], ['both', 'Pay $0.25 to know both'], ], widget=widgets.RadioSelect ) recipient_1 = models.IntegerField() recipient_2 = models.IntegerField() allocation_1 = models.FloatField() allocation_2 = models.FloatField() reci1_top = models.StringField() reci1_prize = models.StringField() reci2_top = models.StringField() reci2_prize = models.StringField() def assign_recipents(self): recipients = self.get_others_in_group() print('player', self.id_in_group, 'recipients', recipients) # print('recipients', recipients) self.recipient_1 = recipients[0].id_in_group self.recipient_2 = recipients[1].id_in_group if self.id_in_group == self.subsession.DM: self.group.recipient_1 = self.recipient_1 self.group.recipient_2 = self.recipient_2 print("group recipient 1:", self.recipient_1) print("group recipient 2:", self.recipient_2)