from otree.api import * import static_data.generateAllPaths as gPaths import time relTreatments = [1,3] doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'pDecolor' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): # Comprehension Questions compQ_1 = models.StringField() compQ_2 = models.StringField() compQ_3 = models.StringField() compQ_4 = models.StringField() # Save task information decoloringExplain = models.LongStringField() decoloring = models.LongStringField() # PAGES class pathDependentStop(Page): @staticmethod def is_displayed(player): return (player.participant.treatment in relTreatments) and not player.participant.timeoutHappened and not player.participant.demo @staticmethod def js_vars(player: Player): return dict( winProb = player.session.config["winProb"], upTick = player.session.config["upTick_Intro"], min_time_on_page = player.session.config["min_time_on_page_instructions"], testing = player.session.config["testing"], allPaths = gPaths.getAllPaths() ) @staticmethod def vars_for_template(player: Player): return dict( testing = player.session.config["testing"], endowment = '£%.2f' % player.session.config["endowment"], costly = (player.participant.treatment == 3), costPerBall = '£%.2f' % player.session.config["costPerBall"] ) @staticmethod def get_timeout_seconds(player): participant = player.participant return participant.expiry - time.time() @staticmethod def before_next_page(player, timeout_happened): if timeout_happened: player.participant.timeoutHappened = True player.session.dropouts.append(player.participant.treatment) player.session.actives[player.participant.treatment] = player.session.actives[player.participant.treatment] - 1 class decoloringExplain(Page): @staticmethod def is_displayed(player): return (player.participant.treatment in relTreatments) and not player.participant.timeoutHappened and not player.participant.demo @staticmethod def js_vars(player): return dict( winProb = player.session.config["winProb"], upTick = player.session.config["upTick_Intro"], min_time_on_page = player.session.config["min_time_on_page_instructions"], testing = player.session.config["testing"], initialColor = player.participant.plotColor, allPaths = gPaths.getAllPaths() ) @staticmethod def vars_for_template(player: Player): return dict( testing = player.session.config["testing"], ) @staticmethod def live_method(player, data): player.decoloringExplain = str(data) @staticmethod def get_timeout_seconds(player): participant = player.participant return participant.expiry - time.time() @staticmethod def before_next_page(player, timeout_happened): if timeout_happened: player.participant.timeoutHappened = True player.session.dropouts.append(player.participant.treatment) player.session.actives[player.participant.treatment] = player.session.actives[player.participant.treatment] - 1 class compQ(Page): form_model = "player" form_fields = [ "compQ_1", "compQ_2", "compQ_3", "compQ_4", ] @staticmethod def is_displayed(player): return (player.participant.treatment in relTreatments) and not player.participant.timeoutHappened and not player.participant.demo @staticmethod def js_vars(player): return dict( winProb = player.session.config["winProb"], upTick = player.session.config["upTick_Intro"], min_time_on_page = player.session.config["min_time_on_page_instructions"], wait_time = player.session.config["time_after_wrong_comp"], testing = player.session.config["testing"], allPaths = gPaths.getAllPaths(), ) @staticmethod def vars_for_template(player): return dict( testing = player.session.config["testing"], ) @staticmethod def get_timeout_seconds(player): participant = player.participant return participant.expiry - time.time() @staticmethod def before_next_page(player, timeout_happened): if timeout_happened: player.participant.timeoutHappened = True player.session.dropouts.append(player.participant.treatment) player.session.actives[player.participant.treatment] = player.session.actives[player.participant.treatment] - 1 class attentionScreen(Page): @staticmethod def is_displayed(player): return (player.participant.treatment in relTreatments) and not player.participant.timeoutHappened and not player.participant.demo @staticmethod def get_timeout_seconds(player): participant = player.participant return participant.expiry - time.time() @staticmethod def before_next_page(player, timeout_happened): if timeout_happened: player.participant.timeoutHappened = True player.session.dropouts.append(player.participant.treatment) player.session.actives[player.participant.treatment] = player.session.actives[player.participant.treatment] - 1 class decoloringTask(Page): form_model = "player" form_fields = ['decoloring'] @staticmethod def is_displayed(player): return (player.participant.treatment in relTreatments) and not player.participant.timeoutHappened @staticmethod def live_method(player, data): player.participant.decoloring = data @staticmethod def js_vars(player: Player): return dict( winProb = player.session.config["winProb"], upTick = player.session.config["upTick"], testing = player.session.config["testing"], user_chosen_decision = player.participant.bf, endowment = '£%.2f' % player.session.config["endowment"], initialColor = player.participant.plotColor, colorName = player.participant.color, treatment = player.participant.treatment, allPaths = gPaths.getAllPaths(), costly = (player.participant.treatment == 3), costPerBall = '£%.2f' % player.session.config["costPerBall"], ) @staticmethod def vars_for_template(player: Player): return dict( testing = player.session.config["testing"], ) @staticmethod def get_timeout_seconds(player): participant = player.participant return participant.expiry - time.time() @staticmethod def before_next_page(player, timeout_happened): player.participant.demo = False # Show normal if this paged reached player.decoloring = str(player.participant.decoloring) if timeout_happened: player.participant.timeoutHappened = True player.session.dropouts.append(player.participant.treatment) player.session.actives[player.participant.treatment] = player.session.actives[player.participant.treatment] - 1 class thankYou(Page): @staticmethod def is_displayed(player): return (player.participant.treatment in relTreatments) and not player.participant.timeoutHappened @staticmethod def get_timeout_seconds(player): participant = player.participant return participant.expiry - time.time() @staticmethod def before_next_page(player, timeout_happened): if timeout_happened: player.participant.timeoutHappened = True player.session.dropouts.append(player.participant.treatment) player.session.actives[player.participant.treatment] = player.session.actives[player.participant.treatment] - 1 page_sequence = [ pathDependentStop, decoloringExplain, compQ, attentionScreen, decoloringTask, thankYou, ]