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 = 'T4_control' 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.context_image_number = random.randint(1, 4) if self.round_number == 1: player.participant.vars['CommonFunctions'] = CommonFunctions() class Group(BaseGroup): def getTotalGroupScore(self): groups = self.in_all_rounds() group_scores = [] for group in groups: group_scores.append(sum([player.payoff for player in group.get_players()])) return sum(group_scores) def viewCodebookTapped(self, id_in_group, payload): player = self.get_player_by_id(id_in_group) if player.view_codebook_count > 0: player.view_codebook_count -= 1 print(f'Received from {id_in_group}, payload: {payload}') print(f'player view codebook count: {player.view_codebook_count}') return_dict = dict( view_codebook_count=player.view_codebook_count, ) 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_image_number = 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'], ]) question2 = models.IntegerField(widget=widgets.RadioSelect, choices=[ [1, 'a. + $6'], [2, 'b. - $6'], [3, 'c. + $1'], [4, 'd. 0'], ]) question3 = models.IntegerField(widget=widgets.RadioSelect, choices=[ [1, 'a. + $6'], [2, 'b. - $6'], [3, 'c. + $1'], [4, 'd. 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'], ]) question5 = models.IntegerField(widget=widgets.RadioSelect, choices=[ [1, 'a. The same dice will be rolled for all participants in this stage.'], [2, 'b. Each participant will have a dice, rolled separately.'], [3, 'c. None of the above.'], ]) 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'] ]) def question1_error_message(self, value): if value != 4: return 'Wrong choice' def question2_error_message(self, value): if value != 4: return 'Wrong choice' def question3_error_message(self, value): if value != 1: return 'Wrong choice' def question4_error_message(self, value): if value != 4: return 'Wrong choice' def question5_error_message(self, value): if value != 2: return 'Wrong choice' def question6_error_message(self, value): if value != 4: return 'Wrong choice'