from otree.api import * from otree.settings import settings import time doc = """ Welcome page for subjects taking part to the designing of statistical communication plan """ class C(BaseConstants): NAME_IN_URL = 'comprehension_check' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): start_time_questions = models.FloatField() time_spent_questions = models.FloatField() start_time_transition = models.FloatField() time_spent_transition = models.FloatField() n_submissions = models.IntegerField() private_account_balance_p1 = models.IntegerField( choices=[ [4, '4 tokens'], [6, '6 tokens'] ], label="How many tokens are there in participant 1’s private account?", widget=widgets.RadioSelect ) check_total_contribution = models.IntegerField( choices=[ [6, '6 tokens'], [10, '10 tokens'] ], label="How many tokens are there in the shared account?", widget=widgets.RadioSelect ) check_tokens_from_common_project = models.IntegerField( choices=[ [2, '2 tokens'], [6, '6 tokens'] ], label="How many tokens does the shared account return to each participant?", widget=widgets.RadioSelect ) best_strategy_gamma_high = models.StringField( choices=["Invest all tokens in shared account", "Keep all tokens in private account", "Invest half of tokens in the shared account", "It depends on Player 2 's strategy"], label="In this case, what is the best decision for Player 1 if they want to earn as many tokens as possible?", widget=widgets.RadioSelect ) # FUNCTIONS # PAGES class Questions(Page): form_model = 'player' form_fields = ["private_account_balance_p1", "check_total_contribution", "check_tokens_from_common_project", "best_strategy_gamma_high"] # @staticmethod def vars_for_template(player: Player): if player.field_maybe_none('start_time_questions') is None: player.start_time_questions = time.time() player.n_submissions = 0 # remaining_submissions = max(0,5 - player.n_submissions) comprehension_check_link = player.session.config['comprehension_check_link'] # 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, 'remaining_submissions': remaining_submissions, 'comprehension_check_link' : comprehension_check_link} # def error_message(player, values): solutions = dict( private_account_balance_p1=4, check_total_contribution=10, check_tokens_from_common_project=6, best_strategy_gamma_high="Invest all tokens in shared account" ) if any(values[field_name] != solutions[field_name] for field_name in solutions): player.n_submissions += 1 return 'Wrong answer. Please try again.' # @staticmethod def before_next_page(player: Player, timeout_happened=False): player.time_spent_questions = time.time() - player.start_time_questions class Transition(Page): @staticmethod def vars_for_template(player: Player): if player.field_maybe_none('start_time_transition') is None: player.start_time_transition = 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_transition = time.time() - player.start_time_transition page_sequence = [Questions, Transition]