from otree.api import * c = cu doc = '' class C(BaseConstants): NAME_IN_URL = 'GARP_SLIDER' PLAYERS_PER_GROUP = None NUM_ROUNDS = 32 GARP_SLOPES = (0.5, 0.333, 0.5, 0.25, 4, 1, 2, 0.5, 1, 0.5, 3, 1, 2, 0.333, 0.75, 1.33, 2, 0.5, 5, 0.2, 2.5, 0.4, 0.6, 1.66, 0.75, 1.33, 0.33, 3, 0.66, 1.5) GARP_ENDOWMENTS = (150, 120, 120, 160, 40, 80, 60, 75, 60, 60, 40, 100, 75, 40, 80, 60, 20, 40, 20, 100, 40, 100, 100, 60, 40, 30, 90, 30, 120, 80) class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): keep = models.IntegerField(min=0) def setUp(player: Player): participant = player.participant participant.slider_options = [0] * len(C.GARP_SLOPES) import random round_numbers = list(range(0, len(C.GARP_SLOPES))) random.shuffle(round_numbers) participant.garp_question_order = round_numbers def custom_export(players): yield ['participant_code', 'id_in_group'] for p in players: pp = p.participant yield [pp.code, p.id_in_group] class Introduction(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return (player.round_number == 1) @staticmethod def before_next_page(player: Player, timeout_happened): setUp(player) class GARP_Example(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return (player.round_number == 1) class Sliders(Page): form_model = 'player' form_fields = ['keep'] @staticmethod def is_displayed(player: Player): return player.round_number <= len(C.GARP_SLOPES) @staticmethod def vars_for_template(player: Player): participant = player.participant return dict(ratio = round(1/C.GARP_SLOPES[participant.garp_question_order[player.round_number - 1]], 2)) @staticmethod def js_vars(player: Player): participant = player.participant return dict(endowment=C.GARP_ENDOWMENTS[participant.garp_question_order[player.round_number - 1]], ratio= 1 / C.GARP_SLOPES[participant.garp_question_order[player.round_number - 1]]) @staticmethod def before_next_page(player: Player, timeout_happened): participant = player.participant participant.slider_options[participant.garp_question_order[player.round_number - 1]] = player.keep page_sequence = [Introduction, GARP_Example, Sliders]