from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import random ''' this the where all the designs for the pages to be displayed are organised. the sequence of display is at the bottom each page with Page Class is displayed and WaitPage class are pages where calculations are done. WaitPage class page are not displayed to the players but we can use functions like "after_all_players_arrive" to make all of the players wait till other players have reached those pages. ''' class Welcome(Page): pass class Instruction_part_1(Page): pass class Instruction_part_2(Page): pass class Instruction_part_3(Page): pass class Instruction_part_4(Page): pass class Choose_Product(Page): def is_displayed(self): return self.player.id_in_group == 1 form_model = 'player' form_fields = ['chosen_product'] # Choice of Product - value that the participant enters gets stored in player.chosen_product class Choose_Product_player2(Page): def is_displayed(self): return self.player.id_in_group == 2 form_model = 'player' form_fields = ['chosen_product'] # Choice of Product - value that the participant enters gets stored in player.chosen_product class Choose_Quantity(Page): def is_displayed(self): return self.player.id_in_group == 1 form_model = 'player' form_fields = ['chosen_quantity'] # Choice of Product quantity - value that the participant enters gets stored in player.chosen_quantity class Choose_Quantity_player2(Page): def is_displayed(self): return self.player.id_in_group == 2 form_model = 'player' form_fields = ['chosen_quantity'] # Choice of Product quantity - value that the participant enters gets stored in player.chosen_quantity class Feedback_1(Page):#no calculation is done here, all the values genrated in wait_page above is fetched in the template page def is_displayed(self): return self.player.id_in_group == 1 def vars_for_template(self): group = self.group product =[p.chosen_product for p in group.get_players()] quantity = [p.chosen_quantity for p in group.get_players()] quantity[1]= 200 true_demand = Constants.true_market_demand # the true_demand array generated at the start of the session is fetched players_in_the_game = self.group.get_players() if (self.player.id_in_group == 1): players_in_the_game[0].bonus = Constants.bonus_multiplier * true_demand[product[0]-1] - Constants.bonus_multiplier * abs(true_demand[product[0]-1]- quantity[0]) players_in_the_game[0].true_demand_stage1 = true_demand[product[0]-1] players_in_the_game[0].forecast_stage1 = str(Constants.forecast_matrix_P1) class Feedback_1_player2(Page): # no calculation is done here, all the values genrated in wait_page above is fetched in the template page def is_displayed(self): return self.player.id_in_group == 2 def vars_for_template(self): group = self.group product = [p.chosen_product for p in group.get_players()] quantity = [p.chosen_quantity for p in group.get_players()] quantity[0] = 200 true_demand = Constants.true_market_demand # the true_demand array generated at the start of the session is fetched players_in_the_game = self.group.get_players() if (self.player.id_in_group == 2): players_in_the_game[1].bonus = Constants.bonus_multiplier * true_demand[product[1]-1] - Constants.bonus_multiplier * abs(true_demand[product[1]-1]- quantity[1]) players_in_the_game[1].true_demand_stage1 = true_demand[product[1] - 1] players_in_the_game[1].forecast_stage1= str(Constants.forecast_matrix_P2) class Instruction_section_2(Page): pass class section2_WaitPage1(WaitPage): def after_all_players_arrive(self): player = self.group.get_players() for p in range(0,Constants.num_of_players): if player[p].id_in_group==1: player[p].chosen_product2= player[p+1].chosen_product elif player[p].id_in_group==2: player[p].chosen_product2=player[p-1].chosen_product class Choose_Quantity_2(Page): def is_displayed(self): return self.player.id_in_group == 1 def vars_for_template(self): player = self.group.get_players() for p in player: if p.id_in_group==1: chosen_product = p.chosen_product2 forecast_to_show = [0] * Constants.num_of_forecaster for f in range(0,Constants.num_of_forecaster): forecast_to_show[f] = Constants.forecast_matrix_P2[f][chosen_product-1] players_in_the_game = self.group.get_players() if (self.player.id_in_group == 1): players_in_the_game[0].forecast_stage2 = str(forecast_to_show) return {'forecast_to_show': forecast_to_show} form_model = 'player' form_fields = ['chosen_quantity2'] # Choice of Product quantity - Values enterd by the player writes player.chosen_quantity class Choose_Quantity_2_player2(Page): def is_displayed(self): return self.player.id_in_group == 2 def vars_for_template(self): player = self.group.get_players() for p in player: if p.id_in_group == 2: chosen_product2 = p.chosen_product2 forecast_to_show_2 = [0] * Constants.num_of_forecaster for f in range(0,Constants.num_of_forecaster): forecast_to_show_2[f] = Constants.forecast_matrix_P1[f][chosen_product2-1] players_in_the_game = self.group.get_players() if (self.player.id_in_group == 2): players_in_the_game[1].forecast_stage2 = str(forecast_to_show_2) return {'forecast_to_show_2': forecast_to_show_2} form_model = 'player' form_fields = ['chosen_quantity2'] # Choice of Product quantity - Values enterd by the player writes player.chosen_quantity class Feedback_2(Page): #fetches the value of true_demand for display def is_displayed(self): return self.player.id_in_group == 1 def vars_for_template(self): group = self.group true_demand = Constants.true_market_demand quantity = [p.chosen_quantity2 for p in group.get_players()] quantity[1] = 200 players_in_the_game = self.group.get_players() if (self.player.id_in_group == 1): players_in_the_game[0].bonus2 = Constants.bonus_multiplier * true_demand[players_in_the_game[0].chosen_product2-1] - Constants.bonus_multiplier * abs(true_demand[players_in_the_game[0].chosen_product2-1] - quantity[0]) players_in_the_game[0].true_demand_stage2 = true_demand[players_in_the_game[0].chosen_product2 - 1] return {'true_demand': Constants.true_market_demand} class Feedback_2_player2(Page): # fetches the value of true_demand for display def is_displayed(self): return self.player.id_in_group == 2 def vars_for_template(self): group = self.group true_demand = Constants.true_market_demand quantity = [p.chosen_quantity2 for p in group.get_players()] quantity[0] = 200 players_in_the_game = self.group.get_players() if (self.player.id_in_group == 2): players_in_the_game[1].bonus2 = Constants.bonus_multiplier * true_demand[players_in_the_game[1].chosen_product2 - 1] - Constants.bonus_multiplier * abs(true_demand[players_in_the_game[1].chosen_product2 - 1] - quantity[1]) players_in_the_game[1].true_demand_stage2 = true_demand[players_in_the_game[1].chosen_product2 - 1] return {'true_demand': Constants.true_market_demand} class End_of_survey(Page):#this page is displayed only after the final round of game is played. def is_displayed(self): return self.round_number >= Constants.num_rounds # this is the sequence of the page to be displayed page_sequence = [ Welcome, Instruction_part_1, Instruction_part_2, Instruction_part_3, Instruction_part_4, Choose_Product, Choose_Product_player2, Choose_Quantity, Choose_Quantity_player2, Feedback_1, Feedback_1_player2, Instruction_section_2, section2_WaitPage1, Choose_Quantity_2, Choose_Quantity_2_player2, Feedback_2, Feedback_2_player2, End_of_survey, ]