from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class InstructionsPage(Page): def vars_for_template(self): return dict( participant_id=self.player.participant.id_in_session, round_number=self.round_number ) def is_displayed(self): return self.round_number == 1 class InstructionsStage2Page(Page): def vars_for_template(self): figure1 = 'Image/Stage 2 Fig 1 Control.png' figure2 = 'Image/Stage 2 Fig 2 Control.png' figure3 = 'Image/Stage 2 Fig 3 Control.png' return dict( participant_id=self.player.participant.id_in_session, round_number=self.round_number, figure1=figure1, figure2=figure2, figure3=figure3 ) def is_displayed(self): return self.round_number == 1 class ControlQuestionnaire1Page(Page): form_model = 'player' form_fields = ['question1', 'question2', 'question3', 'question4', 'question5', 'question6'] def vars_for_template(self): return dict( participant_id=self.player.participant.id_in_session, round_number=self.round_number ) def is_displayed(self): return self.round_number == 1 class ViewCodeBookPage(Page): live_method = 'viewCodebookTapped' def before_next_page(self): pass def vars_for_template(self): commonFunctions = self.participant.vars['CommonFunctions'] context_images = commonFunctions.getContextImagesPath(self.round_number) action_images = commonFunctions.getActionImagesPath(self.round_number) row_images = [] for i in range(0, 4): x = [action_images[i]] for j in range(0, 4): if i==j: x.append('Image/tick.png') else: x.append('Image/cross.png') row_images.append(x) return dict( participant_id=self.player.participant.id_in_session, context_images=context_images, row_images=row_images, view_codebook_count=self.player.view_codebook_count_left, round_number=self.round_number, ) def js_vars(self): return dict( view_codebook_count=self.player.view_codebook_count_left, ) class ChooseActionPage(Page): form_model = 'player' form_fields = ['action_choice'] def before_next_page(self): commonFunctions = self.participant.vars['CommonFunctions'] getActionImagesGroup = commonFunctions.getActionImagesGroup(self.round_number) if getActionImagesGroup[self.player.context_image_number-1] == self.player.action_choice: self.player.check_action_choice = 1 self.player.payoff += 1 else: self.player.check_action_choice = 0 # if self.timeout_happened and self.player.action_choice == None: # self.player.action_choice = 0 # self.player.check_action_choice = 0 # else: # if commonFunctions.getActionImagesGroup(self.player.group.id_in_subsession, self.round_number)[self.player.group.context_image_number-1] == self.player.action_choice: # self.player.check_action_choice = 1 # self.player.payoff += 1 # else: # self.player.check_action_choice = 0 def vars_for_template(self): commonFunctions = self.participant.vars['CommonFunctions'] context_images_group = commonFunctions.getContextImagesGroup(self.round_number) context_image = f'Image/{commonFunctions.random_group}Env{context_images_group}{self.player.context_image_number}.png' action_images = [f'Image/0Action{i}.png' for i in range(1, 5)] return dict( participant_id=self.player.participant.id_in_session, action_images=action_images, context_image=context_image, round_number=self.round_number, ) class ResultsWaitPage(WaitPage): def after_all_players_arrive(self): pass class Results(Page): def vars_for_template(self): commonFunctions = self.participant.vars['CommonFunctions'] player_action_choice_image = f'Image/0Action{self.player.action_choice}.png' context_images_group = commonFunctions.getContextImagesGroup(self.round_number) context_image = f'Image/{commonFunctions.random_group}Env{context_images_group}{self.player.context_image_number}.png' players = self.player.in_rounds(1, self.round_number) score = int(sum([player.payoff for player in players])) tickCrossImage = commonFunctions.getTickCrossImage(self.player) return dict( participant_id=self.player.participant.id_in_session, player_action_choice_image=player_action_choice_image, context_image=context_image, tickCrossImage=tickCrossImage, round_number=self.round_number, score=score ) page_sequence = [InstructionsPage, ControlQuestionnaire1Page, InstructionsStage2Page, ViewCodeBookPage, ChooseActionPage, Results]