from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import numpy as np import random doc = """ JMP """ class Constants(BaseConstants): name_in_url = 'study' players_per_group = 2 num_rounds = 8 template_report='trust/profit_report.html' template_recap='trust/recap_template.html' template_wait_page='trust/wait_page_template.html' template_mturk_wait_page='trust/mturk_wait_page_template.html' template_mturk_wait_page='trust/mturk_wait_page_template.html' template_instructions='attention/instructions_template.html' #time allowed per page max_per_page=120 probability_min=2 probability_increment=1 probability_max=7 probability_total=10 probability_dif=probability_max-probability_min supervisor_endowment=c(400) employee_endowment=c(360) fixed_payment_in_points=c(250) #this is hardcoded please remember to change bonus_max=c(200) cost_per_rock=20 supervisor_bonus_low=c(70) supervisor_bonus_high=c(190) cost_max_employee=probability_dif*cost_per_rock profit_low="Low" profit_high="High" confronatation_employee=c(10) confronatation_supervisor=c(30) class Subsession(BaseSubsession): pass # def creating_session(self): # if self.round_number == 1: # for g in self.get_groups(): # p1 = g.get_player_by_id(1) # if 'treatment_confrontation' in self.session.config: # p1.participant.vars['treatment_confrontation'] = self.session.config['treatment_confrontation'] # else: # p1.participant.vars['treatment_confrontation'] = random.choice([0, 1]) # if 'treatment_info' in self.session.config: # p1.participant.vars['treatment_info'] = self.session.config['treatment_info'] # else: # p1.participant.vars['treatment_info'] = random.choice([0, 1, 2]) # #0=outcome only # #1=outcome+effort # #2=effort only class Group(BaseGroup): effort = models.IntegerField( choices=np.arange(0, Constants.probability_dif+1, Constants.probability_increment).tolist(), widget=widgets.RadioSelectHorizontal ) confrontation = models.IntegerField( choices=[ [0, 'No'], [1, 'Yes']], widget=widgets.RadioSelectHorizontal ) bonus = models.CurrencyField( min=0, max=Constants.bonus_max ) supervisor_bonus = models.CurrencyField() payoff_supervisor = models.CurrencyField() payoff_employee = models.CurrencyField() profit = models.StringField( choices=[ "Low", "High"], ) treatment_info = models.IntegerField() treatment_confrontation = models.IntegerField() random_draw=models.IntegerField() random_period=models.IntegerField() def profit_random(self): self.random_draw=random.randrange(1,Constants.probability_total+1) return self.random_draw<=Constants.probability_min+self.effort class Player(BasePlayer): collegue_left=models.BooleanField() participant_left=models.BooleanField() waited_for_group=models.BooleanField() kicked_out_period=models.IntegerField() def role(self): return {1: 'Supervisor', 2: 'Employee'}[self.id_in_group]