from otree.api import * import itertools #for balanced groups #import random #for unbalanced groups doc = """ Treatment check """ class C(BaseConstants): NAME_IN_URL = 'Pay' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): contract_read = models.BooleanField( widget=widgets.CheckboxInput(), blank=True, ) treatment = models.IntegerField(min=0, max=4, label='Treatment group') number_K_contract = models.IntegerField(min=0, max=100, label='Number of letters "K" clicked in the grid.') number_IK_contract = models.IntegerField(min=0, max=100, label='Number of letters "I" clicked in the grid.') sum_K_contract = models.IntegerField(initial=0, min=0, max=100, label='Sum of letters "K" clicked in the grid.') sum_IK_contract = models.IntegerField(initial=0, min=0, max=100, label='Sum of letters "IK" clicked in the grid.') correct_K_contract = models.IntegerField(initial=0, min=0, max=100, label='Sum of correct "K" in the grid.') correct_IK_contract = models.IntegerField(initial=0, min=0, max=100, label='Sum of letters "IK" clicked in the grid.') payout_contract = models.IntegerField(initial=0, min=0, label='Points made in that round') contract_clicked = models.IntegerField(initial=0, label='1 if participant clicked on the contract information') payout_estimate = models.IntegerField( min=0, max=500, label='Please estimate the number of points that you have earned with that task:' ) clarity = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', '']], label='It is clear to me how I can earn points', widget=widgets.RadioSelectHorizontal, ) expectation = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', '']], label='It is clear to me what is expected of me', widget=widgets.RadioSelectHorizontal, ) attention = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', '']], label='Please select option (7) - Strongly agree', widget=widgets.RadioSelectHorizontal, ) remember = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', '']], label='I remember how my contract is designed', widget=widgets.RadioSelectHorizontal, ) overall = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', '']], label='Overall, I understand my contract', widget=widgets.RadioSelectHorizontal, ) procedure_1 = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', '']], label='I have influence over the points that I can earn', widget=widgets.RadioSelectHorizontal, ) procedure_2 = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', '']], label='My contract is closely aligned with the task', widget=widgets.RadioSelectHorizontal, ) procedure_3 = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', '']], label='The contract rules ignore relevant aspects of the task', widget=widgets.RadioSelectHorizontal, ) procedure_4 = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', '']], label='My contract contains rules that have no relation to the task', widget=widgets.RadioSelectHorizontal, ) procedure_5 = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', '']], label='Overall, the contract is appropriate for the task', widget=widgets.RadioSelectHorizontal, ) dist_1 = models.StringField( choices=[['1', ''], ['2', ''], ['3', ''], ['4', ''], ['5', ''], ['6', ''], ['7', '']], label='The points reflect the effort I put into the task completion', widget=widgets.RadioSelectHorizontal, ) #FUNCTIONS def creating_session(subsession): treatment = itertools.cycle([1,1,2,3,2,3,4,4]) for player in subsession.get_players(): participant = player.participant participant.contract_group = next(treatment) player.treatment = participant.contract_group # PAGES class Contract(Page): form_model = 'player' form_fields = ['contract_read'] def error_message(player, values): if values['contract_read'] == 0 or values['contract_read'] == None: return 'You have to fully read the contract in order to continue with the experiment. Please read the contract again.' class TaskTest_2(Page): form_model = 'player' form_fields = ['number_K_contract', 'number_IK_contract'] @staticmethod def live_method(player, data): player.sum_K_contract = int(data['value_K']); player.sum_IK_contract = int(data['value_IK']); player.correct_K_contract = int(data['correct_K']); player.correct_IK_contract = int(data['correct_IK']); class TestResults(Page): form_model = 'player' form_fields = ['payout_estimate'] @staticmethod # to calculate the appropriate payouts, stored in player.payout_contract def vars_for_template(player): participant = player.participant if participant.contract_group < 3: if player.sum_K_contract == player.correct_K_contract: sum_K_is_K = 1; else: sum_K_is_K = 0; if player.sum_IK_contract == player.correct_IK_contract: sum_IK_is_IK = 1; else: sum_IK_is_IK = 0; if player.number_K_contract == player.correct_K_contract: num_K_is_K = 1; else: num_K_is_K = 0; if player.number_IK_contract == player.correct_IK_contract: num_IK_is_IK = 1; else: num_IK_is_IK = 0; calc = (sum_K_is_K + sum_IK_is_IK + num_K_is_K + num_IK_is_IK) * 50 player.payout_contract = int(round(calc,0)) else: sum_Ks = player.sum_K_contract * 5 sum_IKs = player.sum_IK_contract * 7 if player.number_K_contract == player.correct_K_contract: a_K = 23; a_K_is_K = 1; else: a_K = 0; a_K_is_K = 0; if player.number_IK_contract == player.correct_IK_contract: a_IK = 17; a_IK_is_IK = 1; else: a_IK = 0; a_IK_is_IK = 0; calc = sum_Ks + sum_IKs + a_K + a_IK + (0.25 * ((sum_Ks * a_K_is_K) + (sum_IKs * a_IK_is_IK) + (sum_Ks * a_IK_is_IK) + (sum_IKs * a_K_is_K))) * (1.2 * a_K_is_K * a_IK_is_IK) player.payout_contract = int(round(calc,0)) @staticmethod def live_method(player, data): player.contract_clicked = int(data['contract_clicked']); class ContractSurvey(Page): form_model = 'player' form_fields = ['clarity', 'expectation', 'attention', 'remember', 'procedure_1', 'procedure_2', 'procedure_3', 'procedure_4', 'procedure_5', 'dist_1', 'overall'] page_sequence = [Contract, TaskTest_2,TestResults, ContractSurvey]