from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class Paid_intro(Page): #introduction (appear only at round 1) def is_displayed(self): return self.subsession.round_number == 1 def vars_for_template(self): self.group.azzera() class WaitPage1(WaitPage): wait_for_all_groups = True class WaitPage2(WaitPage): wait_for_all_groups = True class Price_setting_CP_gen (Page): # choice of the price by CP generalist form_model = 'group' form_fields = ['p_gen_input'] def js_vars(self): # variables for the plot of price and quantity sold if self.subsession.round_number > 1: return dict( p_gen_list=self.player.participant.vars['list_p_gen'], p_spec_list=self.player.participant.vars['list_p_spec'], demand_gen_list=self.player.participant.vars['list_demand_gen'], demand_spec_list=self.player.participant.vars['list_demand_spec'] ) else: return () def is_displayed(self): return self.player.id_in_group == 1 def vars_for_template(self): self.group.recupera_dati() #recollect data from previous round if self.subsession.round_number == 1: return{ 'role': self.player.role, 'round': self.subsession.round_number, 'group':self.group.id_in_subsession, } else: return{ 'role': self.player.role, 'group':self.group.id_in_subsession, 'round': self.subsession.round_number, 'cum_payoff': self.group.cum_payoff_gen, 'tarif_1_ISP_1_old':self.group.in_round(self.subsession.round_number-1).p1_ISP_1, 'tarif_2_ISP_1_old':self.group.in_round(self.subsession.round_number-1).p2_ISP_1, 'tarif_1_ISP_2_old':self.group.in_round(self.subsession.round_number-1).p1_ISP_2, 'tarif_2_ISP_2_old':self.group.in_round(self.subsession.round_number-1).p2_ISP_2, 'tarif_1_ISP_1_sold_old':self.group.tarif_1_sold_old_ISP_1, 'tarif_2_ISP_1_sold_old':self.group.tarif_2_sold_old_ISP_1, 'tarif_1_ISP_2_sold_old':self.group.tarif_1_sold_old_ISP_2, 'tarif_2_ISP_2_sold_old':self.group.tarif_2_sold_old_ISP_2, } class Price_setting_CP_spec (Page): # choice of the price by CP specialist form_model = 'group' form_fields = ['p_spec_input'] def is_displayed(self): return self.player.id_in_group == 2 def vars_for_template(self): self.group.recupera_dati() # recollect data from previous rounds if self.subsession.round_number == 1: return{ 'role': self.player.role, 'round': self.subsession.round_number, 'group':self.group.id_in_subsession, } else: return{ 'role': self.player.role, 'group':self.group.id_in_subsession, 'round': self.subsession.round_number, 'tarif_1_ISP_1_old':self.group.in_round(self.subsession.round_number-1).p1_ISP_1, 'tarif_2_ISP_1_old':self.group.in_round(self.subsession.round_number-1).p2_ISP_1, 'tarif_1_ISP_2_old':self.group.in_round(self.subsession.round_number-1).p1_ISP_2, 'tarif_2_ISP_2_old':self.group.in_round(self.subsession.round_number-1).p2_ISP_2, 'cum_payoff': self.group.cum_payoff_spec, 'tarif_1_ISP_1_sold_old':self.group.tarif_1_sold_old_ISP_1, 'tarif_2_ISP_1_sold_old':self.group.tarif_2_sold_old_ISP_1, 'tarif_1_ISP_2_sold_old':self.group.tarif_1_sold_old_ISP_2, 'tarif_2_ISP_2_sold_old':self.group.tarif_2_sold_old_ISP_2, } def js_vars(self): # variables for the plot of price and quantity sold if self.subsession.round_number > 1: return dict( p_gen_list=self.player.participant.vars['list_p_gen'], p_spec_list=self.player.participant.vars['list_p_spec'], demand_gen_list=self.player.participant.vars['list_demand_gen'], demand_spec_list=self.player.participant.vars['list_demand_spec'], ) else: return () class Price_setting_ISP_1(Page): # choice of the tariff by ISP_1 form_model = 'group' form_fields = ['p1_ISP_1', 'p2_ISP_1'] def is_displayed(self): return self.player.id_in_group == 3 def error_message(self, values): if values['p1_ISP_1'] == values ['p2_ISP_1']: return 'Escoge dos tarifas diferentes' def vars_for_template(self): self.group.recupera_dati() # recollect data from previous rounds if self.subsession.round_number == 1: return{ 'round': self.subsession.round_number, 'group':self.group.id_in_subsession, } else: return{ 'p_gen_price': self.player.participant.vars['list_p_gen'][self.subsession.round_number-2], 'p_spec_price': self.player.participant.vars['list_p_spec'][self.subsession.round_number-2], 'round': self.subsession.round_number, 'group':self.group.id_in_subsession, 'role': self.player.role, 'round': self.subsession.round_number, 'tarif_1_ISP_1_old':self.group.in_round(self.subsession.round_number-1).p1_ISP_1, 'tarif_2_ISP_1_old':self.group.in_round(self.subsession.round_number-1).p2_ISP_1, 'tarif_1_ISP_2_old':self.group.in_round(self.subsession.round_number-1).p1_ISP_2, 'tarif_2_ISP_2_old':self.group.in_round(self.subsession.round_number-1).p2_ISP_2, 'tarif_1_ISP_1_sold_old':self.group.tarif_1_sold_old_ISP_1, 'tarif_2_ISP_1_sold_old':self.group.tarif_2_sold_old_ISP_1, 'tarif_1_ISP_2_sold_old':self.group.tarif_1_sold_old_ISP_2, 'tarif_2_ISP_2_sold_old':self.group.tarif_2_sold_old_ISP_2, 'cum_payoff': self.group.cum_payoff_ISP_1 } class Price_setting_ISP_2(Page): # choice of the tariff by ISP_2 form_model = 'group' form_fields = ['p1_ISP_2', 'p2_ISP_2'] def old_data(self): self.group.recupera_dati() # recollect data from previous round def error_message(self, values): if values['p1_ISP_2'] == values ['p2_ISP_2']: return 'Escoge dos tarifas diferentes' def is_displayed(self): return self.player.id_in_group == 4 def vars_for_template(self): self.group.recupera_dati() self.player.participant.vars['tarifs_ISP_2_old'].sort() self.player.participant.vars['tarifs_ISP_2_old'].sort() if self.subsession.round_number == 1: return{ 'round': self.subsession.round_number, 'group':self.group.id_in_subsession, } else: return{ 'p_gen_price': self.player.participant.vars['list_p_gen'][self.subsession.round_number-2], 'p_spec_price': self.player.participant.vars['list_p_spec'][self.subsession.round_number-2], 'round': self.subsession.round_number, 'group':self.group.id_in_subsession, 'role': self.player.role, 'round': self.subsession.round_number, 'tarif_1_ISP_1_old':self.group.in_round(self.subsession.round_number-1).p1_ISP_1, 'tarif_2_ISP_1_old':self.group.in_round(self.subsession.round_number-1).p2_ISP_1, 'tarif_1_ISP_2_old':self.group.in_round(self.subsession.round_number-1).p1_ISP_2, 'tarif_2_ISP_2_old':self.group.in_round(self.subsession.round_number-1).p2_ISP_2, 'tarif_1_ISP_1_sold_old':self.group.tarif_1_sold_old_ISP_1, 'tarif_2_ISP_1_sold_old':self.group.tarif_2_sold_old_ISP_1, 'tarif_1_ISP_2_sold_old':self.group.tarif_1_sold_old_ISP_2, 'tarif_2_ISP_2_sold_old':self.group.tarif_2_sold_old_ISP_2, 'cum_payoff': self.group.cum_payoff_ISP_2 } class ResultsWaitPage(WaitPage): # compute demands, utilities and payoff for the current round def after_all_players_arrive (self): self.group.demand() self.group.set_payoff() class Results (Page): # show result of the current round def vars_for_template(self): return{ 'demand_CP_spec': round(self.group.demand_spec_TOT), 'demand_CP_gen': round(self.group.demand_gen_TOT), 'p_gen': self.group.p_gen, 'p_spec': self.group.p_spec, 'group':self.group.id_in_subsession, 'revenue_gen': round(self.group.revenue_CP_gen), 'revenue_spec': round(self.group.revenue_CP_spec), 'revenue_ISP_1': round(self.group.revenue_ISP_1), 'revenue_ISP_2': round(self.group.revenue_ISP_2), 'round': self.subsession.round_number, 'demand_ISP_1': round(self.group.demand_ISP_1), 'demand_ISP_2': round(self.group.demand_ISP_2), 'tarif_1_ISP_1':self.group.p1_ISP_1, 'tarif_2_ISP_1':self.group.p2_ISP_1, 'tarif_1_ISP_2':self.group.p1_ISP_2, 'tarif_2_ISP_2':self.group.p2_ISP_2, 'tarif_1_sold_ISP_1': self.player.participant.vars['tarifs_sold_ISP_1_TOT'][self.group.p1_ISP_1-1], 'tarif_2_sold_ISP_1': self.player.participant.vars['tarifs_sold_ISP_1_TOT'][self.group.p2_ISP_1-1], 'tarif_1_sold_ISP_2': self.player.participant.vars['tarifs_sold_ISP_2_TOT'][self.group.p1_ISP_2-1], 'tarif_2_sold_ISP_2': self.player.participant.vars['tarifs_sold_ISP_2_TOT'][self.group.p2_ISP_2-1], 'demand_spec_low' :round(self.group.demand_spec_L), 'demand_spec_high' : round(self.group.demand_spec_H), 'demand_gen_low' : round(self.group.demand_gen_L), 'demand_gen_high' : round(self.group.demand_gen_H), 'role': self.player.role, 'cum_payoff_gen': round(self.group.cum_payoff_gen), 'cum_payoff_spec': round(self.group.cum_payoff_spec), 'cum_payoff_ISP_1': round(self.group.cum_payoff_ISP_1), 'cum_payoff_ISP_2': round(self.group.cum_payoff_ISP_2), } class End(Page): def vars_for_template(self): # compute the final payment in euros. self.player.set_euro() return { 'role': self.player.role, 'group':self.group.id_in_subsession, 'finalpay': self.player.euro, } def is_displayed(self): ## ultimo round mostra risultati return self.round_number == Constants.num_rounds class Questionnaire (Page): #final questionnario, appers at the last round form_model = 'player' form_fields = ['age', 'gender', 'experiments', 'nat','major'] def is_displayed(self): ## ultimo round mostra risultati return self.round_number == Constants.num_rounds page_sequence = [ Paid_intro, WaitPage1, Price_setting_CP_gen, Price_setting_CP_spec, Price_setting_ISP_1, Price_setting_ISP_2, ResultsWaitPage, Results, End, WaitPage2, Questionnaire, #MyPage ]