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,from a CSV-file, the list of all potential options that type 1 participants may face t in part1 of the experiments. Then type 3 decides between option A and Band exports the decision. There is 1 decision per page; the number of pages is 39. There are 6 participants type 3. Therefore, 234 decisions. """ class Constants(BaseConstants): name_in_url = 'Type3_part2' 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 = '£' num_rounds=1 #currency_real = 'CHF' # define exchange rate 1 ECU = xxx $ = xxx CHF XR = 1200 # define scaling of lottery scale = 1 ######################################################## ############ DEFINE SHOWUPFEE showup_fee = 0.5 FixedPointsType1 = 2000 FixedPointsType2 = 2000 TotalPayoffType2=3.67 with open('Type3_part2/type3.csv') as decisions_file: questions = list(csv.DictReader(decisions_file)) class Subsession(BaseSubsession): def creating_session(self): if self.round_number == 1: self.session.vars['questions'] = Constants.questions.copy() for player in self.get_players(): player.set_participant() class Group(BaseGroup): pass class Player(BasePlayer): Participant = models.IntegerField() def set_participant(self): if self.id_in_group in [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,83,85,87,89,91,93,95,97,99]: self.Participant = 1 if self.id_in_group in [2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100]: self.Participant = 2 payoff=Constants.TotalPayoffType2 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 check_correct(self): self.is_correct = (self.submitted_answer == self.solution)