import random import time from otree.api import * from intro import ( C as CIntro, CustomTimeoutPage, survey_third_party_is_ai, third_party_estimate_label, third_party_popover_body, treatment_has_ai, treatment_is_single, ) from markupsafe import Markup doc = """ Your app description """ class C(CIntro): NAME_IN_URL = 'practice' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): player_count = models.IntegerField(initial=0) class Group(BaseGroup): pass class Player(BasePlayer): private_prediction = models.IntegerField( label=Markup( "What do you think this student's score was? (Please enter a number: 1-100)" ), min=1, max=100, blank=True, null=True, ) shared_prediction = models.IntegerField( label=Markup( "Share your estimated score with your partner. You can keep or change your previous estimate.
" "Note:This estimate will be shared with your partner" ), min=1, max=100, blank=True, null=True, ) team_prediction = models.IntegerField( label="What is your final estimate at this stage? (Please enter a number: 1-100)", min=1, max=100, blank=True, null=True, ) current_step = models.IntegerField(initial=1) treatment = models.StringField(initial='') def get_interface_data(player: Player): return player.session.vars['interface_data'] def participant_is_single_player(player: Player) -> bool: if player.participant.vars.get('is_single'): return True return treatment_is_single(player.participant.treatment or '') def group_by_arrival_time_method(subsession: Subsession, waiting_players: list[Player]): """Treatment already assigned in intro app. Just pass everyone through as solo groups.""" if len(waiting_players) == 0: return None player = waiting_players[0] # Copy treatment to practice player model for data export player.treatment = player.participant.vars.get('treatment', '') subsession.player_count += 1 return [player] # PAGES class GroupWaitPage(WaitPage): group_by_arrival_time = True class PracticePrivate(CustomTimeoutPage): form_model = 'player' form_fields = ['private_prediction'] @staticmethod def vars_for_template(player: Player): return dict( data=get_interface_data(player), is_single=participant_is_single_player(player), ) @staticmethod def before_next_page(player: Player, timeout_happened): player.private_prediction = 87 player.shared_prediction = player.private_prediction player.current_step += 1 class PracticeChat(CustomTimeoutPage): @staticmethod def vars_for_template(player: Player): t = player.participant.treatment or '' return dict( contains_ai=treatment_has_ai(t), data=get_interface_data(player), third_party_estimate_label=third_party_estimate_label(t), third_party_popover_body=third_party_popover_body(t), is_single=participant_is_single_player(player), survey_third_party_is_ai=survey_third_party_is_ai(t), my_prediction=player.field_maybe_none('shared_prediction'), ) @staticmethod def before_next_page(player: Player, timeout_happened): player.current_step += 1 class PracticeTeam(CustomTimeoutPage): form_model = 'player' form_fields = ['team_prediction'] @staticmethod def vars_for_template(player: Player): t = player.participant.treatment or '' return dict( data=get_interface_data(player), third_party_estimate_label=third_party_estimate_label(t), third_party_popover_body=third_party_popover_body(t), is_single=participant_is_single_player(player), my_prediction=player.field_maybe_none('shared_prediction'), ) @staticmethod def before_next_page(player: Player, timeout_happened): player.current_step += 1 player.team_prediction = player.shared_prediction player.participant.vars['wait_page_arrival_time'] = time.time() page_sequence = [ GroupWaitPage, PracticePrivate, PracticeChat, PracticeTeam, ]