from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import csv import xlrd # for reading XLS-files author = 'Dr. Jana Freundt & Leander Kopp' doc = """ This app reads 2 lotteries from a CSV-file and exports the decision. A prototype_Part2 app that reads its questions from a spreadsheet (see lotteries.csv in this directory). There is 1 decision per page; the number of pages in the game is determined by the number of decisions in the CSV. """ class Constants(BaseConstants): name_in_url = 'Part1_FEMALE' players_per_group = None ############ LANGUAGE SETTINGS # 1: english, 2:german, 3:french..... language_code=1 ############ DEFINE CURRENCY, XRs AND LOTTERYSCALING ### # define displayed currency currency='points' #currency='CHF' currency_real='£' # define exchange rate 1 ECU = xxx $ = xxx CHF XR = 0.01 XR = 0.001 XR = 0.00075 # define scaling of lottery scale = 1 ######################################################## ############ DEFINE SHOWUPFEE showup_fee = 2666.66 #read & store all lotteries with open('Part1_FEMALE/lotteries.csv') as questions_file: questions = list(csv.DictReader(questions_file)) with open('Part1_FEMALE/decisiontree.csv') as decisiontree_file: decisiontree = list(csv.DictReader(decisiontree_file)) #tree = ("Part1_FEMALE/decisiontree.xlsx") #tree = ("Part1_FEMALE/decisiontree_spicy.xlsx") #tree = ("Part1_FEMALE/decisiontree_spicy_9rounds.xlsx") # tree = ("Part1_FEMALE/decisiontree_spicy_prolific.xlsx") #tree = ("Part1_FEMALE/decisiontree_10rounds.xlsx") #tree = ("Part1_FEMALE/decisiontree_spicy_10rounds.xlsx") #tree = ("Part1_FEMALE/decisiontree_spicy_10rounds_mu120.xlsx") tree = ("Part1_FEMALE/tree.xlsx") # To open Workbook wb = xlrd.open_workbook(tree) sheet = wb.sheet_by_index(0) # Get for every stage all optimal lotteries (row,column) num_rounds = len(questions) num_rounds = 10 # 10 rounds for DOSE # prepare numbers for along the binary decision tree shift=[256,128,64,32,16,8,4,2,1] class Subsession(BaseSubsession): democrat_count = models.IntegerField(initial=0) republican_count = models.IntegerField(initial=0) exclusion_count = models.IntegerField(initial=0) male_count = models.IntegerField(initial=0) female_count = models.IntegerField(initial=0) def creating_session(self): if self.round_number == 1: self.session.vars['questions'] = Constants.questions.copy() class Group(BaseGroup): pass class Player(BasePlayer): #### Risk parameter risk_parameter = models.FloatField() #### Choice consistency choice_consistency = models.FloatField() #### payoff variable payoff_part1 = models.FloatField() #### selected round for payoff (including high and low payoffs of this lottery) payoffrelevant_round = models.IntegerField() payoffrelevant_round_part1_low = models.FloatField() payoffrelevant_round_part1_high = models.FloatField() optimal_lottery = models.IntegerField() #tree_row = models.IntegerField(initial=128) # set the initial row of the optimal lottery from the binary tree #tree_row = models.IntegerField(initial=256) # set the initial row of the optimal lottery from the binary tree tree_row = models.IntegerField(initial=512) # set the initial row of the optimal lottery from the binary tree ############ DEFINE LOTTERY VARIABLES ### # Define B-Lottery variables lotteryB_high = models.FloatField() lotteryB_low = models.FloatField() probB_low = models.FloatField() probB_high = models.FloatField() # Define A-Lottery variables lotteryA_high = models.FloatField() lotteryA_low = models.FloatField() probA_low = models.FloatField() probA_high = models.FloatField() ######################################### # Define Choice variable: This variable will store whether lottery A or B was chosen (in each round) lotterychoice = models.IntegerField() ########### DEFINE PRACTICE ROUND VARIABLES ### roundsA = models.IntegerField() draws_highA = models.IntegerField() roundsB = models.IntegerField() draws_highB = models.IntegerField() ############################################### ########## DEFINE CONTROL QUESTION VARIABLES ### ControlQuestion1 = models.IntegerField() ControlQuestion2 = models.IntegerField() ControlQuestion3 = models.IntegerField() ControlQuestion4 = models.IntegerField() # counter for control questions counterWrong = models.IntegerField(initial=0) ################################################ prolificID = models.StringField() exclusion = models.IntegerField(initial=0) # tab switches & focus-/unfocus-time tab_consent = models.IntegerField() tab_instructions_general_part1 = models.IntegerField() tab_intro_title_part1 = models.IntegerField() tab_desc_lotteries_part1 = models.IntegerField() tab_practice_part1 = models.IntegerField() tab_desc_rlim_part1 = models.IntegerField() tab_pre_question_part1 = models.IntegerField() tab_question_part1 = models.IntegerField() tab_end_part1 = models.IntegerField() # tab switches & focus-/unfocus-time focus_consent = models.FloatField() focus_instructions_general_part1 = models.FloatField() focus_intro_title_part1 = models.FloatField() focus_desc_lotteries_part1 = models.FloatField() focus_practice_part1 = models.FloatField() focus_desc_rlim_part1 = models.FloatField() focus_pre_question_part1 = models.FloatField() focus_question_part1 = models.FloatField() focus_end_part1 = models.FloatField() # tab switches & focus-/unfocus-time totaltime_consent = models.FloatField() totaltime_instructions_general_part1 = models.FloatField() totaltime_intro_title_part1 = models.FloatField() totaltime_desc_lotteries_part1 = models.FloatField() totaltime_practice_part1 = models.FloatField() totaltime_desc_rlim_part1 = models.FloatField() totaltime_pre_question_part1 = models.FloatField() totaltime_question_part1 = models.FloatField() totaltime_end_part1 = models.FloatField() gender = models.IntegerField( choices=[[1, 'Male'], [2, 'Female'], [3, 'Do not wish to answer']], verbose_name="", widget=widgets.RadioSelect ) affiliation = models.IntegerField( choices=[[1, 'Democrat'], [2, 'Republican'], [5, 'Independent'], [3, 'Other'],[4, 'None']], verbose_name="", widget=widgets.RadioSelect ) independent = models.StringField( choices=[[1, 'Democratic Party'], [2, 'Neither'], [3, 'Republican Party']], verbose_name="", widget=widgets.RadioSelect ) strength = models.StringField( choices=[ [1, 'Not at all strongly'], [2, 'Not very strongly'], [3, 'Average'], [4, 'Somewhat strongly'], [5, 'Very strongly']], verbose_name="", widget=widgets.RadioSelect ) picture = models.StringField( choices=[[1, 'Green Picture'], [2, 'Blue Picture']], verbose_name="", widget=widgets.RadioSelect ) age = models.IntegerField( choices=[(age, str(age)) for age in range(18, 99)], verbose_name="" ) allstates = models.IntegerField( choices=[ [1, 'Alabama'], [2, 'Alaska'], [3, 'Arizona'], [4, 'Arkansas'], [5, 'California'], [6, 'Colorado'], [7, 'Connecticut'], [8, 'Delaware'], [9, 'Florida'], [10, 'Georgia'], [11, 'Hawaii'], [12, 'Idaho'], [13, 'Illinois'], [14, 'Indiana'], [15, 'Iowa'], [16, 'Kansas'], [17, 'Kentucky'], [18, 'Louisiana'], [19, 'Maine'], [20, 'Maryland'], [21, 'Massachusetts'], [22, 'Michigan'], [23, 'Minnesota'], [24, 'Mississippi'], [25, 'Missouri'], [26, 'Montana'], [27, 'Nebraska'], [28, 'Nevada'], [29, 'New Hampshire'], [30, 'New Jersey'], [31, 'New Mexico'], [32, 'New York'], [33, 'North Carolina'], [34, 'North Dakota'], [35, 'Ohio'], [36, 'Oklahoma'], [37, 'Oregon'], [38, 'Pennsylvania'], [39, 'Rhode Island'], [40, 'South Carolina'], [41, 'South Dakota'], [42, 'Tennessee'], [43, 'Texas'], [44, 'Utah'], [45, 'Vermont'], [46, 'Virginia'], [47, 'Washington'], [48, 'West Virginia'], [49, 'Wisconsin'], [50, 'Wyoming'] ], verbose_name="" )