from otree.api import * c = cu doc = '' class C(BaseConstants): NAME_IN_URL = 'IPGG' PLAYERS_PER_GROUP = 4 NUM_ROUNDS = 5 INFOCOST = 3 ENDOWMENT = cu(20) MULTIPLIER = 1.2 INSTRUCTIONSUMPIRE_TEMPLATE = 'IPGG/instructionsumpire.html' INSTRUCTIONSPLAYER_TEMPLATE = 'IPGG/instructionsplayer.html' INSTRUCTIONSGENERIC_TEMPLATE = 'IPGG/instructionsgeneric.html' class Subsession(BaseSubsession): corruzione = models.IntegerField() corruzionesessione = models.IntegerField() robotcorrupt = models.IntegerField() corruzionegruppi = models.IntegerField() corruzioneround = models.IntegerField() corruzioneg1 = models.IntegerField(initial=0) corruzioneg2 = models.IntegerField(initial=0) corruzioneg3 = models.IntegerField(initial=0) corruzioneg4 = models.IntegerField(initial=0) tuttacorruzione = models.IntegerField() def creating_session(subsession: Subsession): session = subsession.session subsession.group_randomly(fixed_id_in_group=True) def my_function2(subsession: Subsession): session = subsession.session for g in subsession.get_groups(): if g.id_in_subsession == 1: subsession.corruzioneg1 = g.corruzioneround if g.id_in_subsession == 2: subsession.corruzioneg2 = g.corruzioneround if g.id_in_subsession == 3: subsession.corruzioneg3 = g.corruzioneround if g.id_in_subsession == 4: subsession.corruzioneg4 = g.corruzioneround subsession.corruzionesessione = subsession.corruzioneg1 + subsession.corruzioneg2 + subsession.corruzioneg3 + subsession.corruzioneg4 subsession.tuttacorruzione = sum([p.corruzionesessione for p in subsession.in_all_rounds()]) Subsession.creating_session = creating_session Subsession.my_function2 = my_function2 class Group(BaseGroup): contributions = models.IntegerField() partecipanti = models.IntegerField() umpirelastgroup = models.IntegerField() total_contribution = models.CurrencyField() individual_share = models.CurrencyField() corruzioneround = models.IntegerField() total_corruzione = models.IntegerField() total = models.IntegerField() corruzione = models.IntegerField() def after_all_players_arrive(group: Group): #creazione delle stringhe p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) p3 = group.get_player_by_id(3) p4 = group.get_player_by_id(4) # stinghe x pagine punishment arbitro/accettaz bribe for p in group.get_players(): try: p2.progettocomune = p2.contribution except TypeError: p2.contribution = None try: p3.progettocomune = p3.contribution except TypeError: p3.contribution = None try: p4.progettocomune = p4.contribution except TypeError: p4.contribution = None #stringhe x feedback da mostrare al player 2 (non faccio vedere le bribe) # if p3.progettocomune == "Uscita": try: p2.progettocomunepl3 = p3.progettocomune p1.progettocomunepl3 = p3.progettocomune p4.progettocomunepl3 = p3.progettocomune except TypeError: p3.progettocomune = None try: p2.progettocomunepl4 = p4.progettocomune p1.progettocomunepl4 = p4.progettocomune p3.progettocomunepl4 = p4.progettocomune except TypeError: p4.progettocomune = None try: p1.progettocomunepl2 = p2.progettocomune p3.progettocomunepl2 = p2.progettocomune p4.progettocomunepl2 = p2.progettocomune except TypeError: p2.progettocomune = None partecipanti= 0 for p in group.get_players(): partecipanti = partecipanti + 1 # - 1 because it countes the umpire p1.partecipantipg = partecipanti - 1 p2.partecipantipg = partecipanti - 1 p3.partecipantipg = partecipanti - 1 p4.partecipantipg = partecipanti - 1 def set_payoff1(group: Group): contributions = 0 partecipanti= 0 for p in group.get_players(): partecipanti = p.partecipantipg try: contributions = contributions + p.contribution except TypeError: p.contribution = None for p in group.get_players(): group.total_contribution= contributions * 2 group.individual_share = group.total_contribution / partecipanti #modifica variabile punizione ai fini del calcolo payoff (la variabile punishment è al livllo del player, ma l'arbitro punisce con ogni variabile un solo giocatore: devo perciò "cancellare" i casi vuoti for p in group.get_players(): p1 = group.get_player_by_id(1) p2 = group.get_player_by_id(2) p3 = group.get_player_by_id(3) p4 = group.get_player_by_id(4) p.punizione2 = 0 if p1.punishment2 == 700: p1.punizione2 = 0 else: p.punizione2 = p.punizione2 + p1.punishment2 p.punizione3 = 0 if p1.punishment3 == 700: p1.punizione3 = 0 #pass else: p.punizione3 = p.punizione3 + p1.punishment3 p.punizione4 = 0 if p1.punishment4 == 700: p1.punizione4 = 0 # pass else: p.punizione4 = p.punizione4 + p1.punishment4 p1.punizione2 = p4.punizione2 #check p1.punizione3 = p4.punizione3 p1.punizione4 = p4.punizione4 p.punizione = 0 if p1.punishment2 == 700: p2.punizione = 0 else: p2.punizione = p.punizione2 if p1.punishment3 == 700: p3.punizione = 0 else: p3.punizione = p.punizione + p.punizione3 if p1.punishment4 == 700: p4.punizione = 0 else: p4.punizione = p.punizione + p.punizione4 if p.punishment2 == 700: p1.punishment2 = 0 if p.punishment3 == 700: p1.punishment3 = 0 if p.punishment4 == 700: p1.punishment4 = 0 #payoff participants for p in group.get_players(): p2.payoff = C.ENDOWMENT - p2.contribution + group.individual_share - p2.punizione p3.payoff = C.ENDOWMENT - p3.contribution + group.individual_share - p3.punizione p4.payoff = C.ENDOWMENT - p4.contribution + group.individual_share - p4.punizione #payoff arbitro for p in group.get_players(): if group.total_contribution >= 54: p1.payoff = 17 + 8 p1.bonus = 8 else: p1.payoff = 17 p1.bonus = 0 def verify(group: Group): for p in group.get_players(): p1 = group.get_player_by_id(1) p.sumpunishment = p1.punishment2 + p1.punishment3 + p1.punishment3 if p.sumpunishment > 15 or p1.punishment2 > 10 or p1.punishment3 > 10 or p1.punishment4 > 10 : p.errore = 1 else: p.errore = 0 Group.after_all_players_arrive = after_all_players_arrive Group.set_payoff1 = set_payoff1 class Player(BasePlayer): QuestionPG = models.IntegerField(choices=[[27, '9 (contribuzione) + 9 (contribuzione) + 9 (contribuzione) + 0 (contribuzione) = 27 punti.'], [54, '9 (contribuzione) + 9 (contribuzione) + 9 (contribuzione) + 0 (contribuzione) = 27 punti. 27 x 2 (moltiplicatore progetto comune) = 54 punti']], label='1) Quanto vale il progetto comune?', widget=widgets.RadioSelect) Questionme = models.IntegerField(choices=[[19, '54 : 4 (partecipanti) = 14 punti (quota individuale progetto comune). 14 (dotazione iniziale) - 9 (contribuzione) + 14 = 19 punti'], [28, '54 : 4 (partecipanti) = 14 punti (quota individuale progetto comune). 14 (dotazione iniziale) + 14 = 28 punti']], label="2) Quanti punti ottieni complessivamente, se l'arbitro non ti toglie nessun punto?", widget=widgets.RadioSelect) Question3 = models.IntegerField(choices=[[16, "14 + 12 (quota individuale progetto comune) - 3 (contribuzione) - 7 (punti tolti dall'arbitro) = 16 punti"], [19, "14 + 12 (quota individuale progetto comune) - 7 (punti tolti dall'arbitro) = 19 punti"]], label="3) Quanti punti ottiene complessivamente il partecipante che ha messo 3 punti nel progetto comune, se l'arbitro gli ha tolto 7 punti?", widget=widgets.RadioSelect) QuestionUmp = models.IntegerField(choices=[[17, '17 punti'], [25, '17 + 8 (punti ottenuti grazie al progetto comune) = 25 punti se non accetti i punti offerti '], [27, '17 + 8 (punti ottenuti grazie al progetto comune) + 2 (punti offerti) = 27 punti se accetti i punti offerti']], label='2) Quanti punti ottieni complessivamente?', widget=widgets.RadioSelect) bonus = models.IntegerField() punishment2 = models.IntegerField(blank=True, initial=700, label='Indica se e quanti punti vuoi togliere al partecipante', max=10) punishment3 = models.IntegerField(blank=True, initial=700, label='Indica se e quanti punti vuoi togliere al partecipante', max=10) punishment4 = models.IntegerField(blank=True, initial=700, label='Indica se e quanti punti vuoi togliere al partecipante', max=10) punizione2 = models.IntegerField(choices=[]) punizione3 = models.IntegerField(choices=[]) punizione4 = models.IntegerField(choices=[]) punizione = models.IntegerField() numberg = models.IntegerField(choices=[[1, '1'], [2, '2'], [3, '3']]) progettocomune = models.IntegerField() partecipantipg = models.IntegerField() contribution = models.IntegerField(choices=[[0, '0'], [1, '1'], [2, '2'], [3, '3'], [4, '4'], [5, '5'], [6, '6'], [7, '7'], [8, '8'], [9, '9'], [10, '10'], [11, '11'], [12, '12'], [13, '13'], [14, '14'], [15, '15'], [16, '16'], [17, '17'], [18, '18'], [19, '19'], [20, '20']], label='Quanto vuoi mettere nel progetto comune?') progettocomunepl2 = models.IntegerField() progettocomunepl3 = models.IntegerField() progettocomunepl4 = models.IntegerField() progettocomunepl5 = models.IntegerField() sumpunishment = models.FloatField() errore = models.IntegerField() def setglobals(player: Player): participant = player.participant participant.vars['IPGG_payoff'] = participant.payoff return(participant.vars) Player.setglobals = setglobals class Attesagruppixpartire(WaitPage): wait_for_all_groups = True @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Role(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == 1 class IstruzioniPlayer(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): group = player.group return player.round_number == 1 and player.id_in_group != 1 class IstruzioniUmpire(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): group = player.group return player.round_number == 1 and player.id_in_group == 1 class Start(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Contribuzione(Page): form_model = 'player' form_fields = ['contribution'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group != 1 class Giocatori(WaitPage): after_all_players_arrive = after_all_players_arrive @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group != 1 class WaitingUmpire(WaitPage): after_all_players_arrive = after_all_players_arrive body_text = 'Attendi che i partecipanti facciano le loro scelte' @staticmethod def is_displayed(player: Player): group = player.group return group.get_player_by_id(1) class Punishment(Page): form_model = 'player' form_fields = ['punishment2', 'punishment3', 'punishment4'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group == 1 class VerifyPunishment(WaitPage): after_all_players_arrive = verify @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group != 1 and player.sumpunishment > 15 class PunishmentError(Page): form_model = 'player' form_fields = ['punishment2', 'punishment3', 'punishment4'] @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group != 1 and player.errore == 1 class Attesagiocatori(WaitPage): after_all_players_arrive = after_all_players_arrive @staticmethod def is_displayed(player: Player): group = player.group return player.id_in_group != 1 class ExecutingPayoffRound1(WaitPage): after_all_players_arrive = set_payoff1 @staticmethod def is_displayed(player: Player): return player.round_number == 1 class PayoffRound(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == 1 @staticmethod def before_next_page(player: Player, timeout_happened): player.setglobals() class Ringraziamento(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == 5 page_sequence = [Attesagruppixpartire, Role, IstruzioniPlayer, IstruzioniUmpire, Start, Contribuzione, Giocatori, WaitingUmpire, Punishment, VerifyPunishment, PunishmentError, Attesagiocatori, ExecutingPayoffRound1, PayoffRound, Ringraziamento]