from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) import csv import math author = 'Francisco Gomez Martinez' doc = """ This app reads a list of all potential options that type 1 participants are indifferent in part1 from a CSV-file and exports the decision. 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 = 'Part2_type2' 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 = '$' #currency_real = 'CHF' # define exchange rate 1 ECU = xxx $ = xxx CHF XR = 1000 # define scaling of lottery scale = 1 ######################################################## ############ DEFINE SHOWUPFEE showup_fee = 2 FixedPointsType1 = 2000 FixedPointsType3 = 2000 TotalPayoffType2=4 with open('Part2_type2/type2.csv') as decisions_file: questions = list(csv.DictReader(decisions_file)) num_rounds = 39 class Subsession(BaseSubsession): def creating_session(self): if self.round_number == 1: self.session.vars['questions'] = Constants.questions.copy() for p in self.get_players(): question_data = p.current_question() # Read B-Lotteries p.optionB_low = float(question_data['Blow']) p.optionB_high = float(question_data['Bhigh']) # Read A-Lotteries p.optionA_low = float(question_data['Alow']) p.optionA_high = float(question_data['Ahigh']) # Read UserID p.decision_round_type2 = str(question_data['decision_round_type2']) class Group(BaseGroup): pass class Player(BasePlayer): question_id = models.IntegerField() question = models.StringField() solution = models.StringField() # filename for CSV-export file filename = models.StringField() ############ DEFINE LOTTERY VARIABLES ### # Define B-Lottery variables optionB_high = models.FloatField() optionB_low = models.FloatField() # Define A-Lottery variables optionA_high = models.FloatField() optionA_low = models.FloatField() # Define B-Lottery variables # Define User-ID userID = models.StringField() decision_round_type2=models.StringField() # Define Choice variable # Define outcome variable outcome = models.StringField() ######################################### optionchoice = models.IntegerField() optionchoicetype2 = models.IntegerField() submitted_answer = models.StringField(widget=widgets.RadioSelect) ########## DEFINE CONTROL QUESTION VARIABLES ### ControlQuestion1 = models.IntegerField() ControlQuestion2 = models.IntegerField() ControlQuestion3 = models.IntegerField() ControlQuestion4 = models.IntegerField() # counter for control questions counterWrong_page1 = models.IntegerField(initial=0) ################################################ prolificID = models.StringField() tab_consent = models.IntegerField() tab_intro_title_part1 = models.IntegerField() tab_desc_lotteries_part1 = models.IntegerField() tab_question_part1 = models.IntegerField() tab_end_part1 = models.IntegerField() # tab switches & focus-/unfocus-time focus_consent = models.FloatField() focus_intro_title_part1 = models.FloatField() focus_desc_lotteries_part1 = models.FloatField() focus_question_part1 = models.FloatField() focus_end_part1 = models.FloatField() # tab switches & focus-/unfocus-time totaltime_consent = models.FloatField() totaltime_intro_title_part1 = models.FloatField() totaltime_desc_lotteries_part1 = models.FloatField() totaltime_question_part1 = models.FloatField() totaltime_end_part1 = models.FloatField() ###### display display = models.BooleanField(initial=False) def submitted_answer_choices(self): qd = self.current_question() return [ qd['A'], qd['B'], 1, ] def current_question(self): if self.id_in_group == 1: return self.session.vars['questions'][self.round_number - 1] if self.id_in_group == 2: return self.session.vars['questions'][self.round_number - 194 ] if self.id_in_group == 3: return self.session.vars['questions'][self.round_number - 155 ] if self.id_in_group == 4: return self.session.vars['questions'][self.round_number - 117] if self.id_in_group == 5: return self.session.vars['questions'][self.round_number - 78] if self.id_in_group == 6: return self.session.vars['questions'][self.round_number - 40 ] def check_correct(self): self.is_correct = (self.submitted_answer == self.solution)