from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class Investment(Page): form_model = 'player' form_fields = ['investment', 'num_clicks'] def vars_for_template(self): if self.round_number == 1 and self.player.id_in_group == 1: self.player.endowment = Constants.endowment1 if self.round_number == 1 and self.player.id_in_group == 2: self.player.endowment = Constants.endowment1 if self.round_number == 2 and self.player.id_in_group == 1: self.player.endowment = Constants.endowment1 if self.round_number == 2 and self.player.id_in_group == 2: self.player.endowment = Constants.endowment2 if self.round_number == 3 and self.player.id_in_group == 1: self.player.endowment = Constants.endowment2 if self.round_number == 3 and self.player.id_in_group == 2: self.player.endowment = Constants.endowment1 if self.round_number == 4 and self.player.id_in_group == 1: self.player.endowment = Constants.endowment2 if self.round_number == 4 and self.player.id_in_group == 2: self.player.endowment = Constants.endowment2 return {'label': "How much will you contribute to the project (from 0 to {})".format(self.player.endowment)} class ResultsWaitPage(WaitPage): def after_all_players_arrive(self): self.group.set_payoffs() if self.round_number == 2: self.group.fark1() if self.round_number == 3: self.group.fark2() if self.round_number == Constants.num_rounds: for p in self.group.get_players(): if p.id_in_group == 1: p.fark = p.in_round(2).fark if p.id_in_group == 2: p.fark = p.in_round(3).fark for p in self.group.get_players(): if self.round_number == 1: p.participant.vars['PRO_total_investment_1'] = self.group.in_round(1).total_investment p.participant.vars['PRO_result_1'] = self.group.in_round(1).resultStatus p.participant.vars['PRO_total_payoff_1'] = self.group.in_round(1).total_payoff if self.round_number == 2: p.participant.vars['PRO_total_investment_2'] = self.group.in_round(2).total_investment p.participant.vars['PRO_result_2'] = self.group.in_round(2).resultStatus p.participant.vars['PRO_total_payoff_2'] = self.group.in_round(2).total_payoff if self.round_number == 3: p.participant.vars['PRO_total_investment_3'] = self.group.in_round(3).total_investment p.participant.vars['PRO_result_3'] = self.group.in_round(3).resultStatus p.participant.vars['PRO_total_payoff_3'] = self.group.in_round(3).total_payoff if self.round_number == 4: p.participant.vars['PRO_total_investment_4'] = self.group.in_round(4).total_investment p.participant.vars['PRO_result_4'] = self.group.in_round(4).resultStatus p.participant.vars['PRO_total_payoff_4'] = self.group.in_round(4).total_payoff class Results_FinalWaitPage(WaitPage): def is_displayed(self): return self.round_number == Constants.num_rounds body_text = "ESAS AŞAMA BİTTİ. Lüfen bekleyin." def after_all_players_arrive(self): if self.round_number == Constants.num_rounds: for p in self.group.get_players(): p.payoff = p.in_round(Constants.rounds_to_pay).pyf print('player payoff:', p.payoff) ### PRO ### p.participant.vars['PRO_payoff'] = p.in_round(Constants.rounds_to_pay).pyf p.participant.vars['PRO_paying_round'] = Constants.rounds_to_pay p.participant.vars['PRO_rule'] = Constants.kural p.participant.vars['PRO_investment_1'] = p.in_round(1).investment p.participant.vars['PRO_investment_2'] = p.in_round(2).investment p.participant.vars['PRO_investment_3'] = p.in_round(3).investment p.participant.vars['PRO_investment_4'] = p.in_round(4).investment p.participant.vars['PRO_payment_1'] = p.in_round(1).pyf p.participant.vars['PRO_payment_2'] = p.in_round(2).pyf p.participant.vars['PRO_payment_3'] = p.in_round(3).pyf p.participant.vars['PRO_payment_4'] = p.in_round(4).pyf p.participant.vars['PRO_fark'] = p.fark class Results(Page): pass page_sequence = [Investment, ResultsWaitPage, Results_FinalWaitPage]