from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import pandas as pd import numpy as np author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'downstream_Hap' players_per_group = 9 #num_rounds = 48 num_rounds = 2 endowment = c(10) multiplication_factor = 2 structure = pd.DataFrame({'Round1':[1,7,2,8,4,5,3,6,7,4,3,1,5,8,6,2], 'Round2':[5,4,1,2,7,3,8,6,1,4,2,7,8,3,5,6], 'Round3':[8,1,3,2,5,7,6,4,8,5,1,2,6,3,4,7]}) structure = structure.T df = np.empty((0,16),int) for trials in range(16): var = trials dfar = np.append(np.array(range(trials,16)),np.array(range(var))) dfar = np.array([dfar]) df = np.append(df,dfar,axis=0) df = pd.DataFrame(df) l = [1,2,3,4,5,6,7,8,9] class Subsession(BaseSubsession): def creating_session(self): rn = self.round_number - 1 if self.round_number <= 16: new_structure = np.array([C.STRUCTURE.iloc[0,C.DF.iloc[rn,:3]]]) new_structure = np.append(new_structure,C.L) new_structure = list(dict.fromkeys(new_structure)) new_st = [int(s) for s in new_structure] print(new_structure) new_structure = [new_st] self.set_group_matrix(new_structure) elif self.round_number >= 17 and self.round_number <= 31: var=rn-16 new_structure = np.array([C.STRUCTURE.iloc[1,C.DF.iloc[var,:3]]]) new_structure = np.append(new_structure,C.L) new_structure = list(dict.fromkeys(new_structure)) new_st = [int(s) for s in new_structure] print(new_structure) new_structure = [new_st] self.set_group_matrix(new_structure) elif self.round_number >=33: var=rn-32 new_structure = np.array([C.STRUCTURE.iloc[2,C.DF.iloc[var,:3]]]) new_structure = np.append(new_structure,C.L) new_structure = list(dict.fromkeys(new_structure)) new_st = [int(s) for s in new_structure] print(new_structure) new_structure = [new_st] self.set_group_matrix(new_structure) class Group(BaseGroup): sent_amount = models.CurrencyField(min=0, max=C.ENDOWMENT) def set_payoffs(self): p1 = self.get_player_by_role('Sender') p1.payoff = C.ENDOWMENT - self.sent_amount p2 = self.get_player_by_role('Receiver') p2.payoff = self.sent_amount * C.MULTIPLICATION_FACTOR p3 = self.get_player_by_role('Informer') p3.payoff = 0 p4 = self.get_player_by_role('Controller') p4.payoff = 0 p5 = self.get_player_by_role('pass') p5.payoff = 0 class Player(BasePlayer): def role(self): if self.id_in_group==1: return 'Receiver' elif self.id_in_group==2: return 'Sender' elif self.id_in_group==3: return 'Informer' elif self.id_in_group==9: return 'Controller' else: return 'pass' contribution = models.CurrencyField(min=0, max=C.ENDOWMENT)