from otree.api import * from otree.settings import settings import time doc = """ Merged explanation app for structured and structured_NL treatments """ class C(BaseConstants): NAME_IN_URL = 'explanation' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): start_time_Explanation1 = models.FloatField() time_spent_Explanation1 = models.FloatField() start_time_Explanation2 = models.FloatField() time_spent_Explanation2 = models.FloatField() treatment_group = models.StringField() class Explanation1(Page): @staticmethod def vars_for_template(player: Player): player.treatment_group = player.participant.treatment_group if player.field_maybe_none('start_time_Explanation1') is None: player.start_time_Explanation1 = time.time() total_pages = settings.TOTAL_PAGES_treatment_structured_com_NL current_index = player.participant._index_in_pages progress_percent = int(current_index / total_pages * 100) return { 'progress_percent': progress_percent, 'total_pages': total_pages, 'current_index': current_index, } @staticmethod def before_next_page(player: Player, timeout_happened=False): player.time_spent_Explanation1 = time.time() - player.start_time_Explanation1 class Explanation2(Page): # @staticmethod def vars_for_template(player: Player): player.treatment_group = player.participant.treatment_group if player.field_maybe_none('start_time_Explanation2') is None: player.start_time_Explanation2 = time.time() total_pages = settings.TOTAL_PAGES_treatment_structured_com_NL current_index = player.participant._index_in_pages progress_percent = int(current_index / total_pages * 100) return { 'progress_percent': progress_percent, 'total_pages': total_pages, 'current_index': current_index, } # @staticmethod def before_next_page(player: Player, timeout_happened=False): player.time_spent_Explanation2 = time.time() - player.start_time_Explanation2 page_sequence = [Explanation1, Explanation2]