from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import random as random import itertools import json as json import pandas as pd import numpy as np import math author = 'Your name here' doc = """ MPL """ class Constants(BaseConstants): name_in_url = '9H32Dcsfw2DDg' players_per_group = None num_rounds = 2 num_participants = 10 timeout = 40 play_rounds = 5 #ordering = ['BA','AB'] ### MPL max_amount = 40 increments = 2 no_decisions = math.floor((2*max_amount/increments))+1 # Payoff Constants payoff_incorrect = c(0) pwd_rate_high = 12 pwd_piecerate_high = c(pwd_rate_high) math_rate_high = 12 math_piecerate_high = c(math_rate_high) pwd_rate_low = 10 pwd_piecerate_low = c(pwd_rate_low) math_rate_low = 10 math_piecerate_low = c(math_rate_low) MPL_sequence = ['HighLow','LowHigh'] task = 'MPL' num_pwd_tasks = 10 num_math_tasks = 10 class Subsession(BaseSubsession): def creating_session(self): MPL_sequence = Constants.MPL_sequence.copy() # shuffle the list random.shuffle(MPL_sequence) # make a cycle out of the shuffled list MPL_seq = itertools.cycle(MPL_sequence) for p in self.get_players(): # Establishes task ordering & Incentives for Math Task if self.round_number == 1: p.participant.vars['MPL_sequence'] = next(MPL_seq) p.participant.vars['MPL_max_amount'] = Constants.max_amount p.participant.vars['MPL_increments'] = Constants.increments p.participant.vars['MPL_no_decisions'] = Constants.no_decisions p.task = Constants.task p.MPL_sequence = p.participant.vars['MPL_sequence'] # MPL basics p.max_amount = p.participant.vars['MPL_max_amount'] p.increments = p.participant.vars['MPL_increments'] p.no_decisions = p.participant.vars['MPL_no_decisions'] class Group(BaseGroup): pass class Player(BasePlayer): task = models.StringField() MPL_sequence = models.StringField() MPL_high_time_spent = models.FloatField(blank=True) MPL_low_time_spent = models.FloatField(blank=True) Instructions_1_time_spent = models.FloatField(blank=True) Instructions_2_time_spent = models.FloatField(blank=True) MPL_Instructions_time_spent = models.FloatField(blank=True) MPL_high_warnings = models.IntegerField() MPL_low_warnings = models.IntegerField() Instructions_1_warnings = models.IntegerField() Instructions_2_warnings = models.IntegerField() MPL_Instructions_warnings = models.IntegerField() ### MPL increments = models.FloatField() max_amount = models.FloatField() no_decisions = models.IntegerField() # Decision numbers last_False_high = models.IntegerField() first_True_high = models.IntegerField() # Decision values last_False_val_high = models.FloatField() first_True_val_high = models.FloatField() # Lists decision_list_high = models.StringField() no_reminder_list_high = models.StringField() reminder_list_high = models.StringField() # Decision numbers last_False_low = models.IntegerField() first_True_low = models.IntegerField() # Decision values last_False_val_low = models.FloatField() first_True_val_low = models.FloatField() # Lists decision_list_low = models.StringField() no_reminder_list_low = models.StringField() reminder_list_low = models.StringField() ## Control questions control_q1 = models.PositiveIntegerField(choices=[ [0,'You will get a recommendation. You will pay the cost listed on the right.'], [1,'You will NOT get a recommendation. You will pay the cost listed on the left.'] ], initial=None, widget=widgets.RadioSelectHorizontal) control_q2 = models.PositiveIntegerField(choices=[ [0,'Only once.'], [1,'Each round.'] ], initial=None, widget=widgets.RadioSelectHorizontal) control_q3 = models.PositiveIntegerField(choices=[i for i in range(Constants.no_decisions-11,Constants.no_decisions+9)],initial=None) def control_q1_error_message(self,value): """Customized error message for control question 1.""" cond = (value != 0) if cond: return 'Your answer is incorrect. Please try again!' def control_q2_error_message(self,value): """Customized error message for control question 2.""" cond = (value != 1) if cond: return 'Your answer is incorrect. Please try again!' #def control_q3_error_message(self,value): # """Customized error message for control question 3.""" # cond = (value != Constants.no_decisions) # if cond: # return 'Your input is incorrect. Please try again!'