from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) from .Stage4Game import Stage4Game import random author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'stage3_control' players_per_group = None num_rounds = 20 num_games = 10 class Subsession(BaseSubsession): def creating_session(self): if self.round_number == 1: self.session.vars['Stage4Game'] = Stage4Game(self) def get_other_player(self, is_first_mover, pairing_uuid): players = Player.objects.filter(pairing_uuid=pairing_uuid) for player in players: if not is_first_mover == player.is_first_mover: return player return None def update_payoff(self): game = self.session.vars['Stage4Game'] all_subsessions = self.in_rounds(1, Constants.num_rounds) for index, subsession in enumerate(all_subsessions): for player in subsession.get_players(): other_player = self.get_other_player(player.is_first_mover, player.pairing_uuid) first_mover_player = player if player.is_first_mover else other_player second_mover_player = other_player if player.is_first_mover else player print('is unique id equal: ', player.pairing_uuid == other_player.pairing_uuid) player.game_payoff = game.get_payoff( first_mover_player, second_mover_player, player.is_first_mover ) if index == Constants.num_rounds-1: random_round = random.randint(1, Constants.num_rounds) player.participant.vars['Stage3Earning'] = { 'Earning': player.in_round(random_round).payoff, 'Round': random_round } class Group(BaseGroup): pass class Player(BasePlayer): # True for first mover, False for second mover is_first_mover = models.BooleanField() # pairing uuid. this is to track the pairing for the game played pairing_uuid = models.StringField() # game number. this is to track the game number which the player played game_number = models.IntegerField() game_payoff = models.IntegerField() # decision choice (for first movers): 1 for A, 2 for B choice = models.IntegerField() # decision choice (for second movers) choice_if_A = models.IntegerField() choice_if_B = models.IntegerField() # control questionnaire 3 question1 = models.IntegerField(widget=widgets.RadioSelect, choices=[ [1, 'a. Choose between A or B'], [2, 'b. Choose between A or B when second mover has chosen A'], [3, 'c. Choose between A or B when second mover has chosen B'], [4, 'd. Both b and c are correct'], ]) question2 = models.IntegerField(widget=widgets.RadioSelect, choices=[ [1, 'a. Choose between A or B'], [2, 'b. Choose between A or B when second mover has chosen A'], [3, 'c. Choose between A or B when second mover has chosen B'], [4, 'd. Both b and c are correct'], ]) question3 = models.IntegerField(widget=widgets.RadioSelect, choices=[ [1, 'a. 1'], [2, 'b. 2'], [3, 'c. 3'], [4, 'd. 4'], ]) question4 = models.IntegerField(widget=widgets.RadioSelect, choices=[ [1, 'a. 4'], [2, 'b. 5'], [3, 'c. 6'], [4, 'd. 7'], ]) question5 = models.IntegerField(widget=widgets.RadioSelect, choices=[ [1, 'a. I will be paid for the points I earn in every round'], [2, 'b. I will be paid for the points I earn in one round'], [3, 'c. I will not know which round I will be paid for until the end of the experiment'], [4, 'd. This round is randomly determined by the computer'], [5, 'e. The coparticipant I am matched with is randomly determined in each round '] ]) question6 = models.IntegerField(widget=widgets.RadioSelect, choices=[ [1, 'a. S$10'], [2, 'b. S$20'], [3, 'c. S$30'], [4, 'd. S$40'] ]) def question1_error_message(self, value): if value != 1: return 'Wrong choice' def question2_error_message(self, value): if value != 4: return 'Wrong choice' def question3_error_message(self, value): if value != 3: return 'Wrong choice' def question4_error_message(self, value): if value != 1: return 'Wrong choice' def question5_error_message(self, value): if value != 1: return 'Wrong choice' def question6_error_message(self, value): if value != 2: return 'Wrong choice'