from otree.api import * c = cu doc = '' class C(BaseConstants): NAME_IN_URL = 'judgement' PLAYERS_PER_GROUP = None NUM_ROUNDS = 40 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass def storymaker_g(group: Group): import random players=group.get_players() for p in players: trip_x=p.participant.vars['triplets'] trip_y=p.participant.vars['labels'] tripzip=zip(trip_x,trip_y) tripzipprime=[x for x in tripzip] selection=random.choice(tripzipprime) tmp=list(zip(selection[0],selection[1])) random.shuffle(tmp) p.Story1=tmp[0][0] p.Story2=tmp[1][0] p.Story3=tmp[2][0] p.Label1=tmp[0][1] p.Label2=tmp[1][1] p.Label3=tmp[2][1] Group.storymaker_g = storymaker_g class Player(BasePlayer): Choice = models.IntegerField(choices=[[1, 'Story 1'], [2, 'Story 2'], [3, 'Story 3']], widget=widgets.RadioSelect) Story1 = models.LongStringField() Story2 = models.LongStringField() Story3 = models.LongStringField() Slot = models.IntegerField() Deceived = models.IntegerField() Target = models.IntegerField() Reward = models.CurrencyField(initial=5) Confidence = models.IntegerField(choices=[[1, 'Just guessing'], [2, 'Somewhat confident'], [3, 'Reasonably confident'], [4, 'Certain']], label='', widget=widgets.RadioSelect) Feedback = models.LongStringField(blank=True, label='') AttentionCheck = models.BooleanField(initial=False) def storymaker(player: Player): participant = player.participant import random trip_x=player.participant.vars['triplets'] trip_y=player.participant.vars['labels'] tripzip=zip(trip_x,trip_y) tripzipprime=[x for x in tripzip] player.Slot=random.choice(range(len(tripzipprime))) selection=tripzipprime[player.round_number - 1] tmp=list(zip(selection[0],selection[1])) random.shuffle(tmp) tarlist=[tmp[0][1],tmp[1][1],tmp[2][1]] player.Target=tarlist.index(max(tarlist))+1 player.Story1=tmp[0][0] player.Story2=tmp[1][0] player.Story3=tmp[2][0] def get_triplets(player: Player): import csv import os rawdata=[] all_files=os.listdir('csv_experiments') for file in all_files: with open('csv_experiments/'+file, newline='') as f: reader=csv.reader(f) subdata=[] for row in reader: subdata.append(row) rawdata.append(subdata) triplets=[] for datum in rawdata: header=datum[0] for i in range(1, len(datum)): for j in range(len(datum[i])): triplet=[] if header[j][-6:]=='Truth1' and datum[i][j] != '' and datum[i][j+1] != '' and datum[i][j+2] != '': triplet.append(datum[i][j]) triplet.append(datum[i][j+1]) triplet.append(datum[i][j+2]) triplets.append(triplet) triplet=[] labels=[[0,0,1]]*len(triplets) player.triplets=triplets player.triplabs=labels Player.storymaker = storymaker Player.get_triplets = get_triplets class TakeJudgements(Page): form_model = 'player' form_fields = ['Choice', 'Confidence', 'Feedback'] @staticmethod def vars_for_template(player: Player): session = player.session subsession = player.subsession storymaker(player) if subsession.round_number == 8: player.Target = 2 player.Story1="I graduated high school." player.Story2="For my middle school science fair, I built a time machine and went back to kill the dinosaurs." player.Story3="I wear shirts." return dict( s1="I graduated high school.", s2="For my middle school science fair, I built a time machine and went back to kill the dinosaurs.", s3="I wear shirts.", ) elif subsession.round_number == 17: player.Target = 3 player.Story1="My house has doors." player.Story2="At some point in the past, I ate breakfast. And then later, I ate more stuff." player.Story3="I was the first man on the moon. Not Neal Armstrong. Me." return dict( s1="My house has doors.", s2="At some point in the past, I ate breakfast. And then later, I ate more stuff.", s3="I was the first man on the moon. Not Neal Armstrong. Me.", ) elif subsession.round_number == 33: player.Target = 3 player.Story1="I typed this on a keyboard." player.Story2="Normally I sleep for less than 30 hours at a time." player.Story3="I'm not actually a human. I'm a sentient lion that learned to type, and one day I will have revenge on the scientists that created me." return dict( s1="I typed this on a keyboard.", s2="Normally I sleep for less than 30 hours at a time.", s3="I'm not actually a human. I'm a sentient lion that learned to type, and one day I will have revenge on the scientists that created me.", ) else: return dict( s1=player.Story1, s2=player.Story2, s3=player.Story3, ) @staticmethod def before_next_page(player: Player, timeout_happened): participant = player.participant if player.Choice == player.Target: player.Deceived=0 player.Reward += 1 player.payoff=.5 player.participant.vars['points'] += 1 else: player.Deceived=1 class Feedback(Page): form_model = 'player' @staticmethod def vars_for_template(player: Player): session = player.session subsession = player.subsession if player.Deceived == 1: if subsession.round_number==8 or subsession.round_number==17 or subsession.round_number==33: player.AttentionCheck=True return dict(gotit=0) else: return dict(gotit=1) class Attention(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): if player.AttentionCheck==True: return False else: return False @staticmethod def app_after_this_page(player: Player, upcoming_apps): return upcoming_apps[0] page_sequence = [TakeJudgements, Feedback, Attention]