from otree.api import * doc = """ game_baseline """ PPG = 2 class C(BaseConstants): NAME_IN_URL = 'game_baseline' PLAYERS_PER_GROUP = PPG NUM_ROUNDS = 1 PAYOFF_MUTUAL_H = 0 PAYOFF_MUTUAL_L = 6 PAYOFF_H_WHEN_HL = 16 PAYOFF_L_WHEN_HL = 4 CHOICES = [0, 1] GREEN_ROLE = 'Green' BLUE_ROLE = 'Blue' FIXED_FEE = 3 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): coordinate = models.BooleanField( label="Please choose Action H or Action L.", choices=[ [True, 'L'], [False, 'H'], ] ) #iban1 = models.StringField(label='Please enter your International Bank Account Number (IBAN).') #iban2 = models.StringField(label='Please re-enter your International Bank Account Number (IBAN).') gender = models.StringField( label='How do you identify yourself?', choices=['Woman', 'Man', 'Other', 'I prefer not to say'], widget=widgets.RadioSelect, initial='' ) major = models.StringField( label='What is your major field of study?', choices=['Economics or Business', 'Psychology', 'Law', 'Other', 'Not a student','I prefer not to say'], widget=widgets.RadioSelect, initial='' ) iosblue = models.IntegerField( label='Which picture best describes your relationship with the Blue player?', choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal, ) iosgreen = models.IntegerField( label='Which picture best describes your relationship with the Green player?', choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal, ) q1 = models.IntegerField( label='On a scale from 1 (not at all) to 7 (very much), how helpful do you think communication was?', choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal ) q2 = models.StringField( label='Why do you think communication was (not) helpful?', blank=True ) otheraction = models.BooleanField( label='Which action do you expect the other player to choose?', choices=[ [True, 'L'], [False, 'H'] ] ) confidence = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], widget=widgets.RadioSelect ) satisfaction = models.IntegerField( #label='On a scale from 1 (not at all) to 7 (very much), how satisfied are you with the outcome?', choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal ) #payout = models.StringField( #initial=0 #) def is_coordinated(self): return 'L' if self.coordinate is True else 'H' def other_player(self): return self.get_others_in_group()[0] def get_partner(player: Player): return player.get_others_in_group()[0] # PAGES class Introduction(Page): @staticmethod def vars_for_template(player: Player): return dict(partner=get_partner(player).role) class IntroductionWaitPage(WaitPage): wait_for_all_groups = True class Chat(Page): @staticmethod def vars_for_template(player: Player): return dict(nickname=player.role, partner=get_partner(player).role) @staticmethod def js_vars(player: Player): return dict(my_id=player.id_in_group, my_role=player.role) @staticmethod def live_method(player: Player, data): partner = get_partner(player) if 'leaveChatOffer' in data: leaveChatOffers[player.participant.id_in_session] = data['leaveChatOffer'] leaveChatOffers[partner.participant.id_in_session] = leaveChatOffers.get(partner.participant.id_in_session, False) if leaveChatOffers[player.participant.id_in_session] and leaveChatOffers[partner.participant.id_in_session]: del leaveChatOffers[player.participant.id_in_session] del leaveChatOffers[partner.participant.id_in_session] return {0: dict(finished=True)} return {partner.id_in_group: data} class Coordination(Page): form_model = 'player' form_fields = ['coordinate'] class Expectations(Page): form_model = 'player' form_fields = ['otheraction', 'confidence'] def vars_for_template(player: Player): return dict(partner=get_partner(player).role) class ResultsWaitPage(WaitPage): @staticmethod def after_all_players_arrive(group: Group): player_list = group.get_players() player_1 = player_list[0] player_2 = player_list[1] if player_1.coordinate: if player_2.coordinate: player_1.payoff = C.PAYOFF_MUTUAL_L player_2.payoff = C.PAYOFF_MUTUAL_L else: player_1.payoff = C.PAYOFF_L_WHEN_HL player_2.payoff = C.PAYOFF_H_WHEN_HL else: if player_2.coordinate: player_1.payoff = C.PAYOFF_H_WHEN_HL player_2.payoff = C.PAYOFF_L_WHEN_HL else: player_1.payoff = C.PAYOFF_MUTUAL_H player_2.payoff = C.PAYOFF_MUTUAL_H class SurveyWaitPage(WaitPage): wait_for_all_groups = True class SurveyGreen(Page): form_model = 'player' form_fields = ['gender', 'major', 'iosblue', 'q1', 'q2'] @staticmethod def is_displayed(player): return player.role == 'Green' class SurveyBlue(Page): form_model = 'player' form_fields = ['gender', 'major', 'iosgreen', 'q1', 'q2'] @staticmethod def is_displayed(player): return player.role == 'Blue' #class PaymentInfo(Page): #form_model = 'player' #form_fields = ['iban1', 'iban2'] class WaitForOthers(WaitPage): wait_for_all_groups = True class Results(Page): @staticmethod def vars_for_template(player: Player): #player.payout = player.payoff+C.FIXED_FEE return dict(partner=get_partner(player), earnings=player.payoff+C.FIXED_FEE) class Satisfaction(Page): form_model = 'player' form_fields = ['satisfaction'] class ThankYou(Page): pass leaveChatOffers = dict() page_sequence = [Introduction, IntroductionWaitPage, Chat, Coordination, ResultsWaitPage, Expectations, SurveyWaitPage, SurveyGreen, SurveyBlue, WaitForOthers, Results, Satisfaction, ThankYou]