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 options 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_IE_DOSE' 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 = 1200 # define scaling of lottery scale = 1 FixedPointsType1 = 2000 ######################################################## ############ DEFINE SHOWUPFEE showup_fee =2 #read & store all lotteries with open('Part1_IE_DOSE/distributions_20increments.csv') as questions_file: questions = list(csv.DictReader(questions_file)) with open('Part1_IE_DOSE/IE_decisiontree_20increments.csv') as decisiontree_file: decisiontree = list(csv.DictReader(decisiontree_file)) #tree = ("Part1_risk_DOSE/decisiontree.xlsx") #tree = ("Part1_risk_DOSE/decisiontree_spicy.xlsx") #tree = ("Part1_risk_DOSE/decisiontree_spicy_9rounds.xlsx") # tree = ("Part1_risk_DOSE/decisiontree_spicy_prolific.xlsx") #tree = ("Part1_risk_DOSE/decisiontree_10rounds.xlsx") #tree = ("Part1_risk_DOSE/decisiontree_spicy_10rounds.xlsx") #tree = ("Part1_risk_DOSE/decisiontree_spicy_10rounds_mu120.xlsx") tree = ("Part1_IE_DOSE/IE_tree_20increments.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 = 10 #num_rounds = 7 # 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): def creating_session(self): if self.round_number == 1: self.session.vars['questions'] = Constants.questions.copy() class Group(BaseGroup): pass class Player(BasePlayer): price_round_selected=models.IntegerField() #### IE parameter IE_parameter = models.FloatField() B_low_indifferent=models.FloatField() #### Choice consistency choice_consistency = models.FloatField() #### payoffs variables # Fixed Points for type 1 participant to perform part 1 FixedPointsType1 = models.IntegerField(initial=2000) Payoff_Participant_1_selected_round = models.FloatField() Payoff_Participant_2_selected_round = models.FloatField() #### selected round for payoff (including high and low payoffs of this lottery) payoffrelevant_round = models.IntegerField() optimal_option = 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-Option variables OptionB_high = models.FloatField() OptionB_low = models.FloatField() # Define A-Option variables OptionA_high = models.FloatField() OptionA_low = models.FloatField() ######################################### # Define Choice variable: This variable will store whether lottery A or B was chosen (in each round) optionchoice = models.IntegerField() ########### DEFINE PRACTICE ROUND VARIABLES ### ########## 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) counterWrong_page1 = models.IntegerField(initial=0) counterWrong_page2 = models.IntegerField(initial=0) ################################################ prolificID = models.StringField() # tab switches & focus-/unfocus-time tab_consent = models.IntegerField() tab_understand = 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_understand = 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_understand = 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()