from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants # Introductory page of begininng of game and recall of costs class IntroIntro(Page): def vars_for_template(self): return dict(lastnormalroundnum=self.session.vars['total_number_rounds_game']-self.session.vars['number_last_rounds_game']) def is_displayed(self): return self.player.round_number == 1 # Introductory page for the game with graphical representation of the pool of balls class Intro(Page): def vars_for_template(self): return {'initendowment':self.session.vars['init_endowment']} # Period 1: suggestions and guess of subject class period1(Page): form_model = 'player' form_fields = ['guess_period1'] def vars_for_template(self): return { 'Vert1': 'Game/'+ 'R_' + str(self.player.robot) + 'G.png', 'Bleu1': 'Game/'+ 'R_' + str(self.player.robot) + 'B.png', 'Vert2': 'Game/'+ 'R_' + str(self.player.robot2) + 'G.png', 'Bleu2': 'Game/'+ 'R_' + str(self.player.robot2) + 'B.png', } # Period 2: Agent asks for advice or not class period2(Page): form_model = 'player' form_fields = ['requested_advice'] def vars_for_template(self): return { 'Vert1': 'Game/'+ 'R_' + str(self.player.robot) + 'G.png', 'Bleu1': 'Game/'+ 'R_' + str(self.player.robot) + 'B.png', 'Vert2': 'Game/'+ 'R_' + str(self.player.robot2) + 'G.png', 'Bleu2': 'Game/'+ 'R_' + str(self.player.robot2) + 'B.png' } # Period 2: agent makes guess class period2_bis(Page): form_model = 'player' form_fields = ['guess_period2'] def vars_for_template(self): return { 'Vert1': 'Game/'+ 'R_' + str(self.player.robot) + 'G.png', 'Bleu1': 'Game/'+ 'R_' + str(self.player.robot) + 'B.png', 'Vert2': 'Game/'+ 'R_' + str(self.player.robot2) + 'G.png', 'Bleu2': 'Game/'+ 'R_' + str(self.player.robot2) + 'B.png' } # recorded values for later use (post-questions and final payoff) def before_next_page(self): if self.player.round_number < Constants.num_rounds - Constants.num_lastRounds: self.participant.vars['advice_purchases'].append(self.player.requested_advice) self.player.payoff_period1 = self.player.points_gained_P1() self.player.payoff_period2 = self.player.points_gained_P2() self.player.round_payoff = self.player.points_gained() if self.player.round_number == self.player.participant.vars['paid_round']: self.player.participant.vars['payoff_points'] = self.player.round_payoff self.player.payoff = round(self.player.round_payoff / self.session.vars['euroconversion'], 2) # Final outcome and payoff for the given round class Results(Page): pass ##### PAGES SPECIFIC FOR THE ROUNDS WITH BIDDING SYSTEM # Instruction and Control Questions (need correct answer to validate page) class InstructionLastRound(Page): form_model = 'player' def get_form_fields(self): if self.player.participant.vars['treatment'] in ["1A","1B"]: return ['Q1','Q2','Q3','Q4'] elif self.player.participant.vars['treatment'] in ["2A","2B"] and self.player.participant.vars['treatment_2advisors_lastrounds'] == "version1": return ['Q5','Q6','Q7','Q8'] elif self.player.participant.vars['treatment'] in ["2A","2B"] and self.player.participant.vars['treatment_2advisors_lastrounds'] == "version2": return ['Q9','Q10','Q11'] def is_displayed(self): return self.player.round_number == Constants.num_rounds - Constants.num_lastRounds def error_message(self, values): print('type is',type(values)) if self.player.participant.vars['treatment'] in ["1A","1B"]: if [i for i in values.values()] != ['No','Oui','No','Oui']: return 'Au moins une de vos réponses est fausse, veuillez relire les instructions et répondre de nouveau.' elif self.player.participant.vars['treatment'] in ["2A","2B"] and self.player.participant.vars['treatment_2advisors_lastrounds'] == "version1": if [i for i in values.values()] != ['No','Oui','No','Oui']: return 'Au moins une de vos réponses est fausse, veuillez relire les instructions et répondre de nouveau.' elif self.player.participant.vars['treatment'] in ["2A","2B"] and self.player.participant.vars['treatment_2advisors_lastrounds'] == "version2": if [i for i in values.values()] != ['No','Oui','Oui']: return 'Au moins une de vos réponses est fausse, veuillez relire les instructions et répondre de nouveau.' def vars_for_template(self): return dict(max_bid_single=self.session.vars['max_bid_single'], max_bid_bundle=self.session.vars['max_bid_bundle'], totnumroundsgame=self.session.vars['total_number_rounds_game'], lastnormalroundnum=self.session.vars['total_number_rounds_game']-self.session.vars['number_last_rounds_game'], firstdifferentround=self.session.vars['total_number_rounds_game']-self.session.vars['number_last_rounds_game']+1) # Bidding page if purchased any advice class Bid(Page): form_model = 'player' form_fields = ['bid_price'] def is_displayed(self): if self.player.round_number in Constants.last_rounds and self.player.requested_advice in ['Yes','1','2','12','3']: return True else: return False def vars_for_template(self): if self.player.requested_advice == '12': return dict(bid_price_label='Veuillez proposer un montant de points que vous êtes prêt à payer, entre 0 et {} points.'.format(self.session.vars['max_bid_bundle'])) else: return dict(bid_price_label='Veuillez proposer un montant de points que vous êtes prêt à payer, entre 0 et {} points.'.format(self.session.vars['max_bid_single'])) # Advice, in case of purchase + bid high enough class AdviceLastRound(Page): def is_displayed(self): if self.player.round_number in Constants.last_rounds and self.player.requested_advice in ['Yes','1','2','12','3']: return True else: return False page_sequence = [ IntroIntro, InstructionLastRound, Intro, period1, period2, Bid, AdviceLastRound, period2_bis, Results ]