from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random as r import json from otree.api import safe_json author = 'Marco Faillo + Marco Tecilla and Felix Holzmeister & Armin Pfurtscheller (BRET)' doc = """ Lottery tasks to measure choiceoverload impact on decision making (treatment with 5 numbers) """ class Constants(BaseConstants): name_in_url = 'lottery' players_per_group = None num_rounds = 1 ex = 0.03 show_up= 1 #bret box_value = 0.50 num_rows = 10 num_cols = 10 box_height = '30px' box_width = '30px' random_payoff = True instructions = True feedback = True results = True dynamic = False time_interval = 1.00 random = True devils_game = False undoable = True class Subsession(BaseSubsession): def creating_session(self): for player in self.get_players(): player.participant.vars['l1']=r.sample(range(1,50),5)## table lottery player.participant.vars['l2']=r.sample(range(1,50),2) #door lottery class Group(BaseGroup): pass class Player(BasePlayer): #domande di controllo q1 = models.IntegerField( choices=[[1, 'Earth'], [2, 'World'], [3, 'Planet'], [4, 'Globe']], ) q2 = models.IntegerField( choices=[[1, 'Orange'], [2, 'Pineapple'], [3, 'Apple'], [4, 'Lemon']], ) q3 = models.IntegerField() # contatore errori errors = models.IntegerField(initial=0) r1 =models.IntegerField(initial=0) # numeri prima lotteria r2 =models.IntegerField(initial=0) r3 =models.IntegerField(initial=0) r4 =models.IntegerField(initial=0) r5 =models.IntegerField(initial=0) p1 =models.IntegerField(initial=0)# numeri seconda lotteria (porte) p2 =models.IntegerField(initial=0) choice1 =models.IntegerField(initial=0) #scelta prima lotteria choice2 = models.IntegerField(initial=0) # scelta seconda lotteria 0 non estrae payoff_1 = models.IntegerField(initial=0) # payoff in punti money_1 = models.FloatField(initial=0) # payoff in £ # Bret bomb = models.IntegerField(initial=0) bomb_location = models.TextField(initial="0") boxes_collected = models.IntegerField(initial=0) boxes_scheme = models.TextField(initial=0) round_to_pay = models.IntegerField(initial=0) round_result = models.FloatField(initial=0) pay_bret = models.FloatField(initial=0) payoff_tot = models.FloatField(initial=0) # payoff in punti money_tot = models.FloatField(initial=0) # payoff in £ def estrai(self): self.r1=self.participant.vars['l1'][0] self.r2=self.participant.vars['l1'][1] self.r3=self.participant.vars['l1'][2] self.r4=self.participant.vars['l1'][3] self.r5=self.participant.vars['l1'][4] self.p1=self.participant.vars['l2'][0] self.p2=self.participant.vars['l2'][1] print("prima", self.r1, self.r2,self.r3,self.r4, self.r5) print("seconda", self.p1, self.p2) def calcola_payoff (self): if self.choice2 == 0: self.payoff_1 = self.choice1 else: self.payoff_1 = self.choice2 self.money_1 = self.payoff_1*Constants.ex def set_payoff_total(self): if self.bomb == 0: self.round_result = self.boxes_collected * Constants.box_value else: self.round_result = 0 self.pay_bret = int(self.round_result) self.payoff_tot = self.pay_bret + self.payoff_1 self.money_tot = self.pay_bret*Constants.ex + self.money_1