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 = ['SmileIntensity', 'Liking'] 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'], ] 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): smileIntensity1 = models.IntegerField( label='This person...', choices=Constants.likert7Choices, widget=widgets.RadioSelectHorizontal ) smileIntensity2 = models.IntegerField( label='This person''s smile is authentic', choices=Constants.likert7Choices, widget=widgets.RadioSelectHorizontal ) smileIntensity3 = 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 ) """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'