from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random import numpy as np import time author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'EXLEY_ASPC_TRAINING' players_per_group = None num_rounds = 1 num_choices = 21 # variable à modifier en fonction ATTENTION !!!!!!!! class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): TREATMENT = models.StringField() ENDOWMENT = models.IntegerField() num_rounds = models.IntegerField(initial=Constants.num_rounds) num_choices = models.IntegerField(initial=Constants.num_choices) start_time = models.FloatField() temps_decision = models.FloatField() temps_regard_urne = models.LongStringField(blank=True) user_actions = models.LongStringField() association_choice = models.StringField() WTP_VEC = models.StringField() x1_outcome_vec_order = models.StringField() x2_outcome_vec_order = models.StringField() P1_vec_order = models.StringField() x1_me = models.FloatField() # 10€ x2_me = models.FloatField() # 0€ pas de calibration x_filler = models.FloatField() # 5€ x1_norm = models.FloatField() # calbration de 10€ x_filler_norm = models.FloatField() # calibration de 5€ x1_norm_after_correction = models.FloatField() # vraie valeur de x1_norm x2_norm = models.FloatField() # 0€ pas de calibration P1 = models.IntegerField() P2 = models.IntegerField() interval = models.FloatField() is_ascending = models.StringField() for j in range(1, Constants.num_choices + 1): locals()['choix' + str(j)] = models.StringField(choices=['A', 'B']) del j def ascending_or_descending_def(self): self.is_ascending = self.participant.vars['is_ascending'] # Calculer l'intervalle pour avoir exactement 21 nombres interval = self.participant.vars['x1_me'] / (Constants.num_choices - 1) # 20 intervalles pour 21 nombres self.interval = interval self.participant.vars['interval'] = self.interval self.participant.vars['WTP_values'] = [i * interval for i in range(Constants.num_choices)] if self.is_ascending == 'descending': self.participant.vars['WTP_values'] = self.participant.vars['WTP_values'][::-1] else: pass self.WTP_VEC = str(self.participant.vars['WTP_values']) def CREATE_LOTTERIES(self): self.participant.vars['x2_me_vec'] = [self.participant.vars['x2_me'] for _ in range(len(self.participant.vars['P1_TRAINING']))] self.participant.vars['x1_me_vec'] = [self.participant.vars['x1_me'] for _ in range(len(self.participant.vars['P1_TRAINING']))] pairs = list(zip(self.participant.vars['P1_TRAINING'], self.participant.vars['x1_me_vec'], self.participant.vars['x2_me_vec'])) # SI ON VEUT COLLER A EXLEY, IL NE FAUDRA PEUT ETRE PAS RANDOMISER L'APPARITION DES PROBA # Mélangez les paires random.shuffle(pairs) # Divisez les paires mélangées en deux listes séparées P1_order, x1_outcome_vec_order, x2_outcome_vec_order = zip(*pairs) # On record l'ordre des conditions dans la database self.P1_vec_order = str(P1_order) self.x1_outcome_vec_order = str(x1_outcome_vec_order) self.x2_outcome_vec_order = str(x2_outcome_vec_order) for s in range(1, Constants.num_rounds + 1): self.in_round(s).TREATMENT = "ASPC_TRAINING" self.in_round(s).ENDOWMENT = self.participant.vars['ENDOWMENT'] self.in_round(s).association_choice = self.participant.vars['association_choice'] self.in_round(s).x2_me = self.participant.vars['x2_me'] self.in_round(s).x1_me = self.participant.vars['x1_me'] self.in_round(s).x_filler = self.participant.vars['x_filler'] self.in_round(s).x_filler_norm = self.participant.vars['x_filler_norm'] self.in_round(s).x1_norm = self.participant.vars['x1_norm'] self.in_round(s).x1_norm_after_correction = self.participant.vars['x1_norm_after_correction'] self.in_round(s).x2_norm = self.participant.vars['x2_norm'] self.in_round(s).P1 = P1_order[s-1] self.in_round(s).P2 = (100*self.participant.vars['n']) - P1_order[s-1] self.in_round(s).WTP_VEC = str(self.participant.vars['WTP_values']) self.in_round(s).interval = self.participant.vars['interval'] self.in_round(s).is_ascending = self.participant.vars['is_ascending']