from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random from .machine_learning_algo import prediction_generator doc = """ A market game experiment to study learning based on machine learning. Essential market mechanism based on Kuhnen (2015) """ class Constants(BaseConstants): name_in_url = 'machine_teaching_questionnaire' players_per_group = None num_rounds = 1 half_rounds = 6 fixed_payoff = 2 high_payoff = 4 low_payoff = 0 fee = 2 instructions_template = 'Finance_experiment_questionnaire/instructions_.html' class Subsession(BaseSubsession): def creating_session(self): for g in self.get_players(): g.treat_ = abs((g.id_in_group % 2) - 1) #abs((g.id_in_group % 2) - 1) temp_ = (0 if int(random.Random(g.id_in_group).uniform(0, 1) // 0.5) == 0 else 1) # [1,2,3,4,5,6,7,8,9,10] # random.Random(g.id_in_group).shuffle(temp_) # print(temp_[0]) if temp_ == 1: pics = ['image.jpeg', 'image-2.jpeg', 'image-3.jpeg', 'image-4.jpeg'] elif temp_ == 0: pics = ['imageW.jpeg', 'image-2W.jpeg', 'image-3W.jpeg', 'image-4W.jpeg'] random.Random(g.id_in_group).shuffle(pics) g.exp1 = pics[0] g.exp2 = pics[1] g.exp3 = pics[2] g.exp4 = pics[3] class Group(BaseGroup): pass #################### # QUESTIONNAIRE #################### class Player(BasePlayer): # images exp1 = models.StringField() exp2 = models.StringField() exp3 = models.StringField() exp4 = models.StringField() # treatment or baseline condition treat_ = models.IntegerField(initial=-1) #################### # QUESTIONNAIRE #################### ##### GENERAL q_age = models.IntegerField(label='How old are you?') q_female = models.IntegerField(label='Please indicate your gender.', choices=[ [0, 'Male'], [1, 'Female'], [-1, 'Other'], ], widget=widgets.RadioSelect ) q_work = models.IntegerField(label='How many years of working experience do you have?') # q_news = models.IntegerField(label='How many newspaper subscriptions do you have?', # choices=[ # [0, 'None'], # [1, '1-2'], # [2, '3-5'], # [3, 'More than 5'], # ], # widget=widgets.RadioSelect # ) q_degree = models.IntegerField(label='Please indicate your highest degree.', choices=[ [0, 'No graduation'], [1, 'Secondary school'], [2, 'High school'], [3, 'Bachelor'], [4, 'Master/ Diploma'], [5, 'Ph.D.'], ], widget=widgets.RadioSelect ) ##### RISK AVERSION q_risk_aversion_1 = models.IntegerField( label='I enjoy being daring', choices=[ [1, '1 (I completely disagree)'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7 (I completely agree)'], ], widget=widgets.RadioSelect ) q_risk_aversion_2 = models.IntegerField( label='I take risks', choices=[ [1, '1 (I completely disagree)'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7 (I completely agree)'], ], widget=widgets.RadioSelect ) q_risk_aversion_3 = models.IntegerField( label='I am looking for danger', choices=[ [1, '1 (I completely disagree)'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7 (I completely agree)'], ], widget=widgets.RadioSelect ) # q_risk_aversion_4 = models.IntegerField( # label='I know how to get around the rules', # choices=[ # [1, '1 (I completely disagree)'], # [2, '2'], # [3, '3'], # [4, '4'], # [5, '5'], # [6, '6'], # [7, '7 (I completely agree)'], # ], # widget=widgets.RadioSelect # ) # q_risk_aversion_5 = models.IntegerField( # label='I am ready to try everything out', # choices=[ # [1, '1 (I completely disagree)'], # [2, '2'], # [3, '3'], # [4, '4'], # [5, '5'], # [6, '6'], # [7, '7 (I completely agree)'], # ], # widget=widgets.RadioSelect # ) # q_risk_aversion_6 = models.IntegerField( # label='I am looking fo adventure', # choices=[ # [1, '1 (I completely disagree)'], # [2, '2'], # [3, '3'], # [4, '4'], # [5, '5'], # [6, '6'], # [7, '7 (I completely agree)'], # ], # widget=widgets.RadioSelect # ) ##### Alo aversion q_algo_aversion_1 = models.IntegerField( label='I am familiar with Prediction Software providing information.', choices=[ [1, '1 (I completely disagree)'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7 (I completely agree)'], ], widget=widgets.RadioSelect ) q_algo_aversion_2 = models.IntegerField( label='I am familiar with the process of the Prediction Software providing estimations.', choices=[ [1, '1 (I completely disagree)'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7 (I completely agree)'], ], widget=widgets.RadioSelect ) q_algo_aversion_3 = models.IntegerField( label='I am familiar with receiving estimations from the Prediction Software.', choices=[ [1, '1 (I completely disagree)'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7 (I completely agree)'], ], widget=widgets.RadioSelect ) q_algo_aversion_4 = models.IntegerField( label='Overall, I am familiar with the Prediction Software.', choices=[ [1, '1 (I completely disagree)'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7 (I completely agree)'], ], widget=widgets.RadioSelect ) ##### Technology anxiety q_tech_anxiety_1 = models.IntegerField( label='I feel apprehensive about using technology', choices=[ [1, '1 (I completely disagree)'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7 (I completely agree)'], ], widget=widgets.RadioSelect ) q_tech_anxiety_2 = models.IntegerField( label='Technical terms sound like confusing jargon to me', choices=[ [1, '1 (I completely disagree)'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7 (I completely agree)'], ], widget=widgets.RadioSelect ) q_tech_anxiety_3 = models.IntegerField( label='I have avoided technology because it is unfamiliar to me', choices=[ [1, '1 (I completely disagree)'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7 (I completely agree)'], ], widget=widgets.RadioSelect ) q_tech_anxiety_4 = models.IntegerField( label='I hesitate to use most forms of technology for fear of making mistakes I cannot correct', choices=[ [1, '1 (I completely disagree)'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7 (I completely agree)'], ], widget=widgets.RadioSelect ) ##### Financial knowledge q_finance_1 = models.IntegerField( label='How knowledgeable are you about investment decisions?', choices=[ [1, 'Not at all knowledgeable'], [2, 'Not very knowledgeable'], [3, 'Moderately knowledgeable'], [4, 'Fairly knowledgeable'], [5, 'Very knowledgeable'], ], widget=widgets.RadioSelect ) # q_finance_2 = models.IntegerField( # label='If long-term interest rates were to rise, what effect do you think this would have on the value of a fund invested in fixed income securities (Bonds)?', # choices=[ # [1, 'Value of bonds would rise'], # [2, 'Value of bonds would fall'], # [3, 'Value of fund would stay the same'], # [4, 'I do not know'], # ], # widget=widgets.RadioSelect # ) # # q_finance_3 = models.IntegerField( # label='If an investment earns a return of 7% per year, roughly how long do you think it will take for the value of that investment to double?', # choices=[ # [1, '5 Years'], # [2, '10 Years'], # [3, '15 Year'], # [4, '20 Years'], # [5, 'I do not know'], # ], # widget=widgets.RadioSelect # ) ##### LOSS AVERSION # # q_loss_aversion_1 = models.IntegerField( # label='If the coin turns up heads, then you lose 2 Euros; if the coin turns up tails, you win 6 Euros', # choices=[ # [1, 'Accept'], # [0, 'Reject'], # ], # widget=widgets.RadioSelect # ) # # q_loss_aversion_2 = models.IntegerField( # label='If the coin turns up heads, then you lose 3 Euros; if the coin turns up tails, you win 6 Euros', # choices=[ # [1, 'Accept'], # [0, 'Reject'], # ], # widget=widgets.RadioSelect # ) # # q_loss_aversion_3 = models.IntegerField( # label='If the coin turns up heads, then you lose 4 Euros; if the coin turns up tails, you win 6 Euros', # choices=[ # [1, 'Accept'], # [0, 'Reject'], # ], # widget=widgets.RadioSelect # ) # # q_loss_aversion_4 = models.IntegerField( # label='If the coin turns up heads, then you lose 5 Euros; if the coin turns up tails, you win 6 Euros', # choices=[ # [1, 'Accept'], # [0, 'Reject'], # ], # widget=widgets.RadioSelect # ) # # q_loss_aversion_5 = models.IntegerField( # label='If the coin turns up heads, then you lose 6 Euros; if the coin turns up tails, you win 6 Euros', # choices=[ # [1, 'Accept'], # [0, 'Reject'], # ], # widget=widgets.RadioSelect # ) # # q_loss_aversion_6 = models.IntegerField( # label='If the coin turns up heads, then you lose 7 Euros; if the coin turns up tails, you win 6 Euros', # choices=[ # [1, 'Accept'], # [0, 'Reject'], # ], # widget=widgets.RadioSelect # ) # # q_risk_aversion = models.IntegerField( # label='Please tell us, in general, how willing or unwilling you are to take risks, using a scale from 1 to 7, where 1 means you are completely unwilling to take risks and 10 means you are very willing to take risks. You can also use any number between 0 and 10 to indicate where you fall on the scale, using 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, or 10.', # choices=[ # [0, '0'], # [1, '1 (I completely disagree)'], # [2, '2'], # [3, '3'], # [4, '4'], # [5, '5'], # [6, '6'], # [7, '7 (I completely agree)'], # [8, '8'], # [9, '9'], # [10, '10'], # ], # widget=widgets.RadioSelect # ) trusting_human = models.IntegerField(label='I am willing to rely on advice from an external source, if this source is another human.', choices = [[1, '1 (I completely disagree)'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7 (I completely agree)'], ], widget=widgets.RadioSelect ) trusting_machine = models.IntegerField(label='I am willing to rely on advice from an external source, if this source is an algorithm/ machine learning system.', choices = [[1, '1 (I completely disagree)'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7 (I completely agree)'], ], widget=widgets.RadioSelect ) q_cs_study = models.IntegerField(label='Do you have a background in computer science?', choices=[ [0, 'No'], [1, 'Yes'], ], widget=widgets.RadioSelect ) q_coding_skill = models.IntegerField( label='Please tell us, in general, about your programming skills, ' 'using a scale from 0 to 10, where 0 means no skills at all and 10 means expert. ' 'You can also use any number between 0 and 10 to indicate where you fall on the scale, using 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, or 10.', choices=[ [0, '0'], [1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7 '], [8, '8'], [9, '9'], [10, '10'], ], widget=widgets.RadioSelect ) ml_knowledge = models.IntegerField( label='Please tell us, in general, about your familiarity with machine learning applications, ' 'using a scale from 0 to 10, where 0 means not familiar at all and 10 means completely familiar. ' 'You can also use any number between 0 and 10 to indicate where you fall on the scale, using 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, or 10.', choices=[ [0, '0'], [1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7 '], [8, '8'], [9, '9'], [10, '10'], ], widget=widgets.RadioSelect ) # # q_subscr = models.IntegerField(label='How many different subscriptions of digital services do you have (e.g. Amazon Prime, Netflix, Spotify, Disney+,...)?') #################### # TRIALS #################### trial_1 = models.IntegerField(initial=-1, label='I invest into the', choices=[ [0, 'Bond'], [1, 'Stock'], ], widget=widgets.RadioSelect ) trial_2 = models.IntegerField(initial=-1, label='I invest into the', choices=[ [0, 'Bond'], [1, 'Stock'], ], widget=widgets.RadioSelect )