from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import datetime import pytz author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'instr' players_per_group = None num_rounds = 3 allowed_timeouts = 3 exchange_rate = 0.25 show_up_fee = 5 instr1 = 't4_instr/Instr1.html' instr2 = 't4_instr/Instr2.html' instr3 = 't4_instr/Instr3.html' instr4 = 't4_instr/Instr4.html' instr5 = 't4_instr/Instr5.html' q1_text = "You alternate between the roles of Person A and Person B each round." q2_text = "Person B is only asked to make a decision if Person A chose Take." q3_text = "If you miss 3 decisions, you will be excluded from the study." q4_text = "The experiment lasts 50 rounds in total." q5_text = "Person A chooses Take and Person B chooses Don't Resist." q6_text = "Person A chooses Don't Take." q7_text = "Person A chooses Take and Person B chooses Resist." q8_text = "What information is available to Persons A and B about earlier actions made by either Person A or Person B?" num_questions = 8 class Subsession(BaseSubsession): value = models.IntegerField() cost = models.IntegerField() showup = models.FloatField() endowment = models.IntegerField() reputation = models.BooleanField() last_round = models.IntegerField() def creating_session(self): # Calculate number of attackers and defenders for p in self.get_players(): p.participant.vars['prac_missed'] = 0 # Cost and value self.endowment = 3 self.showup = 5 if self.session.config['vc_ratio'] == 'high': # ratio = 1/2 self.value = 6 self.cost = 12 else: # ratio = 1/4 self.value = 2 self.cost = 8 self.reputation = self.session.config['reputation'] class Group(BaseGroup): pass class Player(BasePlayer): # store time timestamp_start = models.FloatField() q1 = models.IntegerField( verbose_name="You alternate between the roles of Player A and B each round.", choices=[ [1, "True"], [0, "False"], ] ) q2 = models.IntegerField( verbose_name="Player B is only asked to make a decision if Player A chooses Right.", choices=[ [1, "True"], [0, "False"], ] ) q3 = models.IntegerField( verbose_name="If you miss 4 decisions, you will be excluded from the experiment.", choices=[ [1, "True"], [0, "False"], ] ) q4 = models.IntegerField( verbose_name="The experiment lasts 50 rounds in total.", choices=[ [1, "True"], [0, "False"], ] ) q5a = models.IntegerField( min=-10, max=10, ) q5b = models.IntegerField( min=-10, max=10, ) q6a = models.IntegerField( min=-10, max=10, ) q6b = models.IntegerField( min=-10, max=10, ) q7a = models.IntegerField( min=-10, max=10, ) q7b = models.IntegerField( min=-10, max=10, ) q8 = models.IntegerField( choices=[ [1, 'Neither Persons A nor Persons B are informed about the decisions made by other persons in earlier rounds.'], [2, 'Only Persons B receive information about the decisions made by Persons A in earlier rounds.'], [3, 'Only Persons A receive information about the decisions made by Persons B in earlier rounds.'], [4, 'Both Persons A and Persons B receive information about the decisions made by Persons A in earlier rounds.'], [5, 'Both Persons A and Persons B receive information about the decisions made by Persons B in earlier rounds.'], ], # widget = widgets.RadioSelect, ) q1_correct = models.BooleanField() q2_correct = models.BooleanField() q3_correct = models.BooleanField() q4_correct = models.BooleanField() q5_correct = models.BooleanField() q6_correct = models.BooleanField() q7_correct = models.BooleanField() q8_correct = models.BooleanField() num_correct = models.IntegerField() pract_choice_a = models.IntegerField( choices=[ [1, 'Challenge'], [0, 'Leave'], [99, 'No choice'], ], widget=widgets.RadioSelect, label="", # initial=99, ) pract_choice_d = models.IntegerField( choices=[ [0, 'Up'], # 'Acquiesce'], [1, 'Down'], # 'Resist'], ], widget=widgets.RadioSelect, label="", ) pract_rewpun = models.IntegerField(initial=2, blank=True, choices=[ [1, 'reward'], [2, 'nothing'], [3, 'punish'] ]) pract_numlikes = models.IntegerField(initial=0) pract_numpunishers = models.IntegerField(initial=0) pract_payoff_a = models.IntegerField() pract_payoff_b = models.IntegerField() def check_answers(self): self.q1_correct = self.q1 == False self.q2_correct = self.q2 == False self.q3_correct = self.q3 == True self.q4_correct = self.q4 == False self.q5_correct = self.q5a == (self.subsession.endowment + self.subsession.value) and self.q5b == self.subsession.endowment self.q6_correct = self.q6a == self.subsession.endowment and self.q6b == (self.subsession.endowment + self.subsession.value) self.q7_correct = self.q7a == self.q7b == self.subsession.endowment + (self.subsession.value - self.subsession.cost) / 2 self.q8_correct = False if not self.subsession.reputation: self.q8_correct = self.q8 == 1 else: self.q8_correct = self.q8 == 5 self.num_correct = self.q1_correct + self.q2_correct + self.q3_correct + self.q4_correct + self.q5_correct + \ self.q6_correct + self.q7_correct + self.q8_correct