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 = """ WTP Sequence """ class Constants(BaseConstants): name_in_url = '9H32Dcs53s2g' players_per_group = None num_rounds = 2 num_participants = 10 timeout = 40 play_rounds = 5 #ordering = ['BA','AB'] ### WTP max_amount = 64 no_decisions = 7 # 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) WTP_sequence = ['HighLow','LowHigh'] task = 'WTP_Sequence' num_pwd_tasks = 10 num_math_tasks = 10 class Subsession(BaseSubsession): def creating_session(self): WTP_sequence = Constants.WTP_sequence.copy() # shuffle the list random.shuffle(WTP_sequence) # make a cycle out of the shuffled list WTP_seq = itertools.cycle(WTP_sequence) for p in self.get_players(): # Establishes task ordering & Incentives for Math Task if self.round_number == 1: p.participant.vars['WTP_sequence'] = next(WTP_seq) p.participant.vars['WTP_max_amount'] = Constants.max_amount p.participant.vars['WTP_no_decisions'] = Constants.no_decisions p.task = Constants.task p.WTP_sequence = p.participant.vars['WTP_sequence'] # WTP basics p.max_amount = p.participant.vars['WTP_max_amount'] p.no_decisions = p.participant.vars['WTP_no_decisions'] class Group(BaseGroup): pass class Player(BasePlayer): task = models.StringField() WTP_sequence = models.StringField() ### WTP max_amount = models.FloatField() no_decisions = models.IntegerField() WTP_Dec1 = models.BooleanField() WTP_Dec2 = models.BooleanField() WTP_Dec3 = models.BooleanField() WTP_Dec4 = models.BooleanField() WTP_Dec5 = models.BooleanField() WTP_Dec6 = models.BooleanField() WTP_Dec7 = models.BooleanField() WTP_high_lowest = models.FloatField() WTP_high_highest = models.FloatField() WTP_high_midpoint = models.FloatField() WTP_low_lowest = models.FloatField() WTP_low_highest = models.FloatField() WTP_low_midpoint = models.FloatField() ## Control questions control_q1 = models.PositiveIntegerField( choices=[ [1,'Yes'], [0,'No'] ], widget=widgets.RadioSelectHorizontal, initial=None) 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 '' def control_q2_error_message(self,value): """Customized error message for control question 2.""" cond = (value != 1) if cond: return '' WTP_Dec1_time_spent = models.FloatField(blank=True) WTP_Dec2_time_spent = models.FloatField(blank=True) WTP_Dec3_time_spent = models.FloatField(blank=True) WTP_Dec4_time_spent = models.FloatField(blank=True) WTP_Dec5_time_spent = models.FloatField(blank=True) WTP_Dec6_time_spent = models.FloatField(blank=True) WTP_Dec7_time_spent = models.FloatField(blank=True) Instructions_1_time_spent = models.FloatField(blank=True) WTP_Instructions_time_spent = models.FloatField(blank=True) WTP_Middle_time_spent = models.FloatField(blank=True) WTP_Start_time_spent = models.FloatField(blank=True) WTP_Dec1_warnings = models.IntegerField() WTP_Dec2_warnings = models.IntegerField() WTP_Dec3_warnings = models.IntegerField() WTP_Dec4_warnings = models.IntegerField() WTP_Dec5_warnings = models.IntegerField() WTP_Dec6_warnings = models.IntegerField() WTP_Dec7_warnings = models.IntegerField() Instructions_1_warnings = models.IntegerField() WTP_Instructions_warnings = models.IntegerField() WTP_Middle_warnings = models.IntegerField() WTP_Start_warnings = models.IntegerField() #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!'