import itertools import numpy as np from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'juego_control' players_per_group = 4 num_rounds = 5 class Subsession(BaseSubsession): random = np.round_(np.random.normal(500, 150, 10), decimals=0, out=None) num = models.FloatField() def some_method2(self, Ki=[]): players = self.get_players() if self.round_number == 1: for p in players: p.creencia = (p.De_1_a_100 / 20) * 50 + (p.De_101_a_200 / 20)*150 + (p.De_201_a_300 / 20)*250 + \ (p.De_301_a_400 / 20)*350 + (p.De_401_a_500 / 20)*450 + (p.De_501_a_600 / 20)*550 + \ (p.De_601_a_700 / 20)*650 + (p.De_701_a_800 / 20)*750 + (p.De_801_a_900 / 20)*850 + \ (p.De_901_a_1000 / 20)*950 Ki.append(round(p.creencia, 0)) self.session.vars['apuesta'] = Ki pass def some_method(self): if self.round_number == 1: players = self.get_players() Ma_Ka_players = [p for p in players if p.participant.vars['Sesgo'] == 'Mayor' and p.participant.vars['grupo'] == "Kandisky"] Me_Ka_players = [p for p in players if p.participant.vars['Sesgo'] == 'Menor' and p.participant.vars['grupo'] == "Kandisky"] Ma_Kl_players = [p for p in players if p.participant.vars['Sesgo'] == 'Mayor' and p.participant.vars['grupo'] == "Klee"] Me_Kl_players = [p for p in players if p.participant.vars['Sesgo'] == 'Menor' and p.participant.vars['grupo'] == "Klee"] group_matrix = [] # pop elements from M_players until it's empty while Ma_Ka_players: new_group1 = [ Ma_Ka_players.pop(), Ma_Ka_players.pop(), Me_Ka_players.pop(), Me_Ka_players.pop(), ] group_matrix.append(new_group1) while Ma_Kl_players: new_group2 = [ Ma_Kl_players.pop(), Ma_Kl_players.pop(), Me_Kl_players.pop(), Me_Kl_players.pop(), ] group_matrix.append(new_group2) self.set_group_matrix(group_matrix) else: self.group_like_round(1) class Group(BaseGroup): def set_payoffs(self): subsession = self.subsession players = self.get_players() for p in players: p.creencia = (p.De_1_a_100 / 20) * 50 + (p.De_101_a_200 / 20)*150 + (p.De_201_a_300 / 20)*250 + \ (p.De_301_a_400 / 20)*350 + (p.De_401_a_500 / 20)*450 + (p.De_501_a_600 / 20)*550 + \ (p.De_601_a_700 / 20)*650 + (p.De_701_a_800 / 20)*750 + (p.De_801_a_900 / 20)*850 + \ (p.De_901_a_1000 / 20)*950 for p in players: if subsession.random[self.round_number-1] < 101: p.pay = 30 + 10 * (2 * (p.De_1_a_100 /20) - ((p.De_1_a_100 /20) ** 2 + (p.De_101_a_200 /20) ** 2 + (p.De_201_a_300 /20) ** 2 + (p.De_301_a_400 /20) ** 2 + (p.De_401_a_500 /20) ** 2 + (p.De_501_a_600 /20) ** 2 + (p.De_601_a_700 /20) ** 2 + (p.De_701_a_800 /20) ** 2 + (p.De_801_a_900 /20) ** 2 + (p.De_901_a_1000 /20) ** 2)) elif subsession.random[self.round_number-1] < 201: p.pay = 30 + 10 * (2 * (p.De_101_a_200 /20) - ( (p.De_1_a_100 /20) ** 2 + (p.De_101_a_200 /20) ** 2 + (p.De_201_a_300 /20) ** 2 + (p.De_301_a_400 /20) ** 2 + (p.De_401_a_500 /20) ** 2 + (p.De_501_a_600 /20) ** 2 + (p.De_601_a_700 /20) ** 2 + (p.De_701_a_800 /20) ** 2 + (p.De_801_a_900 /20) ** 2 + (p.De_901_a_1000 /20) ** 2)) elif subsession.random[self.round_number-1] < 301: p.pay = 30 + 10 * (2 * (p.De_201_a_300 /20) - ( (p.De_1_a_100 /20) ** 2 + (p.De_101_a_200 /20) ** 2 + (p.De_201_a_300 /20) ** 2 + (p.De_301_a_400 /20) ** 2 + (p.De_401_a_500 /20) ** 2 + (p.De_501_a_600 /20) ** 2 + (p.De_601_a_700 /20) ** 2 + (p.De_701_a_800 /20) ** 2 + ( p.De_801_a_900 /20) ** 2 + (p.De_901_a_1000 /20) ** 2)) elif subsession.random[self.round_number-1] < 401: p.pay = 30 + 10 * (2 * (p.De_301_a_400 /20) - ( (p.De_1_a_100 /20) ** 2 + (p.De_101_a_200 /20) ** 2 + (p.De_201_a_300 /20) ** 2 + (p.De_301_a_400 /20) ** 2 + (p.De_401_a_500 /20) ** 2 + (p.De_501_a_600 /20) ** 2 + (p.De_601_a_700 /20) ** 2 + (p.De_701_a_800 /20) ** 2 + (p.De_801_a_900 /20) ** 2 + (p.De_901_a_1000 /20) ** 2)) elif subsession.random[self.round_number-1] < 501: p.pay = 30 + 10 * (2 * (p.De_401_a_500 /20) - ( (p.De_1_a_100 /20) ** 2 + (p.De_101_a_200 /20) ** 2 + (p.De_201_a_300 /20) ** 2 + (p.De_301_a_400 /20) ** 2 + (p. De_401_a_500 /20) ** 2 + (p.De_501_a_600 /20) ** 2 + (p. De_601_a_700 /20) ** 2 + (p.De_701_a_800 /20) ** 2 + (p. De_801_a_900 /20) ** 2 + (p.De_901_a_1000 /20) ** 2)) elif subsession.random[self.round_number-1] < 601: p.pay = 30 + 10 * (2 * (p.De_501_a_600 /20) - ( (p.De_1_a_100 /20) ** 2 + (p.De_101_a_200 /20) ** 2 + (p.De_201_a_300 /20) ** 2 + (p.De_301_a_400 /20) ** 2 + (p.De_401_a_500 /20) ** 2 + (p.De_501_a_600 /20) ** 2 + (p.De_601_a_700 /20) ** 2 + (p.De_701_a_800 /20) ** 2 + (p.De_801_a_900 /20) ** 2 + (p.De_901_a_1000 /20) ** 2)) elif subsession.random[self.round_number-1] < 701: p.pay = 30 + 10 * (2 * (p.De_601_a_700 /20) - ( (p.De_1_a_100 /20) ** 2 + (p.De_101_a_200 /20) ** 2 + (p.De_201_a_300 /20) ** 2 + (p.De_301_a_400 /20) ** 2 + (p.De_401_a_500 /20) ** 2 + (p.De_501_a_600 /20) ** 2 + (p.De_601_a_700 /20) ** 2 + (p.De_701_a_800 /20) ** 2 + (p.De_801_a_900 /20) ** 2 + (p.De_901_a_1000 /20) ** 2)) elif subsession.random[self.round_number-1] < 801: p.pay = 30 + 10 * (2 * (p.De_701_a_800 /20) - ( (p.De_1_a_100 /20) ** 2 + (p.De_101_a_200 /20) ** 2 + (p.De_201_a_300 /20) ** 2 + (p.De_301_a_400 /20) ** 2 + (p.De_401_a_500 /20) ** 2 + (p.De_501_a_600 /20) ** 2 + (p.De_601_a_700 /20) ** 2 + (p.De_701_a_800 /20) ** 2 + (p.De_801_a_900 /20) ** 2 + (p.De_901_a_1000 /20) ** 2)) elif subsession.random[self.round_number-1] < 901: p.pay = 30 + 10 * (2 * (p.De_801_a_900 /20) - ( (p.De_1_a_100 /20) ** 2 + (p.De_101_a_200 /20) ** 2 + (p.De_201_a_300 /20) ** 2 + (p.De_301_a_400 /20) ** 2 + (p. De_401_a_500 /20) ** 2 + (p.De_501_a_600 /20) ** 2 + (p. De_601_a_700 /20) ** 2 + (p.De_701_a_800 /20) ** 2 + (p. De_801_a_900 /20) ** 2 + (p.De_901_a_1000 /20) ** 2)) elif subsession.random[self.round_number-1] < 1001: p.pay = 30 + 10 * (2 * (p.De_901_a_1000 /20) - ( (p.De_1_a_100 /20) ** 2 + (p.De_101_a_200 /20) ** 2 + (p.De_201_a_300 /20) ** 2 + (p.De_301_a_400 /20) ** 2 + (p.De_401_a_500 /20) ** 2 + (p.De_501_a_600 /20) ** 2 + (p. De_601_a_700 /20) ** 2 + (p.De_701_a_800 /20) ** 2 + (p. De_801_a_900 /20) ** 2 + (p.De_901_a_1000 /20) ** 2)) else: p.pay = 20 for p in players: p.avg_creencias = (p.other_player1().creencia + p.other_player2().creencia + p.other_player3().creencia) / 3 self.subsession.num = self.subsession.random[self.round_number - 1] pass class Player(BasePlayer): De_1_a_100 = models.IntegerField(initial=0, min=0, max=20) De_101_a_200 = models.IntegerField(initial=0, min=0, max=20) De_201_a_300 = models.IntegerField(initial=0, min=0, max=20) De_301_a_400 = models.IntegerField(initial=0, min=0, max=20) De_401_a_500 = models.IntegerField(initial=0, min=0, max=20) De_501_a_600 = models.IntegerField(initial=0, min=0, max=20) De_601_a_700 = models.IntegerField(initial=0, min=0, max=20) De_701_a_800 = models.IntegerField(initial=0, min=0, max=20) De_801_a_900 = models.IntegerField(initial=0, min=0, max=20) De_901_a_1000 = models.IntegerField(initial=0, min=0, max=20) creencia = models.FloatField() avg_creencias = models.FloatField() pay = models.FloatField() def other_player1(self): return self.get_others_in_group()[0] def other_player2(self): return self.get_others_in_group()[1] def other_player3(self): return self.get_others_in_group()[2] pass