from otree.api import * import random doc = """ Your app description """ import random class C(BaseConstants): NAME_IN_URL = 'multiplayer_app' PLAYERS_PER_GROUP = 3 #revert NUM_ROUNDS = 144 #new #NUM_ROUNDS = 150 payoffFullCons = 2 payoffHalfCons = 1 payoffDiss = 0 #new #cellColors = ["IndianRed", "RoyalBlue", "SeaGreen", "Gold", "Lavender", "Indigo"] #revert cellColors = ["red", "blue", "green", "yellow", "purple", "brown"] images = ["diamond", "square", "triangle", "circle"] print("cellColors: ",cellColors) print("images: ",images) random.shuffle(cellColors) #random.shuffle(images) print("cellColors: ",cellColors) print("images: ",images) rewardLevel = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] random.shuffle(rewardLevel) print(len(rewardLevel)) #new: # no probe until after 12 trials, and a probe for every 4 normal """ trialType = [1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0] """ #revert trialType = [1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0] #probeType = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3] probeType = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3] #new #probeType = [1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6] # 1 = 1 v 3 (win-cons v win-diss) # 2 = 2 v 4 (lose-cons v lose-diss) # 3 = 1 v 2 (win-cons v lose-cons) # 4 = 2 v 3 (lose-cons v win-diss) # 5 = 3 v 4 (win-diss v lose-diss) # 6 = high v low random.shuffle(probeType) normalRoundNum = 0 probeRoundNum = 0 # cellColorsInit = ["IndianRed", "SkyBlue", "PaleGreen", "LemonChiffon"] # cellColors = random.shuffle(cellColorsInit) # imagesInit = ['star', 'diamond', 'gear', 'moon'] # images = random.shuffle(imagesInit) #imagesHighRew = images[0,1] #imagesLowRew = images[2,3] #class Session(BaseSession): # an event during which multiple participants take part in a series of tasks or games. An example of a session would be: class Subsession(BaseSubsession): # subsessions include pre-rating, trials, post-rating cellColors = models.StringField() images = models.StringField() # built-in fields: # round_number: gives the current round number # get_players(): returns list of all players in subsession class Group(BaseGroup): # group of players. this experiment only has 1 group composed of 3 players fullConsensus = models.BooleanField(initial=False) reward_left = models.FloatField(initial=0) reward_right = models.FloatField(initial=0) reward_left_string = models.StringField(initial='') reward_right_string = models.StringField(initial='') randomDraw = models.IntegerField(initial=0) images_left = models.StringField(initial='') images_right = models.StringField(initial='') randomDrawProbe = models.IntegerField(initial=0) rewardLev = models.IntegerField(initial=0) probeTypeCurr = models.IntegerField(initial=0) probeColorLeft = models.StringField(initial='') probeColorRight = models.StringField(initial='') colors = models.StringField(initial='') class Player(BasePlayer): # if the variable is at the player level, put here chosBandit = models.StringField(initial='') # declare choice at player level to get individual choices fullConsensus = models.BooleanField(initial=False) socialLocation = models.StringField(initial='') placement = models.StringField(initial='') rewardWin = models.BooleanField(initial=False) condition = models.StringField(initial='') cellColors = models.StringField(initial='') images = models.StringField(initial='') colorLeft = models.StringField(initial='') colorRight = models.StringField(initial='') name = models.StringField() player1_name = models.StringField() player2_name = models.StringField() player3_name = models.StringField() # PAGES class Instructions(Page): @staticmethod def vars_for_template(player: Player): group = player.group class PreRating(Page): @staticmethod def vars_for_template(player: Player): group = player.group class PreRatingWait(WaitPage): # after_all_players_arrive = move_to_next_slide() pass class FixationProbe(Page): form_model = 'player' timeout_seconds = 1 @staticmethod def is_displayed(player): return C.trialType[player.round_number-1] == 0 def vars_for_template(player: Player): group = player.group #revert probeTrialNum = player.round_number//6 #new #probeTrialNum = player.round_number//5 probeTypeCurrent = C.probeType[probeTrialNum-1] group.randomDrawProbe = random.randint(0,1) if C.probeType[probeTrialNum-1] == 1: # condition 1 v 3 (W+C vs W+D) if group.randomDrawProbe == 0: player.condition = '1 v 3' group.images_left = "images/x.png" group.images_right = "images/x.png" group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[0] group.probeColorRight = C.cellColors[2] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[0]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[2]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[0], colorRight = C.cellColors[2] ) elif group.randomDrawProbe == 1: player.condition = '3 v 1' group.images_left = C.images[0] group.images_right = C.images[0] group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[2] group.probeColorRight = C.cellColors[0] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[0]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[2]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[2], colorRight = C.cellColors[0] ) elif C.probeType[probeTrialNum-1] == 2: # condition 2 v 4 (L+C vs L+D) if group.randomDrawProbe == 0: player.condition = '2 v 4' group.images_left = "images/x.png" group.images_right = "images/x.png" group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[1] group.probeColorRight = C.cellColors[3] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[1]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[3]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[1], colorRight = C.cellColors[3] ) elif group.randomDrawProbe == 1: player.condition = '4 v 2' group.images_left = "images/x.png" group.images_right = "images/x.png" group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[3] group.probeColorRight = C.cellColors[1] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[1]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[3]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[3], colorRight = C.cellColors[1] ) #revert elif C.probeType[probeTrialNum-1] == 3: #high reward vs low reward player.condition = 'none' group.images_left = C.images[0] group.images_right = C.images[3] group.probeTypeCurr = probeTypeCurrent return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format('white_' + C.images[0]), #imageRight = "images/{}.png".format('white_' + C.images[3]) imageLeft = "images/{}.png".format(C.images[0]), imageRight = "images/{}.png".format(C.images[3]) ) # 1 = 1 v 3 (win-cons v win-diss) # 2 = 2 v 4 (lose-cons v lose-diss) # 3 = 1 v 2 (win-cons v lose-cons) # 4 = 2 v 3 (lose-cons v win-diss) # 5 = 3 v 4 (win-diss v lose-diss) # 6 = high v low #new """ if C.probeType[probeTrialNum-1] == 3: # condition 1 v 2 (W+C vs L+C) if group.randomDrawProbe == 0: player.condition = '1 v 2' group.images_left = "images/x.png" group.images_right = "images/x.png" group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[0] group.probeColorRight = C.cellColors[1] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[0]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[1]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[0], colorRight = C.cellColors[1] ) elif group.randomDrawProbe == 1: player.condition = '2 v 1' group.images_left = C.images[0] group.images_right = C.images[0] group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[1] group.probeColorRight = C.cellColors[0] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[0]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[1]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[1], colorRight = C.cellColors[0] ) elif C.probeType[probeTrialNum-1] == 4: # condition 2 v 3 (L+C vs W+D) if group.randomDrawProbe == 0: player.condition = '2 v 3' group.images_left = "images/x.png" group.images_right = "images/x.png" group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[1] group.probeColorRight = C.cellColors[2] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[1]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[2]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[1], colorRight = C.cellColors[2] ) elif group.randomDrawProbe == 1: player.condition = '3 v 2' group.images_left = "images/x.png" group.images_right = "images/x.png" group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[2] group.probeColorRight = C.cellColors[1] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[1]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[2]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[2], colorRight = C.cellColors[1] ) elif C.probeType[probeTrialNum-1] == 5: # condition 3 v 4 (W+D vs L+D) if group.randomDrawProbe == 0: player.condition = '3 v 4' group.images_left = "images/x.png" group.images_right = "images/x.png" group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[2] group.probeColorRight = C.cellColors[3] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[2]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[3]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[2], colorRight = C.cellColors[3] ) elif group.randomDrawProbe == 1: player.condition = '4 v 3' group.images_left = "images/x.png" group.images_right = "images/x.png" group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[3] group.probeColorRight = C.cellColors[2] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[2]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[3]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[3], colorRight = C.cellColors[2] ) elif C.probeType[probeTrialNum-1] == 6: #high reward vs low reward player.condition = 'none' group.images_left = C.images[0] group.images_right = C.images[3] group.probeTypeCurr = probeTypeCurrent return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format('white_' + C.images[0]), #imageRight = "images/{}.png".format('white_' + C.images[3]) imageLeft = "images/{}.png".format(C.images[0]), imageRight = "images/{}.png".format(C.images[3]) ) """ randomDrawProbe = group.randomDrawProbe images_left = group.images_left images_right = group.images_right class ProbeChoice(Page): form_model = 'player' form_fields = ['chosBandit'] #timeout_seconds = 20 @staticmethod def is_displayed(player): return C.trialType[player.round_number-1] == 0 def vars_for_template(player: Player): #player.probeRoundNum += 1 group = player.group #revert probeTrialNum = player.round_number//6 #new: #probeTrialNum = player.round_number//5 probeTypeCurrent = C.probeType[probeTrialNum-1] if C.probeType[probeTrialNum-1] == 1: # condition 1 v 3 (W+C vs W+D) #group.randomDrawProbe = random.randint(0,1) if group.randomDrawProbe == 0: player.condition = '1 v 3' group.images_left = "images/x.png" group.images_right = "images/x.png" group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[0] group.probeColorRight = C.cellColors[2] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[0]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[2]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[0], colorRight = C.cellColors[2] ) elif group.randomDrawProbe == 1: player.condition = '3 v 1' group.images_left = C.images[0] group.images_right = C.images[0] group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[2] group.probeColorRight = C.cellColors[0] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[0]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[2]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[2], colorRight = C.cellColors[0] ) elif C.probeType[probeTrialNum-1] == 2: # condition 2 v 4 (L+C vs L+D) #group.randomDrawProbe = random.randint(0,1) if group.randomDrawProbe == 0: player.condition = '2 v 4' group.images_left = "images/x.png" group.images_right = "images/x.png" group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[1] group.probeColorRight = C.cellColors[3] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[1]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[3]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[1], colorRight = C.cellColors[3] ) elif group.randomDrawProbe == 1: player.condition = '4 v 2' group.images_left = "images/x.png" group.images_right = "images/x.png" group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[3] group.probeColorRight = C.cellColors[1] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[1]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[3]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[3], colorRight = C.cellColors[1] ) #revert elif C.probeType[probeTrialNum-1] == 3: #high reward vs low reward player.condition = 'none' group.images_left = C.images[0] group.images_right = C.images[3] group.probeTypeCurr = probeTypeCurrent return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format('white_' + C.images[0]), #imageRight = "images/{}.png".format('white_' + C.images[3]) imageLeft = "images/{}.png".format(C.images[0]), imageRight = "images/{}.png".format(C.images[3]) ) #new """ if C.probeType[probeTrialNum-1] == 3: # condition 1 v 2 (W+C vs L+C) if group.randomDrawProbe == 0: player.condition = '1 v 2' group.images_left = "images/x.png" group.images_right = "images/x.png" group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[0] group.probeColorRight = C.cellColors[1] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[0]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[1]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[0], colorRight = C.cellColors[1] ) elif group.randomDrawProbe == 1: player.condition = '2 v 1' group.images_left = C.images[0] group.images_right = C.images[0] group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[1] group.probeColorRight = C.cellColors[0] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[0]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[1]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[1], colorRight = C.cellColors[0] ) elif C.probeType[probeTrialNum-1] == 4: # condition 2 v 3 (L+C vs W+D) if group.randomDrawProbe == 0: player.condition = '2 v 3' group.images_left = "images/x.png" group.images_right = "images/x.png" group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[1] group.probeColorRight = C.cellColors[2] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[1]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[2]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[1], colorRight = C.cellColors[2] ) elif group.randomDrawProbe == 1: player.condition = '3 v 2' group.images_left = "images/x.png" group.images_right = "images/x.png" group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[2] group.probeColorRight = C.cellColors[1] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[1]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[2]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[2], colorRight = C.cellColors[1] ) elif C.probeType[probeTrialNum-1] == 5: # condition 3 v 4 (W+D vs L+D) if group.randomDrawProbe == 0: player.condition = '3 v 4' group.images_left = "images/x.png" group.images_right = "images/x.png" group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[2] group.probeColorRight = C.cellColors[3] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[2]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[3]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[2], colorRight = C.cellColors[3] ) elif group.randomDrawProbe == 1: player.condition = '4 v 3' group.images_left = "images/x.png" group.images_right = "images/x.png" group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[3] group.probeColorRight = C.cellColors[2] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[2]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[3]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[3], colorRight = C.cellColors[2] ) elif C.probeType[probeTrialNum-1] == 6: #high reward vs low reward player.condition = 'none' group.images_left = C.images[0] group.images_right = C.images[3] group.probeTypeCurr = probeTypeCurrent return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format('white_' + C.images[0]), #imageRight = "images/{}.png".format('white_' + C.images[3]) imageLeft = "images/{}.png".format(C.images[0]), imageRight = "images/{}.png".format(C.images[3]) ) """ randomDrawProbe = group.randomDrawProbe images_left = group.images_left images_right = group.images_right def before_next_page(player: Player, timeout_happened): player.chosBandit = player.chosBandit class ProbeChoiceWait(WaitPage): #template_name = "multiplayer_app/ProbeChoiceWait.html" @staticmethod def is_displayed(player): return C.trialType[player.round_number-1] == 0 def vars_for_template(player): group = player.group chosBandit = player.chosBandit randomDrawProbe = group.randomDrawProbe images_left = group.images_left images_right = group.images_right probeTrialNum = player.round_number//6 #new: #probeTrialNum = player.round_number//5 probeTypeCurrent = C.probeType[probeTrialNum-1] image_avatar = "person" if C.probeType[probeTrialNum-1] == 1: # condition 1 v 3 (W+C vs W+D) if group.randomDrawProbe == 0: player.condition = '1 v 3' group.images_left = C.images[0] group.images_right = C.images[0] group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[0] group.probeColorRight = C.cellColors[2] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[0]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[2]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[0], colorRight = C.cellColors[2] ) elif group.randomDrawProbe == 1: player.condition = '3 v 1' group.images_left = C.images[0] group.images_right = C.images[0] group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[2] group.probeColorRight = C.cellColors[0] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[0]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[2]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[2], colorRight = C.cellColors[0] ) elif C.probeType[probeTrialNum-1] == 2: # condition 2 v 4 (L+C vs L+D) if group.randomDrawProbe == 0: player.condition = '2 v 4' group.images_left = "images/x.png" group.images_right = "images/x.png" group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[1] group.probeColorRight = C.cellColors[3] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[1]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[3]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[1], colorRight = C.cellColors[3] ) elif group.randomDrawProbe == 1: player.condition = '4 v 2' group.images_left = "images/x.png" group.images_right = "images/x.png" group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[3] group.probeColorRight = C.cellColors[1] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[1]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[3]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[3], colorRight = C.cellColors[1] ) #revert elif C.probeType[probeTrialNum-1] == 3: #high reward vs low reward player.condition = 'none' group.images_left = C.images[0] group.images_right = C.images[3] group.probeTypeCurr = probeTypeCurrent return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format('white_' + C.images[0]), #imageRight = "images/{}.png".format('white_' + C.images[3]) imageLeft = "images/{}.png".format(C.images[0]), imageRight = "images/{}.png".format(C.images[3]) ) #new """ if C.probeType[probeTrialNum-1] == 3: # condition 1 v 2 (W+C vs L+C) if group.randomDrawProbe == 0: player.condition = '1 v 2' group.images_left = "images/x.png" group.images_right = "images/x.png" group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[0] group.probeColorRight = C.cellColors[1] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[0]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[1]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[0], colorRight = C.cellColors[1] ) elif group.randomDrawProbe == 1: player.condition = '2 v 1' group.images_left = C.images[0] group.images_right = C.images[0] group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[1] group.probeColorRight = C.cellColors[0] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[0]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[1]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[1], colorRight = C.cellColors[0] ) elif C.probeType[probeTrialNum-1] == 4: # condition 2 v 3 (L+C vs W+D) if group.randomDrawProbe == 0: player.condition = '2 v 3' group.images_left = "images/x.png" group.images_right = "images/x.png" group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[1] group.probeColorRight = C.cellColors[2] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[1]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[2]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[1], colorRight = C.cellColors[2] ) elif group.randomDrawProbe == 1: player.condition = '3 v 2' group.images_left = "images/x.png" group.images_right = "images/x.png" group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[2] group.probeColorRight = C.cellColors[1] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[1]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[2]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[2], colorRight = C.cellColors[1] ) elif C.probeType[probeTrialNum-1] == 5: # condition 3 v 4 (W+D vs L+D) if group.randomDrawProbe == 0: player.condition = '3 v 4' group.images_left = "images/x.png" group.images_right = "images/x.png" group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[2] group.probeColorRight = C.cellColors[3] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[2]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[3]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[2], colorRight = C.cellColors[3] ) elif group.randomDrawProbe == 1: player.condition = '4 v 3' group.images_left = "images/x.png" group.images_right = "images/x.png" group.probeTypeCurr = probeTypeCurrent group.probeColorLeft = C.cellColors[3] group.probeColorRight = C.cellColors[2] return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format((C.cellColors[2]) + '_' + C.images[0]), #imageRight = "images/{}.png".format((C.cellColors[3]) + '_' + C.images[0]) imageLeft = "images/x.png", imageRight = "images/x.png", colorLeft = C.cellColors[3], colorRight = C.cellColors[2] ) elif C.probeType[probeTrialNum-1] == 6: #high reward vs low reward player.condition = 'none' group.images_left = C.images[0] group.images_right = C.images[3] group.probeTypeCurr = probeTypeCurrent return dict( avatar = "images/person.png", #imageLeft = "images/{}.png".format('white_' + C.images[0]), #imageRight = "images/{}.png".format('white_' + C.images[3]) imageLeft = "images/{}.png".format(C.images[0]), imageRight = "images/{}.png".format(C.images[3]) ) """ def js_vars(player): return dict( chosBandit=player.chosBandit #socialLocation = player.socialLocation ) def before_next_page(player: Player, timeout_happened): player.chosBandit = player.chosBandit class PlayersArriveWait(WaitPage): @staticmethod def is_displayed(player): player.round_number == 1 body_text = """ Please wait and do not leave this page. If you are not matched into a group after 10 minutes, you will leave this page automatically. """ group_by_arrival_time = True class Fixation(Page): form_model = 'player' timeout_seconds = 1 @staticmethod def is_displayed(player): return C.trialType[player.round_number-1] == 1 def vars_for_template(player: Player): rewardLevel = C.rewardLevel group = player.group if rewardLevel[player.round_number-1] == 1: #high group.randomDraw = random.randint(0,1) group.images_left = C.images[group.randomDraw] group.rewardLev = rewardLevel[player.round_number-1] if group.randomDraw == 0: group.images_right = C.images[1] elif group.randomDraw == 1: group.images_right = C.images[0] print(group.randomDraw) print(group.images_left, group.images_right) elif rewardLevel[player.round_number-1] == 0: group.randomDraw = random.randint(2,3) group.images_left = C.images[group.randomDraw] group.rewardLev = rewardLevel[player.round_number-1] if group.randomDraw == 2: group.images_right = C.images[3] elif group.randomDraw == 3: group.images_right = C.images[2] print(group.randomDraw) print(group.images_left, group.images_right) group.images_left = group.images_left group.images_right = group.images_right return dict( # imageLeft = "images/{}.png".format(cellColors[currentCondition[0]] + '_' + imagesInit[currImgLeft]) # imageRight = "images/{}.png".format(cellColors[currentCondition[0]] + '_' + imagesInit[currImgRight]) #imageLeft = "images/{}.png".format("white_" + group.images_left), #imageRight = "images/{}.png".format("white_" + group.images_right), imageLeft = "images/{}.png".format(group.images_left), imageRight = "images/{}.png".format(group.images_right), ) class Choice(Page): form_model = 'player' form_fields = ['chosBandit'] #timeout_seconds = 20 @staticmethod def is_displayed(player): return C.trialType[player.round_number-1] == 1 def vars_for_template(player: Player): #player.normalRoundNum += 1 rewardLevel = C.rewardLevel group = player.group colorArray = C.cellColors group.colors = ','.join(colorArray) # if rewardLevel[player.round_number-1] == 1: #high # group.randomDraw = random.randint(0,1) # group.images_left = C.images[group.randomDraw] # if group.randomDraw == 0: # group.images_right = C.images[1] # elif group.randomDraw == 1: # group.images_right = C.images[0] # print(group.randomDraw) # print(group.images_left, group.images_right) # # elif rewardLevel[player.round_number-1] == 0: # group.randomDraw = random.randint(2,3) # group.images_left = C.images[group.randomDraw] # if group.randomDraw == 2: # group.images_right = C.images[3] # elif group.randomDraw == 3: # group.images_right = C.images[2] # print(group.randomDraw) # print(group.images_left, group.images_right) images_left = group.images_left images_right = group.images_right print('POST', group.randomDraw) print('POST', group.images_left, group.images_right) image_avatar = "person" cellColors = C.cellColors return dict( #imageLeft = "images/{}.png".format("white_" + group.images_left), #imageRight = "images/{}.png".format("white_" + group.images_right), imageLeft = "images/{}.png".format(group.images_left), imageRight = "images/{}.png".format(group.images_right), avatar = "images/{}.png".format(image_avatar) ) player.chosBandit = player.chosBandit def before_next_page(player: Player, timeout_happened): player.chosBandit = player.chosBandit class ChoiceWait(WaitPage): template_name = 'multiplayer_app/ChoiceWait.html' @staticmethod def is_displayed(player): return C.trialType[player.round_number-1] == 1 def vars_for_template(player): group = player.group chosBandit = player.chosBandit images_left = group.images_left images_right = group.images_right rewardLevel = C.rewardLevel group.rewardLev = rewardLevel[player.round_number-1] if rewardLevel[player.round_number-1] == 1: #high group.reward_left = abs(round(random.gauss(450, 150) / 100, 2)) group.reward_right = abs(round(random.gauss(450, 150) / 100, 2)) reward_left_string = str("%.2f" % group.reward_left) reward_right_string = str("%.2f" % group.reward_right) group.reward_left_string = reward_left_string group.reward_right_string = reward_right_string if group.reward_left == group.reward_right: group.reward_left = group.reward_left + 1 elif rewardLevel[player.round_number-1] == 0: group.reward_left = abs(round(random.gauss(200, 150) / 100, 2)) group.reward_right = abs(round(random.gauss(200, 150) / 100, 2)) reward_left_string = str("%.2f" % group.reward_left) reward_right_string = str("%.2f" % group.reward_right) group.reward_left_string = reward_left_string group.reward_right_string = reward_right_string if group.reward_left == group.reward_right: group.reward_right = group.reward_right + 1 reward_left = group.reward_left reward_right = group.reward_right #socialLocation = player.socialLocation image_avatar = "person" return dict( # imageLeft = "images/{}.png".format(cellColors[currentCondition[0]] + '_' + imagesInit[currImgLeft]) # imageRight = "images/{}.png".format(cellColors[currentCondition[0]] + '_' + imagesInit[currImgRight]) #imageLeft = "images/{}.png".format("white_" + group.images_left), #imageRight = "images/{}.png".format("white_" + group.images_right), imageLeft = "images/{}.png".format(group.images_left), imageRight = "images/{}.png".format(group.images_right), avatar = "images/{}.png".format(image_avatar) ) def js_vars(player): return dict( chosBandit=player.chosBandit #socialLocation = player.socialLocation ) def after_all_players_arrive(group: Group): player_lists = group.get_players() player1 = player_lists[0] player2 = player_lists[1] player3 = player_lists[2] if player1.chosBandit == "37": # make chose_left a function = models.BooleanField() that returns true if player 1 chose left if player2.chosBandit == "37": if player3.chosBandit == "37": # 1,2,3 v player1.payoff = C.payoffFullCons player2.payoff = C.payoffFullCons player3.payoff = C.payoffFullCons player1.socialLocation = "left" # left player2.socialLocation = "left" player3.socialLocation = "left" group.fullConsensus = True player1.placement = "1" # LLL player2.placement = "1" # LLL player3.placement = "1" # LLL elif player3.chosBandit == "39": # 1,2 v 3 player1.payoff = C.payoffHalfCons player2.payoff = C.payoffHalfCons player3.payoff = C.payoffDiss player1.socialLocation = "left" player2.socialLocation = "left" player3.socialLocation = "right" # right group.fullConsensus = False player1.placement = "2" # LLR player2.placement = "2" # LLR player3.placement = "2" # LLR elif player2.chosBandit == "39": if player3.chosBandit == "37": # 1,3 v 2 player1.payoff = C.payoffHalfCons player2.payoff = C.payoffDiss player3.payoff = C.payoffHalfCons player1.socialLocation = "left" player2.socialLocation = "right" player3.socialLocation = "left" group.fullConsensus = False player1.placement = "3" # LRL player2.placement = "3" # LRL player3.placement = "3" # LRL elif player3.chosBandit == "39": # 1 v 2,3 player1.payoff = C.payoffDiss player2.payoff = C.payoffHalfCons player3.payoff = C.payoffHalfCons player1.socialLocation = "left" player2.socialLocation = "right" player3.socialLocation = "right" group.fullConsensus = False player1.placement = "4" # LRR player2.placement = "4" # LRR player3.placement = "4" # LRR elif player1.chosBandit == "39": if player2.chosBandit == "37": if player3.chosBandit == "37": # 2,3 v 1 player1.payoff = C.payoffDiss player2.payoff = C.payoffHalfCons player3.payoff = C.payoffHalfCons player1.socialLocation = "right" player2.socialLocation = "left" player3.socialLocation = "left" group.fullConsensus = False player1.placement = "5" # RLL player2.placement = "5" # RLL player3.placement = "5" # RLL elif player3.chosBandit == "39": # 2 v 1,3 player1.payoff = C.payoffHalfCons player2.payoff = C.payoffDiss player3.payoff = C.payoffHalfCons player1.socialLocation = "right" player2.socialLocation = "left" player3.socialLocation = "right" group.fullConsensus = False player1.placement = "6" # RLR player2.placement = "6" # RLR player3.placement = "6" # RLR elif player2.chosBandit == "39": if player3.chosBandit == "37": # 3 v 1,2 player1.payoff = C.payoffHalfCons player2.payoff = C.payoffHalfCons player3.payoff = C.payoffDiss player1.socialLocation = "right" player2.socialLocation = "right" player3.socialLocation = "left" group.fullConsensus = False player1.placement = "7" # RRL player2.placement = "7" # RRL player3.placement = "7" # RRL elif player3.chosBandit == "39": # v 1,2,3 player1.payoff = C.payoffFullCons player2.payoff = C.payoffFullCons player3.payoff = C.payoffFullCons player1.socialLocation = "right" player2.socialLocation = "right" player3.socialLocation = "right" group.fullConsensus = True player1.placement = "8" # RRR player2.placement = "8" # RRR player3.placement = "8" # RRR #group.reward_left = round(random.gauss(500, 20) / 100, 2) #group.reward_right = round(random.gauss(500, 20) / 100, 2) def before_next_page(player: Player, timeout_happened): player.chosBandit = player.chosBandit, player.socialLocation = player.socialLocation, player.placement = player.placement class DetermineRew(Page): form_model = 'player' form_fields = ['chosBandit'] timeout_seconds = .001 @staticmethod def vars_for_template(player: Player): group = player.group rewardLevel = C.rewardLevel group.rewardLev = rewardLevel[player.round_number-1] if rewardLevel[player.round_number-1] == 1: #high group.reward_left = abs(round(random.gauss(450, 150) / 100, 2)) group.reward_right = abs(round(random.gauss(450, 150) / 100, 2)) reward_left_string = str("%.2f" % group.reward_left) reward_right_string = str("%.2f" % group.reward_right) group.reward_left_string = reward_left_string group.reward_right_string = reward_right_string if group.reward_left == group.reward_right: group.reward_left = group.reward_left + 1 elif rewardLevel[player.round_number-1] == 0: group.reward_left = abs(round(random.gauss(200, 150) / 100, 2)) group.reward_right = abs(round(random.gauss(200, 150) / 100, 2)) reward_left_string = str("%.2f" % group.reward_left) reward_right_string = str("%.2f" % group.reward_right) group.reward_left_string = reward_left_string group.reward_right_string = reward_right_string if group.reward_left == group.reward_right: group.reward_right = group.reward_right + 1 reward_left = group.reward_left reward_right = group.reward_right class SelectReveal(Page): form_model = 'player' form_fields = ['chosBandit'] timeout_seconds = 1 @staticmethod def is_displayed(player): return C.trialType[player.round_number-1] == 1 def vars_for_template(player: Player): group = player.group chosBandit = player.chosBandit images_left = group.images_left images_right = group.images_right rewardLevel = C.rewardLevel group.rewardLev = rewardLevel[player.round_number-1] #socialLocation = player.socialLocation image_avatar = "person" if player.chosBandit == "37": if group.reward_left > group.reward_right: player.rewardWin = True elif group.reward_left < group.reward_right: player.rewardWin = False elif player.chosBandit == "39": if group.reward_left < group.reward_right: player.rewardWin = True elif group.reward_left > group.reward_right: player.rewardWin = False return dict( # imageLeft = "images/{}.png".format(cellColors[currentCondition[0]] + '_' + imagesInit[currImgLeft]) # imageRight = "images/{}.png".format(cellColors[currentCondition[0]] + '_' + imagesInit[currImgRight]) #imageLeft = "images/{}.png".format("white_" + group.images_left), #imageRight = "images/{}.png".format("white_" + group.images_right), imageLeft = "images/{}.png".format(group.images_left), imageRight = "images/{}.png".format(group.images_right), avatar = "images/{}.png".format(image_avatar) ) def js_vars(player): return dict( chosBandit=player.chosBandit #socialLocation = player.socialLocation ) def before_next_page(player: Player, timeout_happened): player.chosBandit = player.chosBandit class SocialReveal(Page): form_model = 'player' form_fields = ['chosBandit'] timeout_seconds = 1 @staticmethod def is_displayed(player): return C.trialType[player.round_number-1] == 1 def vars_for_template(player: Player): group = player.group chosBandit = player.chosBandit players = group.get_players() others = player.get_others_in_group() images_left = group.images_left images_right = group.images_right image_avatar = "person" player1_name = players[0].participant.name player2_name = players[1].participant.name player3_name = players[2].participant.name print(player3_name) player.player1_name = player1_name player.player2_name = player2_name player.player3_name = player3_name if player.rewardWin == True: if player.payoff == 0: player.condition = '3' player.colorLeft = C.cellColors[2] player.colorRight = C.cellColors[2] return dict( #imageLeft = "images/{}.png".format((C.cellColors[2]) + '_' + group.images_left), #imageRight = "images/{}.png".format((C.cellColors[2]) + '_' + group.images_right), imageLeft = "images/{}.png".format(group.images_left), imageRight = "images/{}.png".format(group.images_right), colorLeft = C.cellColors[2], colorRight = C.cellColors[2], avatar = "images/{}.png".format(image_avatar) ) else: if group.fullConsensus == 1: player.condition = '1' player.colorLeft = C.cellColors[0] player.colorRight = C.cellColors[0] return dict( #imageLeft = "images/{}.png".format((C.cellColors[0]) + '_' + group.images_left), #imageRight = "images/{}.png".format((C.cellColors[0]) + '_' + group.images_right), imageLeft = "images/{}.png".format(group.images_left), imageRight = "images/{}.png".format(group.images_right), colorLeft = C.cellColors[0], colorRight = C.cellColors[0], avatar = "images/{}.png".format(image_avatar) ) else: player.condition = '1_partial' player.colorLeft = C.cellColors[4] player.colorRight = C.cellColors[4] return dict( #imageLeft = "images/{}.png".format((C.cellColors[0]) + '_' + group.images_left), #imageRight = "images/{}.png".format((C.cellColors[0]) + '_' + group.images_right), imageLeft = "images/{}.png".format(group.images_left), imageRight = "images/{}.png".format(group.images_right), colorLeft = C.cellColors[4], colorRight = C.cellColors[4], avatar = "images/{}.png".format(image_avatar) ) elif player.rewardWin == False: if player.payoff == 0: player.condition = '4' player.colorLeft = C.cellColors[3] player.colorRight = C.cellColors[3] return dict( #imageLeft = "images/{}.png".format((C.cellColors[3]) + '_' + group.images_left), #imageRight = "images/{}.png".format((C.cellColors[3]) + '_' + group.images_right), imageLeft = "images/{}.png".format(group.images_left), imageRight = "images/{}.png".format(group.images_right), colorLeft = C.cellColors[3], colorRight = C.cellColors[3], avatar = "images/{}.png".format(image_avatar) ) else: if group.fullConsensus == 1: player.condition = '2' player.colorLeft = C.cellColors[1] player.colorRight = C.cellColors[1] return dict( #imageLeft = "images/{}.png".format((C.cellColors[1]) + '_' + group.images_left), #imageRight = "images/{}.png".format((C.cellColors[1]) + '_' + group.images_right), imageLeft = "images/{}.png".format(group.images_left), imageRight = "images/{}.png".format(group.images_right), colorLeft = C.cellColors[1], colorRight = C.cellColors[1], avatar = "images/{}.png".format(image_avatar) ) else: player.condition = '2_partial' player.colorLeft = C.cellColors[5] player.colorRight = C.cellColors[5] return dict( #imageLeft = "images/{}.png".format((C.cellColors[0]) + '_' + group.images_left), #imageRight = "images/{}.png".format((C.cellColors[0]) + '_' + group.images_right), imageLeft = "images/{}.png".format(group.images_left), imageRight = "images/{}.png".format(group.images_right), colorLeft = C.cellColors[5], colorRight = C.cellColors[5], avatar = "images/{}.png".format(image_avatar) ) return dict( avatar = "images/{}.png".format(image_avatar), avatar_2 = "images/{}.png".format(image_avatar), avatar_3 = "images/{}.png".format(image_avatar) ) player.chosBandit = chosBandit reward_left_string = str("%.2f" % group.reward_left) reward_right_string = str("%.2f" % group.reward_right) group.reward_left_string = reward_left_string group.reward_right_string = reward_right_string def js_vars(player): return dict( chosBandit=player.chosBandit, placement = player.placement, playerid = player.id_in_group, name = player.participant.name ) def before_next_page(player: Player, timeout_happened): player.chosBandit = player.chosBandit class ConditionReveal(Page): form_model = 'player' form_fields = ['chosBandit'] timeout_seconds = 2 @staticmethod def is_displayed(player): return C.trialType[player.round_number-1] == 1 def vars_for_template(player: Player): group = player.group reward_left = group.reward_left reward_right = group.reward_right reward_left_string = str(group.reward_left) reward_right_string = str(group.reward_right) #socialLocation = player.socialLocation image_avatar = "person" images_left = group.images_left images_right = group.images_right players = group.get_players() others = player.get_others_in_group() images_left = group.images_left images_right = group.images_right image_avatar = "person" player1_name = players[0].participant.name player2_name = players[1].participant.name player3_name = players[2].participant.name print(player3_name) player.player1_name = player1_name player.player2_name = player2_name player.player3_name = player3_name #cellColor = session.config.cellColors #icon_image = session.config.images if player.rewardWin == True: if player.payoff == 0: player.condition = '3' player.colorLeft = C.cellColors[2] player.colorRight = C.cellColors[2] return dict( #imageLeft = "images/{}.png".format((C.cellColors[2]) + '_' + group.images_left), #imageRight = "images/{}.png".format((C.cellColors[2]) + '_' + group.images_right), imageLeft = "images/{}.png".format(group.images_left), imageRight = "images/{}.png".format(group.images_right), colorLeft = C.cellColors[2], colorRight = C.cellColors[2], avatar = "images/{}.png".format(image_avatar) ) else: if group.fullConsensus == 1: player.condition = '1' player.colorLeft = C.cellColors[0] player.colorRight = C.cellColors[0] return dict( #imageLeft = "images/{}.png".format((C.cellColors[0]) + '_' + group.images_left), #imageRight = "images/{}.png".format((C.cellColors[0]) + '_' + group.images_right), imageLeft = "images/{}.png".format(group.images_left), imageRight = "images/{}.png".format(group.images_right), colorLeft = C.cellColors[0], colorRight = C.cellColors[0], avatar = "images/{}.png".format(image_avatar) ) else: player.condition = '1_partial' player.colorLeft = C.cellColors[4] player.colorRight = C.cellColors[4] return dict( #imageLeft = "images/{}.png".format((C.cellColors[0]) + '_' + group.images_left), #imageRight = "images/{}.png".format((C.cellColors[0]) + '_' + group.images_right), imageLeft = "images/{}.png".format(group.images_left), imageRight = "images/{}.png".format(group.images_right), colorLeft = C.cellColors[4], colorRight = C.cellColors[4], avatar = "images/{}.png".format(image_avatar) ) elif player.rewardWin == False: if player.payoff == 0: player.condition = '4' player.colorLeft = C.cellColors[3] player.colorRight = C.cellColors[3] return dict( #imageLeft = "images/{}.png".format((C.cellColors[3]) + '_' + group.images_left), #imageRight = "images/{}.png".format((C.cellColors[3]) + '_' + group.images_right), imageLeft = "images/{}.png".format(group.images_left), imageRight = "images/{}.png".format(group.images_right), colorLeft = C.cellColors[3], colorRight = C.cellColors[3], avatar = "images/{}.png".format(image_avatar) ) else: if group.fullConsensus == 1: player.condition = '2' player.colorLeft = C.cellColors[1] player.colorRight = C.cellColors[1] return dict( #imageLeft = "images/{}.png".format((C.cellColors[1]) + '_' + group.images_left), #imageRight = "images/{}.png".format((C.cellColors[1]) + '_' + group.images_right), imageLeft = "images/{}.png".format(group.images_left), imageRight = "images/{}.png".format(group.images_right), colorLeft = C.cellColors[1], colorRight = C.cellColors[1], avatar = "images/{}.png".format(image_avatar) ) else: player.condition = '2_partial' player.colorLeft = C.cellColors[5] player.colorRight = C.cellColors[5] return dict( #imageLeft = "images/{}.png".format((C.cellColors[0]) + '_' + group.images_left), #imageRight = "images/{}.png".format((C.cellColors[0]) + '_' + group.images_right), imageLeft = "images/{}.png".format(group.images_left), imageRight = "images/{}.png".format(group.images_right), colorLeft = C.cellColors[5], colorRight = C.cellColors[5], avatar = "images/{}.png".format(image_avatar) ) return dict( avatar = "images/{}.png".format(image_avatar), avatar_2 = "images/{}.png".format(image_avatar), avatar_3 = "images/{}.png".format(image_avatar) ) if player.chosBandit == "37": if group.reward_left > group.reward_right: group.reward_right = 0 elif group.reward_left < group.reward_right: group.reward_left = 0 elif player.chosBandit == "39": if group.reward_left < group.reward_right: group.reward_left = 0 elif group.reward_left > group.reward_right: group.reward_right = 0 reward_left_string = str("%.2f" % group.reward_left) reward_right_string = str("%.2f" % group.reward_right) group.reward_left_string = reward_left_string group.reward_right_string = reward_right_string def js_vars(player): return dict( chosBandit=player.chosBandit, cellColors = C.cellColors, placement = player.placement, playerid = player.id_in_group, name = player.participant.name #socialLocation = player.socialLocation ) def before_next_page(player: Player, timeout_happened): player.chosBandit = player.chosBandit #player.socialLocation = player.socialLocation class RewardReveal(Page): form_model = 'player' form_fields = ['chosBandit'] timeout_seconds = 3 @staticmethod def is_displayed(player): return C.trialType[player.round_number-1] == 1 def vars_for_template(player: Player): group = player.group chosBandit = player.chosBandit image_avatar = "person" images_left = group.images_left images_right = group.images_right players = group.get_players() others = player.get_others_in_group() images_left = group.images_left images_right = group.images_right image_avatar = "person" player1_name = players[0].participant.name player2_name = players[1].participant.name player3_name = players[2].participant.name print(player3_name) player.player1_name = player1_name player.player2_name = player2_name player.player3_name = player3_name if player.rewardWin == True: if player.payoff == 0: player.condition = '3' player.colorLeft = C.cellColors[2] player.colorRight = C.cellColors[2] return dict( #imageLeft = "images/{}.png".format((C.cellColors[2]) + '_' + group.images_left), #imageRight = "images/{}.png".format((C.cellColors[2]) + '_' + group.images_right), imageLeft = "images/{}.png".format(group.images_left), imageRight = "images/{}.png".format(group.images_right), colorLeft = C.cellColors[2], colorRight = C.cellColors[2], avatar = "images/{}.png".format(image_avatar) ) else: if group.fullConsensus == 1: player.condition = '1' player.colorLeft = C.cellColors[0] player.colorRight = C.cellColors[0] return dict( #imageLeft = "images/{}.png".format((C.cellColors[0]) + '_' + group.images_left), #imageRight = "images/{}.png".format((C.cellColors[0]) + '_' + group.images_right), imageLeft = "images/{}.png".format(group.images_left), imageRight = "images/{}.png".format(group.images_right), colorLeft = C.cellColors[0], colorRight = C.cellColors[0], avatar = "images/{}.png".format(image_avatar) ) else: player.condition = '1_partial' player.colorLeft = C.cellColors[4] player.colorRight = C.cellColors[4] return dict( #imageLeft = "images/{}.png".format((C.cellColors[0]) + '_' + group.images_left), #imageRight = "images/{}.png".format((C.cellColors[0]) + '_' + group.images_right), imageLeft = "images/{}.png".format(group.images_left), imageRight = "images/{}.png".format(group.images_right), colorLeft = C.cellColors[4], colorRight = C.cellColors[4], avatar = "images/{}.png".format(image_avatar) ) elif player.rewardWin == False: if player.payoff == 0: player.condition = '4' player.colorLeft = C.cellColors[3] player.colorRight = C.cellColors[3] return dict( #imageLeft = "images/{}.png".format((C.cellColors[3]) + '_' + group.images_left), #imageRight = "images/{}.png".format((C.cellColors[3]) + '_' + group.images_right), imageLeft = "images/{}.png".format(group.images_left), imageRight = "images/{}.png".format(group.images_right), colorLeft = C.cellColors[3], colorRight = C.cellColors[3], avatar = "images/{}.png".format(image_avatar) ) else: if group.fullConsensus == 1: player.condition = '2' player.colorLeft = C.cellColors[1] player.colorRight = C.cellColors[1] return dict( #imageLeft = "images/{}.png".format((C.cellColors[1]) + '_' + group.images_left), #imageRight = "images/{}.png".format((C.cellColors[1]) + '_' + group.images_right), imageLeft = "images/{}.png".format(group.images_left), imageRight = "images/{}.png".format(group.images_right), colorLeft = C.cellColors[1], colorRight = C.cellColors[1], avatar = "images/{}.png".format(image_avatar) ) else: player.condition = '2_partial' player.colorLeft = C.cellColors[5] player.colorRight = C.cellColors[5] return dict( #imageLeft = "images/{}.png".format((C.cellColors[0]) + '_' + group.images_left), #imageRight = "images/{}.png".format((C.cellColors[0]) + '_' + group.images_right), imageLeft = "images/{}.png".format(group.images_left), imageRight = "images/{}.png".format(group.images_right), colorLeft = C.cellColors[5], colorRight = C.cellColors[5], avatar = "images/{}.png".format(image_avatar) ) if player.chosBandit == "37": if group.reward_left > group.reward_right: group.reward_right = 0 elif group.reward_left < group.reward_right: group.reward_left = 0 elif player.chosBandit == "39": if group.reward_left < group.reward_right: group.reward_left = 0 elif group.reward_left > group.reward_right: group.reward_right = 0 reward_left_string = str("%.2f" % group.reward_left) reward_right_string = str("%.2f" % group.reward_right) group.reward_left_string = reward_left_string group.reward_right_string = reward_right_string def js_vars(player): return dict( chosBandit=player.chosBandit, placement = player.placement, playerid = player.id_in_group, name = player.participant.name ) def before_next_page(player: Player, timeout_happened): player.chosBandit = player.chosBandit #player.socialLocation = player.socialLocation class PostRating(Page): form_model = 'player' form_fields = ['chosBandit'] @staticmethod def vars_for_template(player: Player): group = player.group class PostRatingWait(WaitPage): pass class Debrief(Page): # after_all_players_arrive = move_to_next_slide() pass class ThankYou(Page): # after_all_players_arrive = move_to_next_slide() pass page_sequence = [PlayersArriveWait, FixationProbe, ProbeChoice, ProbeChoiceWait, Fixation, Choice, ChoiceWait, SelectReveal, SocialReveal, ConditionReveal, RewardReveal] def custom_export(players): #header row yield ['participantSessionId', 'participantNum', 'roundNum', 'payoffCons', 'choice', 'groupFullCons', 'rewardWin', 'condition','rewardLeft', 'rewardRight', 'imageLeft', 'imageRight', 'rewardLevel', 'ProbeType', "colors"] #have: session id, otree id, prerating choices, round number, consensus level, choice, binary full consensus, binary reward win, condition, # reward left, reward right, image left, image right, postrating choices # still need: # trial icon id - done! # whether normal or probe - done! # round condition color # probe condition number # demographics #now, data rows: for p in players: participant = p.participant #player = p.player session = p.session subsession = p.subsession group = p.group #put all variable names in the following list, including class, for ex: participant.choice, session.cellColors, group.rewardLeft yield [participant.id_in_session, participant.code, subsession.round_number, p.payoff, p.chosBandit, group.fullConsensus, p.rewardWin, p.condition, group.reward_left, group.reward_right, group.images_left, group.images_right, group.rewardLev, group.probeTypeCurr, group.colors]