from otree.api import * c = cu doc = "Here instead of swiping boxes, the subject taps left or right side buttons to 'open and continue' or 'stop'" class C(BaseConstants): # built-in constants NAME_IN_URL = 'columbiacardtask_none' PLAYERS_PER_GROUP = None NUM_ROUNDS = 56 # user-defined constants BASELINEROUNDS = 0 BOXES = 32 LOSSCARDS = (1, 2, 3) GAINAMOUNTS = (10, 10, 10, 20, 20, 20, 30, 30, 30) LOSSAMOUNTS = (250, 250, 250, 250, 250, 250, 250, 250, 250, 500, 500, 500, 500, 500, 500, 500, 500, 500, 750, 750, 750, 750, 750, 750, 750, 750, 750) NFCLONG = 0 ICECREAMLENGTH = 5 class Subsession(BaseSubsession): pass def creating_session(subsession: Subsession): session = subsession.session # https://otree.readthedocs.io/en/latest/treatments.html#creating-session if subsession.round_number == 1: import itertools import random # create 5 different random orderings (minus 2 because there are 2 extra practice rounds) indices1 = [i for i in range(1,C.NUM_ROUNDS-2-C.BASELINEROUNDS+1)] random.shuffle(indices1) indices2 = [i for i in range(1,C.NUM_ROUNDS-2-C.BASELINEROUNDS+1)] random.shuffle(indices2) indices3 = [i for i in range(1,C.NUM_ROUNDS-2-C.BASELINEROUNDS+1)] random.shuffle(indices3) indices4 = [i for i in range(1,C.NUM_ROUNDS-2-C.BASELINEROUNDS+1)] random.shuffle(indices4) indices5 = [i for i in range(1,C.NUM_ROUNDS-2-C.BASELINEROUNDS+1)] random.shuffle(indices5) # cycle the players between the random orderings index_cycle = itertools.cycle([indices1,indices2,indices3,indices4,indices5]) for player in subsession.get_players(): participant = player.participant participant.indexlist = next(index_cycle) class Group(BaseGroup): pass class Player(BasePlayer): chosencard = models.IntegerField(initial=0) endedinloss = models.BooleanField() stopped = models.IntegerField(initial=0) profit = models.IntegerField() roundlosscards = models.IntegerField() firstlosscard = models.IntegerField() roundgain = models.IntegerField() roundloss = models.IntegerField() losscardlist = models.StringField() dectimes = models.StringField(initial='') computer_randomround1 = models.IntegerField() computer_randomround2 = models.IntegerField() randomprofit1 = models.IntegerField() randomprofit2 = models.IntegerField() reward = models.FloatField() dohmen = models.IntegerField(choices=[[1, '1 = not at all willing to take risks'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8'], [9, '9'], [10, '10 = very willing to take risks']], widget=widgets.RadioSelect) nfcscore = models.IntegerField() nfcall = models.StringField() ace1 = models.StringField(choices=[['Yes', 'Yes'], ['No', 'No']], label='Emotional abuse', widget=widgets.RadioSelect) ace2 = models.StringField(choices=[['Yes', 'Yes'], ['No', 'No']], label='Physical abuse', widget=widgets.RadioSelect) ace3 = models.StringField(choices=[['Yes', 'Yes'], ['No', 'No']], label='Sexual abuse', widget=widgets.RadioSelect) ace4 = models.StringField(choices=[['Yes', 'Yes'], ['No', 'No']], label='Physical neglect', widget=widgets.RadioSelect) ace5 = models.StringField(choices=[['Yes', 'Yes'], ['No', 'No']], label='Emotional neglect', widget=widgets.RadioSelect) ace6 = models.StringField(choices=[['Yes', 'Yes'], ['No', 'No']], label='Household mental illness', widget=widgets.RadioSelect) ace7 = models.StringField(choices=[['Yes', 'Yes'], ['No', 'No']], label='Prison', widget=widgets.RadioSelect) ace8 = models.StringField(choices=[['Yes', 'Yes'], ['No', 'No']], label='Divorce', widget=widgets.RadioSelect) ace9 = models.StringField(choices=[['Yes', 'Yes'], ['No', 'No']], label='Parents always arguing', widget=widgets.RadioSelect) ace10 = models.StringField(choices=[['Yes', 'Yes'], ['No', 'No']], label='Drugs', widget=widgets.RadioSelect) affectbased = models.IntegerField(choices=[[1, '1 = Strongly disagree'], [2, '2 = Moderately disagree'], [3, '3 = Slightly disagree'], [4, '4 = Slightly agree'], [5, '5 = Moderately agree'], [6, '6 = Strongly agree']], label='
I solved the task on a gut level
', widget=widgets.RadioSelect) deliberative = models.IntegerField(choices=[[1, '1 = Strongly disagree'], [2, '2 = Moderately disagree'], [3, '3 = Slightly disagree'], [4, '4 = Slightly agree'], [5, '5 = Moderately agree'], [6, '6 = Strongly agree']], label='I tried to solve the task mathematically
', widget=widgets.RadioSelect) checkup1 = models.StringField(choices=[['1', 'Points earned from two randomly chosen rounds'], ['3', 'Points earned from half of the rounds'], ['2', 'Points earned from all rounds']], label='My bonus payments for the study consist of ...
', widget=widgets.RadioSelect) checkup2 = models.StringField(choices=[['1', 'True'], ['2', 'False']], label='The number of loss boxes changes from round to another
', widget=widgets.RadioSelect) checkup3 = models.StringField(choices=[['2', 'Changes from round to round'], ['1', 'Always 32'], ['3', 'Depends on the number of loss boxes']], label='How many boxes in total are there in a round?
', widget=widgets.RadioSelect) prolificcode = models.StringField(blank=True) handedness = models.StringField(choices=[['Right hand', 'Right hand'], ['Left hand', 'Left hand']], label='Which hand do you typically use to browse your mobile device?
', widget=widgets.RadioSelect) def live_open(player: Player, data): group = player.group time = data['time'] # this is a single timestamp indicating when the message was sent to server starttime = data['starttime'] # this is a timestamp recorded on page, indicating when box moving started opened = data['opened'] # this is zero if swiped right player.chosencard += opened player.dectimes += str(int(time) - int(starttime)) + ';' response = {'openedcards': player.chosencard} # how many cards have been opened so far return {player.id_in_group: response} # using 0: response is an error, broadcasts to the whole group!!! def checkup1_error_message(player: Player, value): if value != '1': return "Your answer is wrong. Hint: as the instructions state, two blocks will be randomly selected at the end of the study and the points from these blocks paid to you." def checkup2_error_message(player: Player, value): if value != '1': return "Your answer is wrong. Hint: there can be 1, 2, or 3 loss boxes within a round and this is randomised from round to another." def checkup3_error_message(player: Player, value): if value != '1': return "Your answer is wrong. Hint: the total number of boxes remains constant, only the number of loss boxes and gain boxes changes from round to another." class MobileCheck(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == 1 @staticmethod def vars_for_template(player: Player): session = player.session return dict( pilot = session.config['pilot'] ) @staticmethod def js_vars(player: Player): session = player.session return dict( icons = session.config['icons'] ) class Welcome(Page): form_model = 'player' form_fields = ['prolificcode'] @staticmethod def is_displayed(player: Player): session = player.session return player.round_number == 1 and session.config['pilot'] == 0 @staticmethod def vars_for_template(player: Player): session = player.session return dict( icons = session.config['icons'] ) @staticmethod def js_vars(player: Player): session = player.session return dict( icons = session.config['icons'] ) class Instructions(Page): form_model = 'player' form_fields = ['checkup1', 'checkup2', 'checkup3'] @staticmethod def is_displayed(player: Player): session = player.session if session.config['icons'] == 'smileys': return player.round_number <= 3 else: return (player.round_number-1) % C.ICECREAMLENGTH == 0 @staticmethod def vars_for_template(player: Player): session = player.session return dict( checkupround = 3, practiceround2 = player.round_number == 2, roundi = player.round_number, rounds = C.NUM_ROUNDS - C.BASELINEROUNDS, icons = session.config['icons'] ) @staticmethod def js_vars(player: Player): session = player.session return dict(boxes = C.BOXES, icons = session.config['icons']) class RoundStart(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number <= C.NUM_ROUNDS - C.BASELINEROUNDS @staticmethod def vars_for_template(player: Player): session = player.session participant = player.participant # THE FOLLOWING VARIABLES ARE SET ONLY AT THE START OF THE ROUND # FIRST 2 ROUNDS ARE PRACTICE ROUNDS WITH "FIXED FEEDBACK" # use factorisation only for non-practice rounds if player.round_number == 1: player.roundlosscards = 2 player.roundgain = 10 player.roundloss = 250 player.firstlosscard = 21 player.losscardlist = '[21,25]' elif player.round_number == 2: player.roundlosscards = 3 player.roundgain = 20 player.roundloss = 500 player.firstlosscard = 7 player.losscardlist = '[7,30,32]' else: # determine the amount of loss cards, gainamount, and lossamount trialnumber = participant.indexlist[player.round_number-2-1] # vector of how many loss cards in each round [1,2,3,1,2,3,1,2,3,...] losscardsvec = int((C.NUM_ROUNDS-2) / len(C.LOSSCARDS)) * C.LOSSCARDS # how many loss cards in this specific round player.roundlosscards = losscardsvec[trialnumber - 1] # which specific card numbers are loss cards in this block import random numbs = list(range(1,C.BOXES+1)) #[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32] losscardlist = [] num1 = random.choice(numbs) losscardlist.append(num1) numbs.remove(num1) if (player.roundlosscards >= 2): num2 = random.choice(numbs) losscardlist.append(num2) numbs.remove(num2) if (player.roundlosscards == 3): num3 = random.choice(numbs) losscardlist.append(num3) # which one is the first loss card because the block ends in this card player.firstlosscard = min(losscardlist) player.losscardlist = str(losscardlist) # gain amount in this block based on trialnumber (excel file) 10,10,10,20,20,20,30,30,30,10,10,10,... gainsvec = int((C.NUM_ROUNDS-2-C.BASELINEROUNDS) / len(C.GAINAMOUNTS)) * C.GAINAMOUNTS player.roundgain = gainsvec[trialnumber - 1] # loss amount in this block based on trialnumber (excel file) 250,250,250,250,250,250,250,250,250,500,500,... lossvec = int((C.NUM_ROUNDS-2-C.BASELINEROUNDS) / len(C.LOSSAMOUNTS)) * C.LOSSAMOUNTS player.roundloss = lossvec[trialnumber - 1] # results from previous rounds (moved here from RoundEnd) tabledata = "" for j in range(1,player.round_number): j_player = player.in_round(j) if session.config['icons'] == 'smileys': tabledata += '' tabledata += "Did a parent or an adult in your home ever swear at you, insult you, or put you down?
' ace2 = 'Did a parent or an adult in your home ever hit, beat, kick, or physically hurt you in any way?
' ace3 = 'Did you experience unwanted sexual contact (such as fondling or oral/anal/vaginal intercourse/penetration)?
' ace4 = 'Did you feel that you did not have enough to eat, had to wear dirty clothes, or had no one to protect or take care of you?
' ace5 = 'Did you feel that no one in your family loved you or thought you were special?
' ace6 = 'Did you live with anyone who was depressed, mentally ill, or attempted suicide?
' ace7 = 'Did you live with anyone who went to jail or prison?
' ace8 = 'Did you lose a parent through parental separation or divorce, abandonment, death, or other reason?
' ace9 = 'Did your parents or adults in your home ever hit, punch, beat, or threaten to harm each other?
' ace10 = 'Did you live with anyone who was a problem drinker or alcoholic, or who used street drugs?
' return dict( ace1 = ace1, ace2 = ace2, ace3 = ace3, ace4 = ace4, ace5 = ace5, ace6 = ace6, ace7 = ace7, ace8 = ace8, ace9 = ace9, ace10 = ace10 ) class RewardPage(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): session = player.session return player.round_number == C.NUM_ROUNDS and session.config['icons'] == 'smileys' @staticmethod def vars_for_template(player: Player): import random if player.field_maybe_none('computer_randomround1') == None and player.field_maybe_none('computer_randomround2') == None: roundlist = list(range(3, C.NUM_ROUNDS-C.BASELINEROUNDS+1)) # randomly chosen rounds randomround1 = random.choice(roundlist) roundlist.remove(randomround1) # make sure that randomround2 is not the same as randomround1 randomround2 = random.choice(roundlist) rewardplayer1 = player.in_round(randomround1) rewardplayer2 = player.in_round(randomround2) player.computer_randomround1 = rewardplayer1.round_number player.computer_randomround2 = rewardplayer2.round_number player.reward = (rewardplayer1.profit + rewardplayer2.profit)/100 player.randomprofit1 = rewardplayer1.profit player.randomprofit2 = rewardplayer2.profit profitzero = False if player.reward == 0: profitzero = True return dict( profitzero = profitzero, randomround1x = player.computer_randomround1, randomround2x = player.computer_randomround2) class FinalPage(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): session = player.session return player.round_number == C.NUM_ROUNDS and session.config['icons'] == 'smileys' @staticmethod def vars_for_template(player: Player): session = player.session return dict( prolificurl = session.config['prolificurl'], icons = session.config['icons'] ) page_sequence = [MobileCheck, Welcome, Instructions, RoundStart, Decision, RoundEnd, RiskReport, NFC, ACE, RewardPage, FinalPage]