from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage, SurveyPage from .models import Constants class Introduction(Page): def vars_for_template(self): partner = self.player.get_others_in_group()[0] return { 'round_number': '{}' .format(self.round_number) } class instructions(Page): def is_displayed(self): return self.round_number == 1 form_model = 'player' form_fields = ['accept'] class Send(Page): """This page is only for P1 P1 sends amount (all, some, or none) to P2 """ form_model = 'group' form_fields = ['sent_amount' , 'expect_decider'] def is_displayed(self): return self.player.id_in_group == 1 def vars_for_template(self): return { 'round_number': '{}' .format(self.round_number), 'prompt': '0 ile {} arasında bir sayı giriniz.'.format(Constants.endowment_Decider-2), } class SendBackWaitPage(WaitPage): pass class SendBack(Page): """This page is only for P2 P2 sends back some amount (of the amount received) to P1""" form_model = 'group' form_fields = ['sent_back_amount'] def is_displayed(self): return self.player.id_in_group == 2 def vars_for_template(self): return { 'round_number': '{}' .format(self.round_number), 'prompt': '0 ile {} arasında bir sayı giriniz.'.format(Constants.endowment_Decider-2), 'earnings': Constants.endowment_Receiver + self.group.sent_amount, } class ResultsWaitPage(WaitPage): def after_all_players_arrive(self): self.group.set_payoffs() class Results(Page): """This page displays the earnings of each player""" def vars_for_template(self): return { 'round_number': '{}' .format(self.round_number), 'player1_period1_amount': Constants.endowment_Decider - self.group.sent_amount, 'player1_period2_amount': Constants.endowment_Receiver + self.group.sent_back_amount, 'player2_period1_amount': Constants.endowment_Receiver + self.group.sent_amount, 'player2_period2_amount': Constants.endowment_Decider - self.group.sent_back_amount, 'player1_payoff' : (Constants.endowment_Decider - self.group.sent_amount) * (Constants.endowment_Receiver + self.group.sent_back_amount), 'player2_payoff' : (Constants.endowment_Receiver + self.group.sent_amount) * (Constants.endowment_Decider - self.group.sent_back_amount) } class OverallResults(Page): """This page displays the earnings of each player""" def is_displayed(self): return self.round_number == Constants.num_rounds def vars_for_template(self): cumulative_payoff = sum([p.payoff for p in self.player.in_all_rounds()]) return { 'overall_earnings': cumulative_payoff } class Survey(SurveyPage): """This page displays the questionnaire for each player""" def is_displayed(self): return self.round_number == Constants.num_rounds form_model = 'player' form_fields = ['dep','edu','age','gen','inc', 'h_inc', 'investment_options_1', 'investment_options_2', 'investment_options_3', 'investment_options_4', 'investment_options_5', 'investment_options_6', 'investment_options_7', 'investment_options_8', 'investment_options_9', 'investment_options_10', 'env_cons_2', 'env_cons_3', 'env_cons_5', 'env_cons_6', 'env_cons_7', 'env_cons_9', 'fate', 'believe', 'gpa' ] page_sequence = [ instructions, Introduction, Send, SendBackWaitPage, SendBack, ResultsWaitPage, Results, Survey, OverallResults ]