from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class Introduction(Page): def is_displayed(self) -> bool: return( # Show this page only for treatment 1 in round 1 self.participant.vars['treatment'] == 1 and self.subsession.round_number == 1 ) class ExecutiveStory(Page): def is_displayed(self) -> bool: return( # Show this page only for treatment 1 in round 1 self.participant.vars['treatment'] == 1 and self.subsession.round_number == 1 ) def before_next_page(self): # Set: Argument collecting start time self.participant.vars['argument_collecting_start_time'] = self.subsession.get_current_timestamp() class CollectArguments(Page): form_model = 'player' form_fields = [ 'ARGUMENT_TYPE', 'PRO_ARG_TEXT', 'CON_ARG_TEXT' ] def is_displayed(self) -> bool: return( # Show this page only for treatment 1 if argument collecting time isn't over self.participant.vars['treatment'] == 1 and not self.participant.vars['argument_collecting_time_is_over'] ) def get_timeout_seconds(self): return( # Players argument collecting start time PLUS self.participant.vars['argument_collecting_start_time'] + # Defined argument collecting total time MINUS Constants.argument_collecting_time - # Current time self.subsession.get_current_timestamp() ) def vars_for_template(self): # Get: All collected arguments arguments_table = self.player.get_arguments_for_template() # Return: Collected arguments return dict( arguments_table=arguments_table.items() ) def before_next_page(self): # Set: Error message for pro argument to false self.participant.vars['pro_argument_is_empty_error'] = False # Set: Error message for contra argument to false self.participant.vars['con_argument_is_empty_error'] = False # Check: Is the time over? if self.participant.vars['argument_collecting_start_time'] + \ Constants.argument_collecting_time - self.subsession.get_current_timestamp() <= 0: # Set: Argument collecting time is over self.participant.vars['argument_collecting_time_is_over'] = True # Check: Is the submit button for a pro argument pressed? if self.player.ARGUMENT_TYPE == 'PRO': # Set: Contra argument text to empty self.player.CON_ARG_TEXT = '' # Check: Is the pro argument empty? if self.player.PRO_ARG_TEXT.strip() == '': # Set: Pro argument text to empty self.player.PRO_ARG_TEXT = '' # Set: Error message to true self.participant.vars['pro_argument_is_empty_error'] = True else: # Increase: Pro argument counter self.participant.vars['pro_argument_counter'] += 1 # Data base: Add argument number self.player.ARGUMENT_NUMBER = 2 * self.participant.vars['pro_argument_counter'] - 1 # Check: Is the submit button for a contra argument pressed? elif self.player.ARGUMENT_TYPE == 'CONTRA': # Set: Contra argument text to empty self.player.PRO_ARG_TEXT = '' # Check: Is the pro argument empty? if self.player.CON_ARG_TEXT.strip() == '': # Set: Pro argument text to empty self.player.CON_ARG_TEXT = '' # Set: Error message to true self.participant.vars['con_argument_is_empty_error'] = True else: # Increase: Pro argument counter self.participant.vars['con_argument_counter'] += 1 # Data base: Add argument number self.player.ARGUMENT_NUMBER = 2 * self.participant.vars['con_argument_counter'] # Check: Is there an error on this page? if self.participant.vars['pro_argument_is_empty_error'] or \ self.participant.vars['con_argument_is_empty_error']: # Stay on this page self._is_frozen = False self._index_in_pages -= 1 self.participant._index_in_pages -= 1 class MostConvincingArguments(Page): form_model = 'player' form_fields = [ 'MOST_CONV_PRO_ARG', 'MOST_CONV_CON_ARG' ] def is_displayed(self) -> bool: return( # Show this page only for treatment 1 in last round WHEN self.participant.vars['treatment'] == 1 and self.subsession.round_number == Constants.num_rounds and # There is at least one argument (self.participant.vars['pro_argument_counter'] > 0 or self.participant.vars['con_argument_counter'] > 0) ) def vars_for_template(self): # Get: All collected arguments arguments_table = self.player.get_arguments_for_template() # Return: Collected arguments return dict( arguments_table=arguments_table.items() ) page_sequence = [ Introduction, ExecutiveStory, CollectArguments, MostConvincingArguments ]