from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) from otree.common import safe_json import csv import random author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'ExperimentCS' players_per_group = None #num_rounds = 1 with open('ExperimentCS/OTreeTest.csv') as abfragen_file: Abfragen = list(csv.DictReader(abfragen_file)) num_rounds = len(Abfragen) StandardChoices=[ [1, 'Disagree strongly'], [2, 'Disagree moderately'], [3, 'Disagree a little'], [4, 'Neither agree nor disagree'], [5, 'Agree a little'], [6, 'Agree moderately'], [7, 'Agree strongly'], ] class Subsession(BaseSubsession): def creating_session(self): if self.round_number == 1: self.session.vars['Abfragen'] = Constants.Abfragen.copy() ## ALTERNATIVE DESIGN: ## to randomize the order of the questions, you could instead do: randomized_Abfragen = random.sample(Constants.Abfragen, len(Constants.Abfragen)) self.session.vars['Abfragen'] = randomized_Abfragen ## and to randomize differently for each participant, you could use ## the random.sample technique, but assign into participant.vars ## instead of session.vars. #Auswahl einer der vier Szenarien #rndSzenario = random.randint(1, 4) #print('Szenario',rndSzenario) for p in self.get_players(): abfragen_data = p.current_question() p.question_id = int(abfragen_data['id']) p.A1S1Ziel1 = float(abfragen_data['A1S1Ziel1']) p.A1S1Ziel2 = float(abfragen_data['A1S1Ziel2']) p.A1S2Ziel1 = float(abfragen_data['A1S2Ziel1']) p.A1S2Ziel2 = float(abfragen_data['A1S2Ziel2']) p.A1S3Ziel1 = float(abfragen_data['A1S3Ziel1']) p.A1S3Ziel2 = float(abfragen_data['A1S3Ziel2']) p.A1S4Ziel1 = float(abfragen_data['A1S4Ziel1']) p.A1S4Ziel2 = float(abfragen_data['A1S4Ziel2']) p.A2S1Ziel1 = float(abfragen_data['A2S1Ziel1']) p.A2S1Ziel2 = float(abfragen_data['A2S1Ziel2']) p.A2S2Ziel1 = float(abfragen_data['A2S2Ziel1']) p.A2S2Ziel2 = float(abfragen_data['A2S2Ziel2']) p.A2S3Ziel1 = float(abfragen_data['A2S3Ziel1']) p.A2S3Ziel2 = float(abfragen_data['A2S3Ziel2']) p.A2S4Ziel1 = float(abfragen_data['A2S4Ziel1']) p.A2S4Ziel2 = float(abfragen_data['A2S4Ziel2']) #randomisierte Variablen für die Auszahlung if self.round_number == 1: p.rndSzenario = random.randint(1, 4) print('Szenario',p.rndSzenario) p.rndAbfrage = random.randint(1, len(randomized_Abfragen)) print('Abfrage', p.rndAbfrage) # definieren der daten für die Graphiken #https://github.com/chapkovski/plotting-graphs-in-otree/blob/master/networx/models.py #https://groups.google.com/forum/#!searchin/otree/scatter$20plot%7Csort:date/otree/J8h8tFthnAM/8szqts-UBgAJ class Group(BaseGroup): pass class Player(BasePlayer): #Demographics gender = models.IntegerField( label="Please select your gender.", choices=[ [1, 'Male'], [2, 'Female'], [3, 'Other'], [4, 'I prefer not to say.'], ] ) age = models.IntegerField(label="Please enter your age.", min=14, max=90, blank=True) studies = models.IntegerField( label="Please estimate how many studies you have participated in (excluding this study)", choices=[ [1, 'Less than 5 studies'], [2, 'Between 5 and less than 10 studies.'], [3, 'between 10 and less than 15 studies.'], [4, '15 or more studies.'], [5, 'I prefer not to say.'] ] ) workexperience = models.IntegerField( label="Please indicate your work experience. All jobs count, including part-time and volunteer work.", choices=[ [1, 'I do not have work experience.'], [2, 'Less than 1 year work experience.'], [3, 'Between 1 and less than 2 years of work experience'], [4, 'Between 2 and less than 3 years work experience.'], [5, 'Between 3 and less than 4 years work experience.'], [6, 'Between 4 and less than 5 years work experience.'], [7, '5 years or more work experience.'], [8, 'I prefer not to say.'], ] ) degree = models.IntegerField( label="Please indicate the highest academic degree you have completed. If you are currently actively pursuing one, please select that academic degree.", choices=[ [1, 'High school or lower'], [2, 'Bachelor degree'], [3, 'Master degree'], [4, 'PhD degree'], [5, 'MBA degree'], [6, 'Other'], [7, 'I prefer not to say.'] ] ) english = models.IntegerField( label="Please rate your English on a percentage scale between 0 and 100.", min=0, max=100, blank=True, initial=None ) #############demographics #age = models.IntegerField( # label='What is your age?', # min=13, max=125) #gender = models.StringField( # choices=['Female', 'Male', 'Other'], # label='What is your gender?', # widget=widgets.RadioSelectHorizontal) education = models.StringField( choices=['Social Sciences and Economics', 'Literature', 'Science', 'Others'], label='What is your field of study?', widget=widgets.RadioSelect ) lab_exp = models.IntegerField( choices=[[1, 'Yes'], [0, 'No']], label='Have you already participated into any lab experiment before?', widget=widgets.RadioSelect ) hob_game = models.IntegerField( choices=[[1, 'Yes'], [0, 'No']], label='Do you play games as a hobby?', widget=widgets.RadioSelect ) game_how_often = models.StringField( choices=['None', 'Barely', 'Once a week', 'More often than once a week', 'Almost everyday'], label='How often do you play games?', widget=widgets.RadioSelect ) def make_field_risk(fosho, heads): return models.IntegerField( choices=[[1, f'${fosho}'], [2, f'A fair coin flip in which you get ${heads} if it is heads, $0 if it is tails.']], label='Which do you prefer?', widget=widgets.RadioSelect, ) #############Risk Aversion risk1 = make_field_risk('50', '200') risk2 = make_field_risk('75', '200') risk3 = make_field_risk('100', '200') risk4 = make_field_risk('125', '200') risk5 = make_field_risk('150', '200') #############Ambiguity Aversion amb = models.IntegerField( choices=[[1, """ Lottery A: There are 100 balls in a box. You know that 50 of them are black and 50 of them are red. If you draw a red one, you get $10; if you draw a black one, you pay $10."""], [2, """ Lottery B: There are 100 balls in a box. You know that they are black and red but you don’t know how many of them are red or black. If you draw a red one, you get $10; if you draw a black one, you pay $10."""]], label=''' Which lottery will you prefer to participate?''', widget=widgets.RadioSelect ) #Variablen für die Abfrage submitted_answer = models.IntegerField( label="Wählen Sie eine Alternative aus:", choices=[[1, 'Alternative 1'],[2, 'Alternative 2']], widget= widgets.RadioSelect ) question_id = models.IntegerField() A1S1Ziel1 = models.FloatField() A1S1Ziel2 = models.FloatField() A1S2Ziel1 = models.FloatField() A1S2Ziel2 = models.FloatField() A1S3Ziel1 = models.FloatField() A1S3Ziel2 = models.FloatField() A1S4Ziel1 = models.FloatField() A1S4Ziel2 = models.FloatField() A2S1Ziel1 = models.FloatField() A2S1Ziel2 = models.FloatField() A2S2Ziel1 = models.FloatField() A2S2Ziel2 = models.FloatField() A2S3Ziel1 = models.FloatField() A2S3Ziel2 = models.FloatField() A2S4Ziel1 = models.FloatField() A2S4Ziel2 = models.FloatField() #Randomisierte Größen für Auszahlung rndSzenario = models.IntegerField() rndAbfrage = models.IntegerField() def current_question(self): return self.session.vars['Abfragen'][self.round_number - 1] # return self.session.vars['Alternative2'][self.round_number-1] def Alternativen(self): self.session.vars['Alternative1']=[[self.A1S1Ziel1,self.A1S1Ziel2],[self.A1S2Ziel1,self.A1S2Ziel2],[self.A1S3Ziel1,self.A1S3Ziel2],[self.A1S4Ziel1,self.A1S4Ziel2]] print('Test1',self.participant.vars['Alternative1'])