from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random from .CommonFunctions import CommonFunctions author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'T1' players_per_group = None num_rounds = 15 class Subsession(BaseSubsession): def creating_session(self): print('Creating round: ', self.round_number) for player in self.get_players(): player.chosen_context_image = random.randint(1, 4) if self.round_number == 1: player.participant.vars['CommonFunctions'] = CommonFunctions() commonFunctions = player.participant.vars['CommonFunctions'] actionImagesGroup = commonFunctions.getActionImagesGroup(self.round_number) player.correct_action_choice = actionImagesGroup[player.chosen_context_image-1] contextImages = commonFunctions.getContextImagesPath(self.round_number) player.context_image1 = contextImages[0] player.context_image2 = contextImages[1] player.context_image3 = contextImages[2] player.context_image4 = contextImages[3] class Group(BaseGroup): def viewCodebookTapped(self, id_in_group, payload): player = self.get_player_by_id(id_in_group) if player.view_codebook_count_left > 0: player.view_codebook_count_left -= 1 print(f'Received from {id_in_group}, payload: {payload}') print(f'player view codebook count: {player.view_codebook_count_left}') return_dict = dict( view_codebook_count=player.view_codebook_count_left, ) return {id_in_group: return_dict} class Player(BasePlayer): view_codebook_count_left = models.IntegerField(initial=5) action_choice = models.IntegerField() check_action_choice = models.IntegerField() # 0 if player selects the wrong action, 1 if player selects the correct action context_image1 = models.StringField() context_image2 = models.StringField() context_image3 = models.StringField() context_image4 = models.StringField() correct_action_choice = models.IntegerField() game_payoff = models.IntegerField(initial=0) chosen_context_image = models.IntegerField() # this is used to generate the random context for choose action choice # Control Questionnaire 1 question1 = models.IntegerField(widget=widgets.RadioSelect, choices=[ [1, 'a. 2'], [2, 'b. 4'], [3, 'c. 6'], [4, 'd. 8'], ]) question1_wrong_count = models.IntegerField(initial=0) question2 = models.IntegerField(widget=widgets.RadioSelect, choices=[ [1, 'a. + $6'], [2, 'b. - $6'], [3, 'c. + $1'], [4, 'd. 0'], ]) question2_wrong_count = models.IntegerField(initial=0) question3 = models.IntegerField(widget=widgets.RadioSelect, choices=[ [1, 'a. + $6'], [2, 'b. - $6'], [3, 'c. + $1'], [4, 'd. 0'], ]) question3_wrong_count = models.IntegerField(initial=0) question4 = models.IntegerField(widget=widgets.RadioSelect, choices=[ [1, 'a. Beginning of experiment'], [2, 'b. At the end of each stage'], [3, 'c. Halfway through the experiment'], [4, 'd. End of experiment'], ]) question4_wrong_count = models.IntegerField(initial=0) question5 = models.IntegerField(widget=widgets.RadioSelect, choices=[ [1, 'a. The same dice will be rolled for all participants.'], [2, 'b. Each participant will have a dice, rolled separately.'], [3, 'c. None of the above.'], ]) question5_wrong_count = models.IntegerField(initial=0) question6 = models.IntegerField(widget=widgets.RadioSelect, choices=[ [1, 'a. I will be paid a show-up fee of S$5'], [2, 'b. I will be able to earn S$6 from the lottery if the number drawn from the virtual dice land on 6'], [3, 'c. I have the opportunity to earn money from other stages apart from show-up fee and lottery'], [4, 'd. All of the above'] ]) question6_wrong_count = models.IntegerField(initial=0) def question1_error_message(self, value): if value != 4: self.question1_wrong_count += 1 return 'Wrong choice' def question2_error_message(self, value): if value != 4: self.question2_wrong_count += 1 return 'Wrong choice' def question3_error_message(self, value): if value != 1: self.question3_wrong_count += 1 return 'Wrong choice' def question4_error_message(self, value): if value != 4: self.question4_wrong_count += 1 return 'Wrong choice' def question5_error_message(self, value): if value != 2: self.question5_wrong_count += 1 return 'Wrong choice' def question6_error_message(self, value): if value != 4: self.question6_wrong_count += 1 return 'Wrong choice' def custom_export(players): # header row yield ['session', 'participant_code', 'participant_id', 'round_number', 'q1 wrong count', 'q2 wrong count', 'q3 wrong count', 'q4 wrong count', 'q5 wrong count', 'q6 wrong count', 'context image 1', 'context image 2', 'context image 3', 'context image 4', 'chosen context image', 'correct action choice', 'view codebook count left', 'player action choice', 'player check action choice'] for p in players: yield [p.session.code, p.participant.code, p.participant.id_in_session, p.round_number, p.question1_wrong_count, p.question2_wrong_count, p.question3_wrong_count, p.question4_wrong_count, p.question5_wrong_count, p.question6_wrong_count, p.context_image1, p.context_image2, p.context_image3, p.context_image4, p.chosen_context_image, p.correct_action_choice, p.view_codebook_count_left, p.action_choice, p.check_action_choice]