from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, ) import random """import itertools import json""" doc = """ This is a 1-player trust game where the player is randomly assigned to be either the first or second decision-maker, and can decide to either trade or cancel. The other decision is made automatically based on the trial. """ class Constants(BaseConstants): name_in_url = 'trust_game_demo' players_per_group = None num_rounds = 12 surveys = ['SmileIntensityOne', 'SmileIntensityTwo', 'Liking', 'Attractiveness', 'Trust', 'Narcissism', 'Handedness'] likert7Choices = [ [1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], ] likert5Choices = [ [1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], ] handednessChoices = [ [-1, ''], [0, ''], [1, ''], ] """smileIntensityChoices = likert7Choices likingChoices = likert5Choices""" """Create your own intro/instructions template""" instructions_template = 'trust_game_demo/Instructions.html' """Any constants to set here, or are all values in question variable, thus defined differently?""" """Initial amount allocated to each player endowment = c(100) multiplier = 3""" """I am guessing I will actually have to use this, probably pretty heavily (e.g., in lieu of constants above""" class Subsession(BaseSubsession): def creating_session(self): if self.round_number == 1: # for p in self.get_players(): # round_numbers = list(range(1, Constants.num_rounds + 1)) # random.shuffle(round_numbers) # p.participant.vars['surveys_rounds'] = dict(zip(Constants.surveys, round_numbers)) # p.participant.vars['num_rounds'] = Constants.num_rounds self.session.vars['photo_conditions'] = [1, 2, 3, 4, 5, 6, 7, 8] """self.session.vars['curr_wait_time'] = random.randint(1, 10)""" """self.session.vars['photo_condition'] = random.randint(1,8)""" self.session.vars['role_conditions'] = ["First", "First", "First" "Second", "Second", "First", "Second", "Second", "First", "Second", "First", "Second", "Second", "Second", "First", "First", "Second", "Second", "First", "Second", "First", "First", "First", "Second", "First"] self.session.vars['comp_decisions'] = ["Trade", "Cancel", "Cancel", "Trade", "Cancel", "Trade", "Cancel", "Trade", "Trade", "Cancel", "Trade", "Cancel", "Cancel", "Trade", "Trade", "Trade", "Cancel", "Cancel", "Trade", "Trade", "Cancel", "Cancel", "Cancel", "Trade"] self.session.vars['running_total'] = 0 self.session.vars['comp_total'] = 0 """try: self.session.vars['curr_player'] = self.session.vars['curr_player'] + 1 except NameError: self.session.vars['curr_player'] = 0""" """comp_decision_setter = random.randint(1, 2) if comp_decision_setter == 1: self.session.vars['comp_decision'] = 'Trade' else: self.session.vars['comp_decision'] = 'Cancel'""" """if self.round_number % 2 == 0: self.get_players() = 1 else: round_role = 2""" """Set other role values here based off of subsession values above?""" class Group(BaseGroup): pass class Player(BasePlayer): smileIntensityOne1 = models.IntegerField( label='This person...', choices=Constants.likert7Choices, widget=widgets.RadioSelectHorizontal ) smileIntensityTwo1 = models.IntegerField( label='This person''s smile is authentic', choices=Constants.likert7Choices, widget=widgets.RadioSelectHorizontal ) smileIntensityTwo2 = models.IntegerField( label='This person''s smile is genuine', choices=Constants.likert7Choices, widget=widgets.RadioSelectHorizontal ) liking1 = models.IntegerField( label='I find this person likable', choices=Constants.likert5Choices, widget=widgets.RadioSelectHorizontal ) liking2 = models.IntegerField( label='I would like to get to know this person', choices=Constants.likert5Choices, widget=widgets.RadioSelectHorizontal ) liking3 = models.IntegerField( label='I could be friends with this person', choices=Constants.likert5Choices, widget=widgets.RadioSelectHorizontal ) liking4 = models.IntegerField( label='I think this person is interesting', choices=Constants.likert5Choices, widget=widgets.RadioSelectHorizontal ) attractiveness1 = models.IntegerField( label='I think s/he is quite handsome or pretty.', choices=Constants.likert5Choices, widget=widgets.RadioSelectHorizontal ) attractiveness2 = models.IntegerField( label='I find him/her very attractive physically.', choices=Constants.likert5Choices, widget=widgets.RadioSelectHorizontal ) attractiveness3 = models.IntegerField( label='I like the way s/he looks.', choices=Constants.likert5Choices, widget=widgets.RadioSelectHorizontal ) trust1 = models.IntegerField( label='dependable', choices=Constants.likert5Choices, widget=widgets.RadioSelectHorizontal ) trust2 = models.IntegerField( label='honest', choices=Constants.likert5Choices, widget=widgets.RadioSelectHorizontal ) trust3 = models.IntegerField( label='reliable', choices=Constants.likert5Choices, widget=widgets.RadioSelectHorizontal ) trust4 = models.IntegerField( label='sincere', choices=Constants.likert5Choices, widget=widgets.RadioSelectHorizontal ) trust5 = models.IntegerField( label='trustworthy', choices=Constants.likert5Choices, widget=widgets.RadioSelectHorizontal ) handedness1 = models.IntegerField( label='With which hand do you write?', choices=Constants.handednessChoices, widget=widgets.RadioSelectHorizontal ) handedness2 = models.IntegerField( label='In which hand do you prefer to use a spoon when eating?', choices=Constants.handednessChoices, widget=widgets.RadioSelectHorizontal ) handedness3 = models.IntegerField( label='In which hand do you prefer to hold a toothbrush when cleaning your teeth?', choices=Constants.handednessChoices, widget=widgets.RadioSelectHorizontal ) handedness4 = models.IntegerField( label='In which hand do you hold a match when you strike it?', choices=Constants.handednessChoices, widget=widgets.RadioSelectHorizontal ) handedness5 = models.IntegerField( label='In which hand do you prefer to hold the eraser when erasing a pencil mark?', choices=Constants.handednessChoices, widget=widgets.RadioSelectHorizontal ) handedness6 = models.IntegerField( label='In which hand do you hold the needle when you are sewing?', choices=Constants.handednessChoices, widget=widgets.RadioSelectHorizontal ) handedness7 = models.IntegerField( label='When buttering bread, which hand holds the knife?', choices=Constants.handednessChoices, widget=widgets.RadioSelectHorizontal ) handedness8 = models.IntegerField( label='In which hand do you hold a hammer?', choices=Constants.handednessChoices, widget=widgets.RadioSelectHorizontal ) handedness9 = models.IntegerField( label='In which hand do you hold the peeler when peeling an apple?', choices=Constants.handednessChoices, widget=widgets.RadioSelectHorizontal ) handedness10 = models.IntegerField( label='Which hand do you use to draw?', choices=Constants.handednessChoices, widget=widgets.RadioSelectHorizontal ) narcissism1 = models.IntegerField( label='1.', choices=[ [1, 'I have a natural talent for influencing people'], [2, 'I am not good at influencing people.'], ], widget=widgets.RadioSelectHorizontal ) narcissism2 = models.IntegerField( label='2.', choices=[ [1, 'Modesty doesn''t become me.'], [2, 'I am essentially a modest person.'], ], widget=widgets.RadioSelectHorizontal ) narcissism3 = models.IntegerField( label='3.', choices=[ [1, 'I would do almost anything on a dare.'], [2, 'I tend to be a fairly cautious person.'], ], widget=widgets.RadioSelectHorizontal ) narcissism4 = models.IntegerField( label='4.', choices=[ [1, 'When people compliment me I sometimes get embarrassed.'], [2, 'I know that I am good because everybody keeps telling me so.'], ], widget=widgets.RadioSelectHorizontal ) narcissism5 = models.IntegerField( label='5.', choices=[ [1, 'The thought of ruling the world frightens the hell out of me.'], [2, 'If I ruled the world it would be a better place.'], ], widget=widgets.RadioSelectHorizontal ) narcissism6 = models.IntegerField( label='6.', choices=[ [1, 'I can usually talk my way out of anything.'], [2, 'I try to accept the consequences of my behavior.'], ], widget=widgets.RadioSelectHorizontal ) narcissism7 = models.IntegerField( label='7.', choices=[ [1, 'I prefer to blend in with the crowd.'], [2, 'I like to be the center of attention.'], ], widget=widgets.RadioSelectHorizontal ) narcissism8 = models.IntegerField( label='8.', choices=[ [1, 'I will be a success.'], [2, 'I am not too concerned about success.'], ], widget=widgets.RadioSelectHorizontal ) narcissism9 = models.IntegerField( label='9.', choices=[ [1, 'I am no better or worse than most people.'], [2, 'I think I am a special person.'], ], widget=widgets.RadioSelectHorizontal ) narcissism10 = models.IntegerField( label='10.', choices=[ [1, 'I am not sure if I would make a good leader.'], [2, 'I see myself as a good leader.'], ], widget=widgets.RadioSelectHorizontal ) narcissism11 = models.IntegerField( label='11.', choices=[ [1, 'I am assertive.'], [2, 'I wish I were more assertive.'], ], widget=widgets.RadioSelectHorizontal ) narcissism12 = models.IntegerField( label='12.', choices=[ [1, 'I like to have authority over other people.'], [2, 'I don''t mind following orders.'], ], widget=widgets.RadioSelectHorizontal ) narcissism13 = models.IntegerField( label='13.', choices=[ [1, 'I find it easy to manipulate people.'], [2, 'I don''t like it when I find myself manipulating people.'], ], widget=widgets.RadioSelectHorizontal ) narcissism14 = models.IntegerField( label='14.', choices=[ [1, 'I insist upon getting the respect that is due me.'], [2, 'I usually get the respect that I deserve.'], ], widget=widgets.RadioSelectHorizontal ) narcissism15 = models.IntegerField( label='15.', choices=[ [1, 'I don''t particularly like to show off my body.'], [2, 'I like to show off my body.'], ], widget=widgets.RadioSelectHorizontal ) narcissism16 = models.IntegerField( label='16.', choices=[ [1, 'I can read people like a book.'], [2, 'People are sometimes hard to understand.'], ], widget=widgets.RadioSelectHorizontal ) narcissism17 = models.IntegerField( label='17.', choices=[ [1, 'If I feel competent I am willing to take responsibility for making decisions.'], [2, 'I like to take responsibility for making decisions.'], ], widget=widgets.RadioSelectHorizontal ) narcissism18 = models.IntegerField( label='18.', choices=[ [1, 'I just want to be reasonably happy.'], [2, 'I want to amount to something in the eyes of the world.'], ], widget=widgets.RadioSelectHorizontal ) narcissism19 = models.IntegerField( label='19.', choices=[ [1, 'My body is nothing special.'], [2, 'I like to look at my body.'], ], widget=widgets.RadioSelectHorizontal ) narcissism20 = models.IntegerField( label='20.', choices=[ [1, 'I try not to be a show off.'], [2, 'I will usually show off if I get the chance.'], ], widget=widgets.RadioSelectHorizontal ) narcissism21 = models.IntegerField( label='21.', choices=[ [1, 'I always know what I am doing.'], [2, 'Sometimes I am not sure of what I am doing.'], ], widget=widgets.RadioSelectHorizontal ) narcissism22 = models.IntegerField( label='22.', choices=[ [1, 'I sometimes depend on people to get things done.'], [2, 'I rarely depend on anyone else to get things done.'], ], widget=widgets.RadioSelectHorizontal ) narcissism23 = models.IntegerField( label='23.', choices=[ [1, 'Sometimes I tell good stories.'], [2, 'Everybody likes to hear my stories.'], ], widget=widgets.RadioSelectHorizontal ) narcissism24 = models.IntegerField( label='24.', choices=[ [1, 'I expect a great deal from other people.'], [2, 'I like to do things for other people.'], ], widget=widgets.RadioSelectHorizontal ) narcissism25 = models.IntegerField( label='25.', choices=[ [1, 'I will never be satisfied until I get all that I deserve.'], [2, 'I take my satisfactions as they come.'], ], widget=widgets.RadioSelectHorizontal ) narcissism26 = models.IntegerField( label='26.', choices=[ [1, 'Compliments embarrass me.'], [2, 'I like to be complimented.'], ], widget=widgets.RadioSelectHorizontal ) narcissism27 = models.IntegerField( label='27.', choices=[ [1, 'I have a strong will to power.'], [2, 'Power for its own sake doesn''t interest me.'], ], widget=widgets.RadioSelectHorizontal ) narcissism28 = models.IntegerField( label='28.', choices=[ [1, 'I don''t care about new fads and fashions.'], [2, 'I like to start new fads and fashions.'], ], widget=widgets.RadioSelectHorizontal ) narcissism29 = models.IntegerField( label='29.', choices=[ [1, 'I like to look at myself in the mirror.'], [2, 'I am not particularly interested in looking at myself in the mirror.'], ], widget=widgets.RadioSelectHorizontal ) narcissism30 = models.IntegerField( label='30.', choices=[ [1, 'I really like to be the center of attention.'], [2, 'It makes me uncomfortable to be the center of attention.'], ], widget=widgets.RadioSelectHorizontal ) narcissism31 = models.IntegerField( label='31.', choices=[ [1, 'I can live my life in any way I want to.'], [2, 'People can''t always live their lives in terms of what they want.'], ], widget=widgets.RadioSelectHorizontal ) narcissism32 = models.IntegerField( label='32.', choices=[ [1, 'Being an authority doesn''t mean that much to me.'], [2, 'People always seem to recognize my authority.'], ], widget=widgets.RadioSelectHorizontal ) narcissism33 = models.IntegerField( label='33.', choices=[ [1, 'I would prefer to be a leader.'], [2, 'It makes little difference to me whether I am leader or not.'], ], widget=widgets.RadioSelectHorizontal ) narcissism34 = models.IntegerField( label='34.', choices=[ [1, 'I am going to be a great person.'], [2, 'I hope I am going to be successful.'], ], widget=widgets.RadioSelectHorizontal ) narcissism35 = models.IntegerField( label='35.', choices=[ [1, 'People sometimes believe what I tell them.'], [2, 'I can make anybody believe anything I want them to.'], ], widget=widgets.RadioSelectHorizontal ) narcissism36 = models.IntegerField( label='36.', choices=[ [1, 'I am a born leader.'], [2, 'Leadership is a quality that takes a long time to develop.'], ], widget=widgets.RadioSelectHorizontal ) narcissism37 = models.IntegerField( label='37.', choices=[ [1, 'I wish somebody would someday write my biography.'], [2, 'I don''t like people to pry into my life for any reason.'], ], widget=widgets.RadioSelectHorizontal ) narcissism38 = models.IntegerField( label='38.', choices=[ [1, 'I get upset when people don''t notice how I look when I go out in public.'], [2, 'I don''t mind blending into the crowd when I go out in public.'], ], widget=widgets.RadioSelectHorizontal ) narcissism39 = models.IntegerField( label='39.', choices=[ [1, 'I am more capable than other people.'], [2, 'There is a lot that I can learn from other people.'], ], widget=widgets.RadioSelectHorizontal ) narcissism40 = models.IntegerField( label='40.', choices=[ [1, 'I am much like everybody else.'], [2, 'I am an extraordinary person.'], ], widget=widgets.RadioSelectHorizontal ) """def set_payoffs(self): p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) p1.payoff = Constants.endowment - self.sent_amount + self.sent_back_amount p2.payoff = self.sent_amount * Constants.multiplier - self.sent_back_amount""" """fakeUpload = models.FileField(blank=True)""" def role(self): return self.session.vars['role_conditions'][self.subsession.round_number - 1] """Seems similar to what we will want to use to keep track of role in each round, but instead of being based off of id_in_group (assuming group size of 1 is in fact the way to do it), it should be randomized at the participant level (list of all round values generated randomly beforehand, then just iterate through the read and get the current role value for each round""" """def role(self): return {1: 'First', 2: 'Second'}[self.id_in_group]""" decision = models.IntegerField( choices=[ [1, 'Trade'], [2, 'Cancel'], ], widget=widgets.RadioSelect, doc='Decision made by the first mover/player', ) """second_move = models.IntegerField( choices=[ [1, 'Trade'], [2, 'Cancel'], ], widget=widgets.RadioSelect, doc='Decision made by the second mover/player', )""" def decision_text(self): if self.decision == 1: return 'Trade' else: return 'Cancel'