from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random, itertools doc = """ commons dilemma with three levels of uncertainty """ class Constants(BaseConstants): name_in_url = 'commons_dilemma_with_uncertainty' players_per_group = 2 num_rounds = 1 instructions_template = 'commons_dilemma_with_uncertainty/Instructions.html' value_certainty = c(200) min_value_lowuncertainty = c(120) max_value_lowuncertainty = c(280) min_value_highuncertainty = c(40) max_value_highuncertainty = c(360) class Subsession(BaseSubsession): def creating_session(self): if self.round_number == 1: for g in self.get_groups(): p1 = g.get_player_by_id(1) p1.value_certainty = Constants.value_certainty p1.value_lowuncertainty = random.randint(Constants.min_value_lowuncertainty, Constants.max_value_lowuncertainty) p1.value_highuncertainty = random.randint(Constants.min_value_highuncertainty, Constants.max_value_highuncertainty) p2 = g.get_player_by_id(2) p2.value_certainty = p1.value_certainty p2.value_lowuncertainty = p1.value_lowuncertainty p2.value_highuncertainty = p1.value_highuncertainty p1.participant.vars['statuscondition'] = 'status' p2.participant.vars['statuscondition'] = p1.participant.vars['statuscondition'] p1.participant.vars['order'] = random.choice([1, 2, 3, 4, 5, 6]) p2.participant.vars['order'] = p1.participant.vars['order'] class Group(BaseGroup): def set_payoffs(self): p1 = self.get_player_by_id(1) p2 = self.get_player_by_id(2) p1.certainty_total_harvest = p2.certainty_total_harvest = p1.certainty_harvest + p2.certainty_harvest p1.lowuncertainty_total_harvest = p2.lowuncertainty_total_harvest = p1.lowuncertainty_harvest + p2.lowuncertainty_harvest p1.highuncertainty_total_harvest = p2.highuncertainty_total_harvest = p1.highuncertainty_harvest + p2.highuncertainty_harvest if p1.certainty_total_harvest > p1.value_certainty: p1.certainty_payoff = p2.certainty_payoff = c(0) p1.certainty_overharvest = p2.certainty_overharvest = True else: p1.certainty_payoff = p1.certainty_harvest p2.certainty_payoff = p2.certainty_harvest p1.certainty_overharvest = p2.certainty_overharvest = False if p1.lowuncertainty_total_harvest > p1.value_lowuncertainty: p1.lowuncertainty_payoff = p2.lowuncertainty_payoff = c(0) p1.lowuncertainty_overharvest = p2.lowuncertainty_overharvest = True else: p1.lowuncertainty_payoff = p1.lowuncertainty_harvest p2.lowuncertainty_payoff = p2.lowuncertainty_harvest p1.lowuncertainty_overharvest = p2.lowuncertainty_overharvest = False if p1.highuncertainty_total_harvest > p1.value_highuncertainty: p1.highuncertainty_payoff = p2.highuncertainty_payoff = c(0) p1.highuncertainty_overharvest = p2.highuncertainty_overharvest = True else: p1.highuncertainty_payoff = p1.highuncertainty_harvest p2.highuncertainty_payoff = p2.highuncertainty_harvest p1.highuncertainty_overharvest = p2.highuncertainty_overharvest = False p1.payoff = p1.certainty_payoff + p1.lowuncertainty_payoff + p1.highuncertainty_payoff p2.payoff = p2.certainty_payoff + p2.lowuncertainty_payoff + p2.highuncertainty_payoff class Player(BasePlayer): statuscondition = models.CharField() order = models.IntegerField() question_1 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_2 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_3 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_4 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_5 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_6 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_7 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_8 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_9 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_10 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_11 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_12 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_13 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_14 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_15 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_16 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_17 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_18 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_19 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_20 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_21 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_22 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_23 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_24 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_25 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_26 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_27 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_28 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_29 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_30 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_31 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_32 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_33 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_34 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) question_35 = models.IntegerField( choices=[1, 2, 3, 4], widget=widgets.RadioSelectHorizontal) quiz_1 = models.CharField( choices=["1 participant", "2 participants", "3 participants", "4 participants"], widget=widgets.RadioSelect) quiz_2 = models.CharField( choices=["1 round", "2 rounds", "3 rounds", "4 rounds"], widget=widgets.RadioSelect) quiz_3 = models.CharField( choices=["I will earn the number of points I took then", "I will earn zero points then", "I have not been informed about how many points I will earn then"], widget=widgets.RadioSelect) quiz_4 = models.CharField( choices=["I will earn the number of points I took then", "I will earn zero points then", "I have not been informed about how many points I will earn then"], widget=widgets.RadioSelect) leadershipscore = models.IntegerField() role_saved = models.CharField() certainty_harvest = models.CurrencyField( min=0, doc="Amount harvested under certainty" ) certainty_check = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) certainty_payoff = models.CurrencyField( min=0, doc="Amount earned under certainty" ) certainty_overharvest = models.BooleanField() lowuncertainty_harvest = models.CurrencyField( min=0, doc="Amount harvested under low uncertainty" ) lowuncertainty_estimate = models.CurrencyField( min=Constants.min_value_lowuncertainty, max=Constants.max_value_lowuncertainty, doc="Resource size estimate under low uncertainty" ) lowuncertainty_check = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) lowuncertainty_payoff = models.CurrencyField( min=0, doc="Amount earned under low uncertainty" ) lowuncertainty_overharvest = models.BooleanField() highuncertainty_harvest = models.CurrencyField( min=0, doc="Amount harvested under high uncertainty" ) highuncertainty_estimate = models.CurrencyField( min=Constants.min_value_highuncertainty, max=Constants.max_value_highuncertainty, doc="Resource size estimate under high uncertainty" ) highuncertainty_check = models.IntegerField( choices=[1, 2, 3, 4, 5, 6, 7], widget=widgets.RadioSelectHorizontal) highuncertainty_payoff = models.CurrencyField( min=0, doc="Amount earned under high uncertainty" ) highuncertainty_overharvest = models.BooleanField() value_certainty = models.CurrencyField() value_lowuncertainty = models.CurrencyField() value_highuncertainty = models.CurrencyField() certainty_total_harvest = models.CurrencyField() lowuncertainty_total_harvest = models.CurrencyField() highuncertainty_total_harvest = models.CurrencyField()