from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) from belief_elicitation.config import * import random from random import randrange from dash import Dash, html, dcc, Input, Output # ******************************************************************************************************************** # # *** CLASS SUBSESSION # ******************************************************************************************************************** # class Subsession(BaseSubsession): def creating_session(self): if self.round_number == 1: n = Constants.num_choices for p in self.get_players(): # create list of lottery indices # ---------------------------------------------------------------------------------------------------- indices = [j for j in range(1, n)] indices.append(n) if Constants.certain_choice else None # create list of lottery indices # ---------------------------------------------------------------------------------------------------- choices = [-100, -80, -60, -40, -20, 0, 20, 40, 60, 80, 100] choices_abs = [100, 80, 60, 40, 20, 0, 20, 40, 60, 80, 100] # create list corresponding to form_field variables including all choices # ---------------------------------------------------------------------------------------------------- form_fields = ['choice_' + str(k) for k in indices] # create list of choices # ---------------------------------------------------------------------------------------------------- p.participant.vars['mpl_choices'] = list( zip(indices, form_fields, choices, choices_abs) ) # initiate list for choices made # ---------------------------------------------------------------------------------------------------- p.participant.vars['mpl_choices_made'] = [None for j in range(1, n + 1)] # generate random switching point for PlayerBot in tests.py # -------------------------------------------------------------------------------------------------------- for participant in self.session.get_participants(): participant.vars['mpl_switching_point'] = random.randint(1, n) # ******************************************************************************************************************** # # *** CLASS GROUP # ******************************************************************************************************************** # class Group(BaseGroup): pass # ******************************************************************************************************************** # # *** CLASS PLAYER # ******************************************************************************************************************** # class Player(BasePlayer): # add model fields to class player # :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: if Constants.certain_choice: for j in range(1, Constants.num_choices + 1): locals()['choice_' + str(j)] = models.StringField() del j else: for j in range(1, Constants.num_choices): locals()['choice_' + str(j)] = models.StringField() del j random_draw = models.IntegerField() choice_to_pay = models.StringField() option_to_pay = models.StringField() test_next_month = models.FloatField( label="What is your best guess of the chance that you will make an appointment of mammography in the upcoming " "month? Please answer this on a 0 − 100 scale where 0 means very unlikely and 100 means for certain.", min=0, max=100, ) follow_cdc = models.FloatField( label="What is your best guess of the chance that you will follow American Cancer Society’s guidelines for " "breast cancer screen and have annual mammography starting at the age of 40? Please answer this on a " "0 − 100 scale where 0 means very unlikely and 100 means for certain.", min=0, max=100, ) five_year_risk = models.FloatField( label="Your estimate is: (%)", min=0, max=100, ) five_year_risk_s = models.FloatField( label="Your estimate is: (%)", min=0, max=100, ) five_year_risk_low = models.FloatField( min=0, max=100, ) five_year_risk_high = models.FloatField( min=0, max=100, ) five_year_risk_uncer = models.FloatField( label=" ", choices=[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100], widget=widgets.RadioSelectHorizontal ) five_year_risk_s_uncer = models.FloatField( label=" ", choices=[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100], widget=widgets.RadioSelectHorizontal ) life_time_risk = models.FloatField( label="Your estimate is: (%)", min=0, max=100, ) life_time_risk_s = models.FloatField( label="Your estimate is: (%)", min=0, max=100, ) life_time_risk_low = models.FloatField( min=0, max=100, ) life_time_risk_high = models.FloatField( min=0, max=100, ) life_time_risk_uncer = models.FloatField( label=" ", choices=[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100], widget=widgets.RadioSelectHorizontal ) life_time_risk_s_uncer = models.FloatField( label=" ", choices=[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100], widget=widgets.RadioSelectHorizontal ) slider_prac = models.IntegerField( min=0, max=100 ) slider_prac_low = models.IntegerField( min=0, max=100 ) slider_prac_high = models.IntegerField( min=0, max=100 ) slider_prac_uncer = models.IntegerField( min=0, max=100 )