from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random doc = """ author: wb """ class Constants(BaseConstants): name_in_url = 'part0' players_per_group = None num_rounds = 1 instructions_template = 'part0/instructions.html' instructions2_template = 'part0/instructions2.html' ta=[40,20,25,35,34,48,19,33,52,13,10,59,34,39,27,46,18,44,17,13] t1 = random.sample(ta, 5) tb=[39,21,26,34,33,22,33,35,26,37,34,39,27,38,36,20] t2=random.sample(tb, 5) numparticipant = 1 bonus = 500 bonus1 = 150 bonus2 = 150 surepaycournot = 750 class Subsession(BaseSubsession): pass class Group(BaseGroup): group_size= models.FloatField() def set_payoffs(self): self.group_size = sum([p.unite for p in self.get_players()]) for p in self.get_players(): p.quantity_j1 = Constants.t1[0] p.quantity_j2 = Constants.t1[1] p.quantity_j3 = Constants.t1[2] p.quantity_j4 = Constants.t1[3] p.quantity_j5 = Constants.t1[4] p.price_1 = max(0, (100 - (p.quantity1 + p.quantity_j1))) p.price_2 = max(0, (100 - (p.quantity1 + p.quantity_j2))) p.price_3 = max(0, (100 - (p.quantity1 + p.quantity_j3))) p.price_4 = max(0, (100 - (p.quantity1 + p.quantity_j4))) p.price_5 = max(0, (100 - (p.quantity1 + p.quantity_j5))) p.price_average = round((p.price_1 + p.price_2 + p.price_3 + p.price_4 + p.price_5) / 5, 1) p.gain_task1 = round(p.quantity1 * (p.price_average - 1), 1) def set_payoffs2(self): self.group_size = sum([p.unite for p in self.get_players()]) for p in self.get_players(): if p.decision_t2 == 1 : p.quantity_j1_v2 = Constants.t2[0] p.quantity_j2_v2 = Constants.t2[1] p.quantity_j3_v2 = Constants.t2[2] p.quantity_j4_v2 = Constants.t2[3] p.quantity_j5_v2 = Constants.t2[4] p.price_1_v2 = max(0, (100 - (p.quantity2 + p.quantity_j1_v2))) p.price_2_v2 = max(0, (100 - (p.quantity2 + p.quantity_j2_v2))) p.price_3_v2 = max(0, (100 - (p.quantity2 + p.quantity_j3_v2))) p.price_4_v2 = max(0, (100 - (p.quantity2 + p.quantity_j4_v2))) p.price_5_v2 = max(0, (100 - (p.quantity2 + p.quantity_j5_v2))) p.price_average_v2 = round( (p.price_1_v2 + p.price_2_v2 + p.price_3_v2 + p.price_4_v2 + p.price_5_v2) / 5, 1) p.gain_task2 = round(p.quantity2 * (p.price_average_v2 - 1), 1) class Player(BasePlayer): agree = models.IntegerField( label='', blank=False, ) treatment = models.IntegerField( label="", blank=True ) q0 = models.IntegerField( choices=[ [1, 'skiing'], [2, 'soccer'], [3, 'snowboarding'], [4, 'running'], [5, 'hockey'], [6, 'football'], [7, 'swimming'], [8, 'tennis'], [9, 'basketball'], [10, 'cycling'], ], label="", widget=widgets.RadioSelectHorizontal, blank=True ) nextq0 = models.IntegerField( default=0, blank=True ) b0 = models.IntegerField( blank=True ) fear_5a = models.IntegerField( choices=[ [1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8'], [9, '9'], [10, 'more than 9'], ], label="", widget=widgets.RadioSelectHorizontal, blank=True ) b5 = models.IntegerField( default=0, blank=True ) eliminated = models.IntegerField( default=0, blank=True ) gaineliminated = models.FloatField( ) q_a = models.IntegerField( choices=[ [0, '0 - Male'], [1, '1 – Female'], [2, '2 – Non binary'], [3, '3 - Rather not say'], ], label="a. What is your gender?", widget=widgets.RadioSelect, blank=False ) q_b = models.IntegerField( label="b. How old are you?", blank=False, min =0, max = 100, ) q_c = models.IntegerField( choices=[ [1, '1- Farmers'], [2, '2- Executive and intellectual professionals'], [3, '3- Intermediate professions'], [4, '4- Shopkeepers, merchants'], [5, '5- Craftsmen'], [6, '6- Employees'], [7, '7- Other workers'], [8, '8- Students'], [9, '9- Retired'], [10, '10- Unemployed'], [11, '11- Others out of work'], ], label="c. What is your professional category?", widget=widgets.RadioSelect, blank=False ) # # q_d = models.IntegerField( # choices=[ # [0, '0- No'], # [1, '1- Yes'], # [2, '2- Don’t know'], # ], # label="d. Have you recently felt betrayed by someone you were close to?", # widget=widgets.RadioSelect, # blank=False # ) num_post = models.IntegerField( label='', blank=False, ) unite = models.IntegerField() qc_a = models.IntegerField( label='', blank=False, ) qc_b = models.IntegerField( label='', blank=False, ) survey1 = models.IntegerField( choices=[ [0, '0'], [1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8'], [9, '9'], [10, '10'], ], label="", widget=widgets.RadioSelectHorizontal, blank=False ) quantity1 = models.IntegerField( min=0, max=100, blank=False, label='', ) decision_t2 = models.IntegerField( choices=[ [0, 'Receive a guaranteed payoff of 750 coins'], [1, 'Play again'], ], label="", widget=widgets.RadioSelect, blank=False ) quantity2 = models.IntegerField( min=0, max=100, blank=False, label='', ) quantity_j1 = models.FloatField() quantity_j2 = models.FloatField() quantity_j3 = models.FloatField() quantity_j4 = models.FloatField() quantity_j5 = models.FloatField() price_1 = models.IntegerField() price_2 = models.IntegerField() price_3 = models.IntegerField() price_4 = models.IntegerField() price_5 = models.IntegerField() price_average = models.FloatField() gain_task1 = models.FloatField() quantity_j1_v2 = models.FloatField() quantity_j2_v2 = models.FloatField() quantity_j3_v2 = models.FloatField() quantity_j4_v2 = models.FloatField() quantity_j5_v2 = models.FloatField() price_1_v2 = models.IntegerField() price_2_v2 = models.IntegerField() price_3_v2 = models.IntegerField() price_4_v2 = models.IntegerField() price_5_v2 = models.IntegerField() price_average_v2 = models.FloatField() gain_task2 = models.FloatField() gain_task1_f = models.FloatField() gain_task2_f = models.FloatField()