from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'MAIF_CONSIGNE' players_per_group = None num_rounds = 1 ENDOWMENT = 5 y_me = 30 x_me = 10 y_outcome = 20 x_outcome = 0 D_me = 10 nb_proba = 5 nb_ligne = 21 nb_traitement = 4 nb_tableau = nb_traitement*nb_proba nb_choice_total = nb_proba * nb_ligne * nb_traitement num_boule = 100 epsilon = 10 num_choices = nb_ligne boule_verte_option = [0, 10, 50, 80, 90] class Subsession(BaseSubsession): def creating_session(self): for p in self.get_players(): p.participant.vars['num_boule'] = Constants.num_boule p.participant.vars['epsilon'] = Constants.epsilon p.participant.vars['num_choices'] = Constants.num_choices p.participant.vars['boule_verte_option'] = Constants.boule_verte_option.copy() p.num_boule = p.participant.vars['num_boule'] p.epsilon = p.participant.vars['epsilon'] p.num_choices = p.participant.vars['num_choices'] p.boule_verte_option = str(p.participant.vars['boule_verte_option'] ) p.ENDOWMENT = Constants.ENDOWMENT p.participant.vars['ENDOWMENT'] = Constants.ENDOWMENT p.participant.vars['y_me'] = Constants.y_me p.participant.vars['x_me'] = Constants.x_me p.participant.vars['y_outcome'] = Constants.y_outcome p.participant.vars['x_outcome'] = Constants.x_outcome p.participant.vars['D_me'] = Constants.D_me p.y_me = p.participant.vars['y_me'] p.x_me = p.participant.vars['x_me'] p.y_outcome = p.participant.vars['y_outcome'] p.x_outcome = p.participant.vars['x_outcome'] p.D_me = p.participant.vars['D_me'] p.participant.vars['nb_proba'] = Constants.nb_proba p.participant.vars['nb_ligne'] = Constants.nb_ligne p.participant.vars['nb_choice_total'] = Constants.nb_choice_total p.participant.vars['nb_traitement'] = Constants.nb_traitement p.participant.vars['nb_tableau'] = Constants.nb_tableau p.nb_proba = str(p.participant.vars['nb_proba']) p.nb_ligne = p.participant.vars['nb_ligne'] p.nb_choice_total = p.participant.vars['nb_choice_total'] p.nb_traitement = p.participant.vars['nb_traitement'] p.nb_tableau = p.participant.vars['nb_tableau'] list_appli = ['YCPC', 'YSPS', 'YCPS', 'YSPC'] p.paiement_treatment = random.choice(list_appli) p.participant.vars['paiement_treatment'] = p.paiement_treatment for s in range(1, Constants.num_rounds + 1): p.in_round(s).y_me = p.participant.vars['y_me'] p.in_round(s).x_me = p.participant.vars['x_me'] p.in_round(s).y_outcome = p.participant.vars['y_outcome'] p.in_round(s).x_outcome = p.participant.vars['x_outcome'] p.in_round(s).D_me = p.participant.vars['D_me'] class Group(BaseGroup): pass class Player(BasePlayer): num_boule = models.IntegerField() epsilon = models.IntegerField() num_choices = models.IntegerField() boule_verte_option = models.StringField() ENDOWMENT = models.IntegerField() y_me = models.IntegerField() x_me = models.IntegerField() y_outcome = models.IntegerField() x_outcome = models.IntegerField() D_me = models.IntegerField() nb_proba = models.StringField() nb_ligne = models.IntegerField() nb_choice_total = models.IntegerField() nb_traitement = models.IntegerField() nb_tableau = models.IntegerField() paiement_treatment = models.StringField()