from . import models from ._builtin import Page, WaitPage from otree.api import Currency as c, currency_range from .models import Constants class Introduction1(Page): def is_displayed(self): return self.subsession.round_number == 1 class Introduction2(Page): def is_displayed(self): return self.subsession.round_number == 1 class Introduction3(Page): def is_displayed(self): return self.subsession.round_number == 1 class quiz(Page): def is_displayed(self): return self.subsession.round_number == 1 form_model = models.Player form_fields = ['quiz_1', 'quiz_2', 'quiz_3', 'quiz_4', 'quiz_5', 'quiz_6'] def error_message(self, values): print('values is', values) if values["quiz_1"] != "3 participants" or values["quiz_2"] != "20 rounds" or values["quiz_3"] != \ "The Buyer will then earn a monetary bonus of 20 points." or values["quiz_4"] != \ "The Buyer will then not earn a monetary bonus." or values["quiz_5"] != \ "That Seller will then earn the number of points he/she asked for his/her part of the puzzle." or \ values["quiz_6"] != "That Seller will then earn zero points in that round.": return 'You gave at least one incorrect answer. You have to answer all six quiz questions correctly to ' \ 'start with the puzzle-pieces task. If you have any questions about the task, you can ask the experimenter.' class Role(Page): def vars_for_template(self): sellerA = self.group.get_player_by_id(2) sellerB = self.group.get_player_by_id(3) if self.player.treatment == 2: sellerA.numberofpieces = "2 pieces" sellerB.numberofpieces = "2 pieces" else: sellerA.numberofpieces = "3 pieces" sellerB.numberofpieces = "1 piece" return {'numberofpieces1': sellerA.numberofpieces, 'numberofpieces2': sellerB.numberofpieces} def before_next_page(self): if self.player.treatment == 1: self.player.treatmentname = "unequal" else: self.player.treatmentname = "equal" self.player.order = self.group.order self.player.value_puzzle = Constants.value_puzzle self.player.buyer_endowment = Constants.buyer_endowment if self.player.id_in_group == 2 and self.player.order == 1: self.player.position = "first" if self.player.id_in_group == 3 and self.player.order == 1: self.player.position = "second" if self.player.id_in_group == 2 and self.player.order == 2: self.player.position = "second" if self.player.id_in_group == 3 and self.player.order == 2: self.player.position = "first" class WTA_first(Page): form_model = models.Player form_fields = ['WTA'] def is_displayed(self): return (self.player.id_in_group == 2 and self.player.order == 1) or (self.player.id_in_group == 3 and self.player.order == 2) def vars_for_template(self): sellerA = self.group.get_player_by_id(2) sellerB = self.group.get_player_by_id(3) if self.player.treatment == 2: sellerA.numberofpieces = "2 pieces" sellerB.numberofpieces = "2 pieces" else: sellerA.numberofpieces = "3 pieces" sellerB.numberofpieces = "1 piece" return {'numberofpieces1': sellerA.numberofpieces, 'numberofpieces2': sellerB.numberofpieces} class WTP1_first(Page): form_model = models.Player form_fields = ['WTP1'] def is_displayed(self): return self.player.id_in_group == 1 and self.player.order == 1 def error_message(self, values): if values["WTP1"] > Constants.value_puzzle: return 'You have an endowment of 20 points per round. ' \ 'Please make sure that your offers together do not exceed 20 points.' def vars_for_template(self): sellerA = self.group.get_player_by_id(2) sellerB = self.group.get_player_by_id(3) if self.player.treatment == 2: sellerA.numberofpieces = "2 pieces" sellerB.numberofpieces = "2 pieces" else: sellerA.numberofpieces = "3 pieces" sellerB.numberofpieces = "1 piece" return {'numberofpieces1': sellerA.numberofpieces, 'numberofpieces2': sellerB.numberofpieces} def before_next_page(self): self.group.WTP1 = self.player.WTP1 class WTP2_first(Page): form_model = models.Player form_fields = ['WTP2'] def is_displayed(self): return self.player.id_in_group == 1 and self.player.order == 2 def error_message(self, values): if values["WTP2"] > Constants.value_puzzle: return 'You have an endowment of 20 points per round. ' \ 'Please make sure that your offers together do not exceed 20 points.' def vars_for_template(self): sellerA = self.group.get_player_by_id(2) sellerB = self.group.get_player_by_id(3) if self.player.treatment == 2: sellerA.numberofpieces = "2 pieces" sellerB.numberofpieces = "2 pieces" else: sellerA.numberofpieces = "3 pieces" sellerB.numberofpieces = "1 piece" return {'numberofpieces1': sellerA.numberofpieces, 'numberofpieces2': sellerB.numberofpieces} class wait_for_first_seller(Page): def is_displayed(self): return (self.player.id_in_group == 3 and self.player.order == 1) or (self.player.id_in_group == 2 and self.player.order == 2) class Waitpage1(WaitPage): def after_all_players_arrive(self): self.group.first_deal() class outcome_first_transaction(Page): def vars_for_template(self): buyer = self.group.get_player_by_id(1) sellerA = self.group.get_player_by_id(2) sellerB = self.group.get_player_by_id(3) if buyer.order == 1: WTA_first = sellerA.WTA first_seller = "Seller A" if buyer.first_deal == True: deal = "The Buyer made a deal with Seller A to buy his/her part of the puzzle. Therefore, the Buyer " \ "now has Seller A's puzzle pieces in his/her possession." moneyleft = 20 - WTA_first if buyer.first_deal == False: deal = "The Buyer did NOT make a deal with Seller A to buy his/her part of the puzzle. Therefore, the Buyer " \ " does not have Seller A's puzzle pieces in his/her possession." moneyleft = 20 if buyer.order == 2: WTA_first = sellerB.WTA first_seller = "Seller B" if buyer.first_deal == True: deal = "The Buyer made a deal with Seller B to buy his/her part of the puzzle. Therefore, the Buyer " \ "now has Seller B's puzzle pieces in his/her possession." moneyleft = 20 - WTA_first else: deal = "The Buyer did NOT make a deal with Seller B to buy his/her part of the puzzle. Therefore, the Buyer " \ " does not have Seller B's puzzle pieces in his/her possession." moneyleft = 20 return {'deal': deal, 'WTA_first': WTA_first, 'first_seller': first_seller, 'moneyleft': moneyleft} class WTA_second(Page): form_model = models.Player form_fields = ['WTA'] def is_displayed(self): return (self.player.id_in_group == 3 and self.player.order == 1) or (self.player.id_in_group == 2 and self.player.order == 2) def vars_for_template(self): sellerA = self.group.get_player_by_id(2) sellerB = self.group.get_player_by_id(3) if self.player.treatment == 2: sellerA.numberofpieces = "2 pieces" sellerB.numberofpieces = "2 pieces" else: sellerA.numberofpieces = "3 pieces" sellerB.numberofpieces = "1 piece" return {'numberofpieces1': sellerA.numberofpieces, 'numberofpieces2': sellerB.numberofpieces} class wait_for_second_seller(Page): def is_displayed(self): return (self.player.id_in_group == 2 and self.player.order == 1) or (self.player.id_in_group == 3 and self.player.order == 2) class WTP1_second(Page): form_model = models.Player form_fields = ['WTP1'] def is_displayed(self): return self.player.id_in_group == 1 and self.player.order == 2 def error_message(self, values): buyer = self.group.get_player_by_id(1) sellerA = self.group.get_player_by_id(2) sellerB = self.group.get_player_by_id(3) if buyer.first_deal == True: if values["WTP1"] > (Constants.value_puzzle - sellerB.WTA): return 'You have an endowment of 20 points per round. ' \ 'Please make sure that your offers together do not exceed 20 points.' if buyer.first_deal == False: if values["WTP1"] > (Constants.value_puzzle): return 'You have an endowment of 20 points per round. ' \ 'Please make sure that your offer does not exceed 20 points.' def vars_for_template(self): sellerA = self.group.get_player_by_id(2) sellerB = self.group.get_player_by_id(3) if self.player.treatment == 2: sellerA.numberofpieces = "2 pieces" sellerB.numberofpieces = "2 pieces" else: sellerA.numberofpieces = "3 pieces" sellerB.numberofpieces = "1 piece" return {'numberofpieces1': sellerA.numberofpieces, 'numberofpieces2': sellerB.numberofpieces} class WTP2_second(Page): form_model = models.Player form_fields = ['WTP2'] def is_displayed(self): return self.player.id_in_group == 1 and self.player.order == 1 def error_message(self, values): buyer = self.group.get_player_by_id(1) sellerA = self.group.get_player_by_id(2) sellerB = self.group.get_player_by_id(3) if buyer.first_deal == True: if values["WTP2"] > (Constants.value_puzzle - sellerA.WTA): return 'You have an endowment of 20 points per round. ' \ 'Please make sure that your offers together do not exceed 20 points.' if buyer.first_deal == False: if values["WTP2"] > (Constants.value_puzzle): return 'You have an endowment of 20 points per round. ' \ 'Please make sure that your offer does not exceed 20 points.' def vars_for_template(self): sellerA = self.group.get_player_by_id(2) sellerB = self.group.get_player_by_id(3) if self.player.treatment == 2: sellerA.numberofpieces = "2 pieces" sellerB.numberofpieces = "2 pieces" else: sellerA.numberofpieces = "3 pieces" sellerB.numberofpieces = "1 piece" return {'numberofpieces1': sellerA.numberofpieces, 'numberofpieces2': sellerB.numberofpieces} class ResultsWaitPage(WaitPage): def after_all_players_arrive(self): self.group.set_payoffs() class Results(Page): def vars_for_template(self): buyer = self.group.get_player_by_id(1) sellerA = self.group.get_player_by_id(2) sellerB = self.group.get_player_by_id(3) WTA1 = sellerA.WTA WTA2 = sellerB.WTA WTP1 = buyer.WTP1 WTP2 = buyer.WTP2 price_puzzle = sellerA.payoff + sellerB.payoff payoff_sellerA = sellerA.payoff payoff_sellerB = sellerB.payoff payoff_buyer = buyer.payoff spent = sellerA.payoff + sellerB.payoff if sellerA.sell == True: deal1 = "Therefore, the Buyer made a deal with Seller A to buy his/her part of the puzzle for" deal1b = "The Buyer made a deal with Seller A." else: deal1 = "Therefore, the Buyer did not make a deal with Seller A to buy his/her part of the puzzle for" deal1b = "The Buyer did not make a deal with Seller A." if sellerB.sell == True: deal2 = "Therefore, the Buyer made a deal with Seller B to buy his/her part of the puzzle for" deal2b = "The Buyer made a deal with Seller B." else: deal2 = "Therefore, the Buyer did not make a deal with Seller B to buy his/her part of the puzzle for" deal2b = "The Buyer did not make a deal with Seller B." if buyer.success == True: successornot = "The Buyer managed to buy the whole puzzle from the two sellers, and therefore the Buyer receives a bonus of" successornot2 = "This means that the Buyer managed to obtain the whole puzzle!" else: successornot = "The Buyer did not manage to buy the whole puzzle from the two sellers, and therefore the Buyer does not receive a bonus of" successornot2 = "This means that the Buyer did not manage to obtain the whole puzzle!" return {'WTA1': WTA1, 'WTA2': WTA2, 'WTP1': WTP1, 'WTP2': WTP2, 'price_puzzle': price_puzzle, 'payoff_sellerA': payoff_sellerA, 'payoff_sellerB': payoff_sellerB, 'payoff_buyer': payoff_buyer, 'deal1': deal1, 'deal1b': deal1b, 'deal2': deal2, 'deal2b': deal2b, 'successornot': successornot, 'successornot2': successornot2,'spent': spent} class Waitpage2(WaitPage): pass class motives(Page): def is_displayed(self): return self.subsession.round_number == Constants.num_rounds form_model = models.Player form_fields = ['motive_1', 'motive_2', 'motive_3', 'motive_4', 'motive_5', 'motive_6', 'motive_7', 'motive_8'] page_sequence = [ Introduction1, Introduction2, Introduction3, quiz, Role, WTA_first, wait_for_first_seller, WTP1_first, WTP2_first, Waitpage1, outcome_first_transaction, WTA_second, wait_for_second_seller, WTP1_second, WTP2_second, ResultsWaitPage, Results, Waitpage2, motives ]