from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import random # Pagina Istruzioni class Istruzioni(Page): def vars_for_template(self): return{ 'treatment' : self.session.config['treatment'] } # Pagina codice class Code(Page): form_model = 'player' form_fields = ['code'] # Pagina contribuzione class Choice(Page): form_model = 'player' form_fields = ['contribute'] def vars_for_template(self): return{ 'treatment' : self.session.config['treatment'], 'valore_estratto': random.randint(1,100) } def before_next_page(self): self.player.find_code(1) # Attesa contribuzione class ChoiceWaitPage(WaitPage): title_text = 'attendi le scelte degli altri giocatori' body_text = 'Attendi le scelte degli altri giocatori' def after_all_players_arrive(self): self.group.set_who_punish() # Pagina punizione class Punishment(Page): form_model = 'player' form_fields = ['punish_value'] def vars_for_template(self): return{ 'id_to_punish': self.group.get_player_by_id(self.player.punish_id).get_code(), 'treatment' : self.session.config['treatment'] } def is_displayed(self): return self.player.contribute > 0 and self.player.punish_id > -1 def before_next_page(self): self.group.get_player_by_id(self.player.punish_id).punish_received = self.group.get_player_by_id(self.player.punish_id).punish_received + self.player.punish_value # Pagina punizione ipotetica class Punishment_Ipo(Page): form_model = 'player' form_fields = ['punish_value_ipo'] def vars_for_template(self): return{ # 'id_to_punish': self.group.get_player_by_id(self.player.punish_id).get_code(), 'id_to_punish': 0, 'treatment' : self.session.config['treatment'] } def is_displayed(self): return self.player.contribute == 0 # Pagina attesa per chi non punisce class NoPunishWaitPage(WaitPage): title_text = 'attendi che decidano la punizione' body_text = 'Attendi che gli altri ti puniscano' def is_displayed(self): return self.player.contribute == 0 # Pagina attesa punizione class PunishWaitPage(WaitPage): title_text = 'attendi le scelte degli altri giocatori' body_text = 'Attendi le scelte degli altri giocatori' def after_all_players_arrive(self): self.subsession.set_payoff() class Results(Page): def vars_for_template(self): return{ 'punizione_valore': round(self.player.punish_value * 1,2), 'punizione_ricevuta': round(self.player.punish_received,2), 'guadagno': self.participant.payoff_plus_participation_fee(), 'costo_punizione': round(self.player.punish_value * 1 * 0.2,2) } # Pagina questionario anagrafico class Anag(Page): form_model = 'player' form_fields = ['age','sex','faculty','num_experiments','degree'] # Questionario finale class Quest_final(Page): form_model = 'player' def get_form_fields(self): my_fields = ['q_1','q_2','q_3','q_4','q_5','q_6','q_7','q_8','q_9','q_10','q_11','q_12'] random.shuffle(my_fields) return my_fields # questionario feeling class Quest_Sens(Page): form_model = 'player' form_fields = ['anger','blame','sympathy'] def is_displayed(self): return self.player.contribute > 0 and self.player.punish_id > -1 page_sequence = [ Code, Choice, ChoiceWaitPage, Punishment, Quest_Sens, Punishment_Ipo, NoPunishWaitPage, PunishWaitPage, Quest_final, Anag, Results ]