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_task2' players_per_group = None num_rounds = 5 #### 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 } 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']] p.participant.vars['X2_TOTAL'] = [p.participant.vars['X2'][i] for i in p.participant.vars['order']] p.participant.vars['P1_TOTAL'] = [p.participant.vars['P1'][i] for i in p.participant.vars['order']] p.participant.vars['P2_TOTAL'] = [p.participant.vars['P2'][i] for i in p.participant.vars['order']] print(p.participant.vars['X1_TOTAL']) 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() def create_wtp_values(self): self.participant.vars['wtp_values'] = list(range(self.participant.vars['X1_TOTAL'], self.participant.vars['X2_TOTAL'] - 1, -1)) print(self.participant.vars['wtp_values'] )