from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random import numpy as np import itertools author = 'Vincent Lenglin' doc = """ preference individuelle """ class Constants(BaseConstants): name_in_url = 'attention_boule_task' players_per_group = None num_rounds = 5*4 nb_page = 100/56 #### RISK #### ################################################################## # LOTERIES SETTING c_loterie_sequence = [0, 1, 2, 3, 4] c_X1 = { "1": 10, "2": 10, "3": 10, "4": 10, "5": 10 } c_X2 = { "1": 0, "2": 0, "3": 0, "4": 0, "5": 0 } c_P1 = { "1": 5, "2": 25, "3": 15, "4": 35, "5": 45 } c_P2 = { "1": 45, "2": 25, "3": 35, "4": 15, "5": 5 } c_iter = 4 c_change_template = [5, 9, 13, 17] c_change = [x - 1 for x in c_change_template] class Subsession(BaseSubsession): def creating_session(self): if self.round_number == 1: for p in self.get_players(): #### RISK #### ################################################################## # RANDOMIZATION + VECTEUR DE L'ORDRE D APPARITION DES LOTERIES # ------------------------------------------- loterie_sequence = Constants.c_loterie_sequence.copy() random.shuffle(loterie_sequence) p.participant.vars['order'] = loterie_sequence p.participant.vars['order_vecteur'] = np.repeat(p.participant.vars['order'], Constants.c_iter) # liste des valeurs des loteries p.participant.vars['X1'] = list(Constants.c_X1.values()) p.participant.vars['X2'] = list(Constants.c_X2.values()) p.participant.vars['P1'] = list(Constants.c_P1.values()) p.participant.vars['P2'] = list(Constants.c_P2.values()) # VECTEUR COMPLETS DES VALEURS DES LOTERIES p.participant.vars['X1_TOTAL'] = [p.participant.vars['X1'][i] for i in p.participant.vars['order_vecteur']] p.participant.vars['X2_TOTAL'] = [p.participant.vars['X2'][i] for i in p.participant.vars['order_vecteur']] p.participant.vars['P1_TOTAL'] = [p.participant.vars['P1'][i] for i in p.participant.vars['order_vecteur']] p.participant.vars['P2_TOTAL'] = [p.participant.vars['P2'][i] for i in p.participant.vars['order_vecteur']] #### TOTAL VECTEUR #### ################################################################## # VECTEUR COMPLETS DES VALEURS DES RISK p.participant.vars['DELTA'] = (p.participant.vars['X1_TOTAL'][0] - p.participant.vars['X2_TOTAL'][0]) / 2 p.participant.vars['CE'] = (p.participant.vars['X1_TOTAL'][0] - p.participant.vars['DELTA']) p.DELTA = p.participant.vars['DELTA'] p.CE = (p.participant.vars['CE']) class Group(BaseGroup): pass class Player(BasePlayer): ###### ALGORITHME PREFERENCES INDIVIDUELLES ########### ###################################################################################### start_time = models.FloatField() temps_decision = models.FloatField() nombre_de_visites_urne = models.IntegerField(initial=0, blank=True) temps_total_urne = models.FloatField(blank=True) choix = models.StringField(blank = False) X1 = models.IntegerField() X2 = models.IntegerField() P1 = models.IntegerField() P2 = models.IntegerField() DELTA = models.FloatField() CE = models.FloatField() def loterie(self): # CALCUL DU PROCHAIN MONTANT CERTAIN EN FONCTION DES CONDITIONS #----------------------------------------------------------------- if self.round_number in Constants.c_change: self.participant.vars['DELTA'] = (self.participant.vars['X1_TOTAL'][self.round_number ] - self.participant.vars['X2_TOTAL'][self.round_number ]) / 2 self.participant.vars['CE'] = (self.participant.vars['X1_TOTAL'][self.round_number ] - self.participant.vars['DELTA']) self.in_round( self.round_number + 1 ).DELTA = self.participant.vars['DELTA'] self.in_round( self.round_number + 1 ).CE = (self.participant.vars['CE']) else: if self.in_round(self.round_number).choix == "A": self.participant.vars['DELTA'] = self.participant.vars['DELTA'] / 2 self.participant.vars['CE'] = (self.participant.vars['CE'] + self.participant.vars['DELTA']) self.in_round( self.round_number + 1 ).DELTA = self.participant.vars['DELTA'] self.in_round( self.round_number + 1 ).CE = (self.participant.vars['CE']) elif self.in_round(self.round_number).choix == "B": self.participant.vars['DELTA'] = self.participant.vars['DELTA'] / 2 self.participant.vars['CE'] = (self.participant.vars['CE'] - self.participant.vars['DELTA']) self.in_round( self.round_number + 1 ).DELTA = self.participant.vars['DELTA'] self.in_round( self.round_number + 1 ).CE = (self.participant.vars['CE']) def changement(self): self.X1 = self.participant.vars['X1_TOTAL'][self.round_number - 1] self.X2 = self.participant.vars['X2_TOTAL'][self.round_number - 1] self.P1 = self.participant.vars['P1_TOTAL'][self.round_number - 1] self.P2 = self.participant.vars['P2_TOTAL'][self.round_number - 1]