from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) from django import forms import random author = 'Your name here' doc = """ Your app description """ def eval_answer(answer, answer_correct): q = random.randint(0, 100) rnd = random.randint(0, 100) elicit_win = False if q <= answer and rnd <= answer_correct: elicit_win = True if q > answer and rnd <= q: elicit_win = True return elicit_win class Constants(BaseConstants): name_in_url = 'survey' players_per_group = None num_rounds = 1 slider_min = 1 slider_max = 7 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): # Polific ID prolific_id = models.StringField() # Payoffs eval_elicit = models.StringField() bonus_elicit = models.FloatField() eval_portfolio = models.StringField() eval_portfolio_round = models.IntegerField() bonus_portfolio = models.FloatField() # Save all info participant_vars = models.StringField() session_vars = models.StringField() # Demographic questions #q_age = models.IntegerField( # label='Age:', # min=10, # max=100 #) #q_gender = models.StringField( # label='Gender:', # choices=['Male', 'Female', 'Other'] #) #q_race = models.StringField( # label='Ethnic origin:', # choices=['White', 'Hispanic or Latino', 'Black or African American', 'Native American or American Indian', # 'Asian / Pacific Islander', 'Other'] #) #q_language = models.StringField( # label='Is English your first language?', # choices=['Yes', 'No'] #) #q_education = models.StringField( # label='Highest degree or level of school (if currently enrolled, highest degree received):', # choices=['Less than high school degree', 'High school degree or equivalent (e.g., GED)', # 'Some college but no degree', 'Bachelor degree', 'Graduate degree'] #) q_education_US = models.StringField( label='Where did you attend high school?', choices=['United States', 'United Kingdom', 'Other country'] ) #q_marital_status = models.StringField( # label='Marital status:', # choices=['Single, never married', 'Married or domestic partnership', 'Widowed', 'Divorced', 'Separated', # 'Other'] #) #q_children = models.StringField( # label='Number of children', # choices=['0', '1', '2', '3', 'More than 3'] #) #q_employment = models.StringField( # label='Employment status (besides working on Mturk):', # choices=['Employed, working 1-39 hours per week', 'Employed, working 40 or more hours per week', # 'Not employed, looking for work', 'Not employed, NOT looking for work', 'Student', 'Retired', # 'Unable to work', 'Other'] #) #q_income = models.StringField( # label='Total household income in 2018:', # choices=['$0 – $9,999', '$10,000 – $19,999', '$20,000 – $29,999', '$30,000 – $39,999', '$40,000 – $49,999', # '$50,000 – $59,999', '$60,000 – $69,999', '$70,000 – $79,999', '$80,000 – $89,999', # '$90,000 – $99,999', '$100,000 or more'] #) q_browser = models.StringField( choices=['Chrome', 'Edge / Internet Explorer', 'Firefox', 'Safari', 'Opera', 'Mobile phone', 'Other' ], label="Which browser did you use?" ) # Experience q_finance_involved = models.IntegerField( label='How much are you involved in the financial decisions within your household? ' '(' + str(Constants.slider_min) + ': Not involved at all, ' + str(Constants.slider_max) + ': Fully responsible)', min=Constants.slider_min, max=Constants.slider_max, widget=widgets.Slider(attrs={'step': '1'}, show_value=True) ) q_finance_decisions = models.StringField( label='What kind of financial decisions do you make?', widget=forms.CheckboxSelectMultiple(choices=(("durable", "Spending on non-durable goods"), ("non_durable", "Spending on durable goods"), ("saving", "Savings"), ("investment", "Investments"), ("other", "Other"), ("none", "None") ) ) ) q_same_experiment = models.StringField( label='Have you participated in similar experiments before?', choices=['Yes', 'No'] ) # Personality q_risk_preference = models.IntegerField( label='I am a person willing to take risks.', min=Constants.slider_min, max=Constants.slider_max, widget=widgets.Slider(attrs={'step': '1'}, show_value=True) ) q_math = models.IntegerField( label='I am good in math.', min=Constants.slider_min, max=Constants.slider_max, widget=widgets.Slider(attrs={'step': '1'}, show_value=True) ) q_optimism = models.IntegerField( label='I am an optimistic person.', min=Constants.slider_min, max=Constants.slider_max, widget=widgets.Slider(attrs={'step': '1'}, show_value=True) ) q_confidence = models.IntegerField( label='I am a confident person.', min=Constants.slider_min, max=Constants.slider_max, widget=widgets.Slider(attrs={'step': '1'}, show_value=True) ) q_recognize_errors = models.IntegerField( label='I find it hard to recognize my errors.', min=Constants.slider_min, max=Constants.slider_max, widget=widgets.Slider(attrs={'step': '1'}, show_value=True) ) q_competitive = models.IntegerField( label='I am a competitive person.', min=Constants.slider_min, max=Constants.slider_max, widget=widgets.Slider(attrs={'step': '1'}, show_value=True) ) q_enjoy_winning = models.IntegerField( label='I enjoy very much winning in a game.', min=Constants.slider_min, max=Constants.slider_max, widget=widgets.Slider(attrs={'step': '1'}, show_value=True) ) q_regret = models.IntegerField( label='After making a decision, I do not worry about it or regret it.', min=Constants.slider_min, max=Constants.slider_max, widget=widgets.Slider(attrs={'step': '1'}, show_value=True) ) # Understanding q_understand = models.IntegerField( label='How clear were the instructions of the study? ' '(' + str(Constants.slider_min) + ': Confusing, ' + str(Constants.slider_max) + ': Clear)', min=Constants.slider_min, max=Constants.slider_max, widget=widgets.Slider(attrs={'step': '1'}, show_value=True) ) q_understand_parts = models.LongStringField( blank=True, label='Which part of the study, if any, was confusing/difficult to understand? Explain why.' ) q_comment = models.LongStringField( blank=True, label='Here you can share any feedback or comments you might have on this study.' ) # Thought process q_puzzle = models.IntegerField( label='How difficult was to decide which industry has better outlook? ' '(' + str(Constants.slider_min) + ': Easy, ' + str(Constants.slider_max) + ': Difficult)', min=Constants.slider_min, max=Constants.slider_max, widget=widgets.Slider(attrs={'step': '1'}, show_value=True) ) q_beliefs = models.IntegerField( label='How difficult was to estimate the portfolios’ chances of paying off? ' '(' + str(Constants.slider_min) + ': Easy, ' + str(Constants.slider_max) + ': Difficult)', min=Constants.slider_min, max=Constants.slider_max, widget=widgets.Slider(attrs={'step': '1'}, show_value=True) ) q_exact = models.StringField( label='Do you think that you should have been able to calculate the answer exactly from the given information?', choices=['Yes', 'No'] ) q_puzzle_to_estimate = models.IntegerField( label='How much did you think about the industry outlooks when you were estimating the portfolios’ chances of ' 'paying off? ' '(' + str(Constants.slider_min) + ': Not at all, ' + str(Constants.slider_max) + ': A lot)', min=Constants.slider_min, max=Constants.slider_max, widget=widgets.Slider(attrs={'step': '1'}, show_value=True) ) q_trust = models.StringField( label='Did you think that chances are likely to be low because the experimenter set them to minimize payoffs?', choices=['Yes', 'No'] ) q_choice = models.IntegerField( label='How difficult was to decide which portfolio is worth choosing? ' '(' + str(Constants.slider_min) + ': Easy, ' + str(Constants.slider_max) + ': Difficult)', min=Constants.slider_min, max=Constants.slider_max, widget=widgets.Slider(attrs={'step': '1'}, show_value=True) ) q_trick = models.StringField( label='Did you think that there must be some trick, so you should choose the portfolio that looks worse?', choices=['Yes', 'No'] ) q_lucky = models.IntegerField( label='How much did you feel disappointed/lucky about the portfolio that was selected for you? ' '(' + str(Constants.slider_min) + ': Disappointed, ' + str(Constants.slider_max) + ': Lucky)', min=Constants.slider_min, max=Constants.slider_max, widget=widgets.Slider(attrs={'step': '1'}, show_value=True) ) q_process = models.LongStringField( label='Walk us through your thought process: How did you estimate the portfolios’ chances of paying off? ' ) def set_payoffs(self): # Question to evaluate: PUZZLE if random.choice(list(range(self.session.vars['N_rounds'] * 4 + 1))) == 0: self.eval_elicit = 'puzzle_solution' elicit_win = eval_answer( answer=self.participant.vars['industries']['puzzle_confidence'], answer_correct=100 ) # industry_correct = [self.participant.vars['industries'][i]['name'] # for i in self.session.vars['industries']['labels'] # if self.participant.vars['industries'][i]['type'] == 'Ind_good'][0] # # industry_correct = 'Eclipse' # puzzle_eval = random.choice(['puzzle_solution', 'puzzle_confidence']) # # if puzzle_eval == 'puzzle_solution': # self.eval_elicit = 'puzzle_solution' # elicit_win = industry_correct == self.participant.vars['industries']['puzzle_solution'] # # elif puzzle_eval == 'puzzle_confidence': # self.eval_elicit = 'puzzle_confidence' # elicit_win = eval_answer( # answer=self.participant.vars['industries']['puzzle_confidence'], # answer_correct=(industry_correct == self.participant.vars['industries']['puzzle_solution'])*100 # ) # Question to evaluate: BELIEF else: task_suffix = random.choice(['', '_first']) b = 'belief' + task_suffix w = 'winning_prob' + task_suffix r = random.choice(range(1, self.session.vars['N_rounds']+1)) i = random.choice(self.session.vars['portfolios']['names']) self.eval_elicit = str(r) + '_' + i + '_' + b elicit_win = eval_answer( answer=self.participant.vars[r][i][b], answer_correct=self.participant.vars[r][i][w] ) # PORTFOLIO realization r = random.choice(range(1, self.session.vars['N_rounds'] + 1)) portfolio_own = self.participant.vars[r]['own'] self.eval_portfolio_round = r self.eval_portfolio = str(r) + '_' + portfolio_own portfolio_win = self.participant.vars[r][portfolio_own]['win'] # Set Bonuses self.bonus_elicit = self.session.vars['bonus']['elicit'] if elicit_win else 0 self.bonus_portfolio = self.session.vars['bonus']['portfolio'] if portfolio_win else 0 self.payoff = self.bonus_elicit + self.bonus_portfolio