from otree.api import * doc = """ Your app description """ # Info needed # - text / template explaining the game # - performence of one of the groups which is revealed # - performance of the other group may be revealed at the end # - the choice may be a slider? where we put the value of the other group? class Constants(BaseConstants): name_in_url = 'senses_beliefs_ability' players_per_group = None instructions_template = 'senses_beliefs_ability/Instructions.html' choice_set = { # Active game "memory": { 'given': 57, 'given2': 0, 'min_val': 0, 'max_val': 100 }, # # Passive games # "m100s": { # 'given': 9.9, # 'given2': 0, # 'min_val': 9, # 'max_val': 20 # }, # "f100s": { # 'given': 10.89, # 'given2': 0, # 'min_val': 9, # 'max_val': 20 # }, # "m400s": { # 'given': 44, # 'given2': 0, # 'min_val': 40, # 'max_val': 100 # }, "f400s": { 'given': 50, 'given2': 0, 'min_val': 40, 'max_val': 200 }, # "m100n": { # 'given': 48, # 'given2': 0, # 'min_val': 40, # 'max_val': 100 # }, # "f100n": { # 'given': 53, # 'given2': 0, # 'min_val': 40, # 'max_val': 100 # }, "math": { 'given': 97, 'given2': 91, 'min_val': 0, 'max_val': 100 }, "happy": { 'given': 76, 'given2': 0, 'min_val': 0, 'max_val': 100 }, } num_rounds = len(choice_set) class Subsession(BaseSubsession): pass def creating_session(subsession): if subsession.round_number == 1: import itertools, random, copy choice_set = Constants.choice_set.copy() # iter_set = itertools.cycle(choice_set) for p in subsession.get_players(): p.participant.choice_set = choice_set.copy() p.participant.choice_set = list(p.participant.choice_set.items()) random.shuffle(p.participant.choice_set) p.participant.choice_set = dict(p.participant.choice_set) for p in subsession.get_players(): current_set = list(p.participant.choice_set)[subsession.round_number - 1] p.game_version = current_set class Group(BaseGroup): pass class Player(BasePlayer): ability_guess = models.FloatField() ability_guess_mult = models.FloatField() game_version = models.StringField() # PAGES class Intro(Page): pass @staticmethod def is_displayed(player: Player): return player.round_number == 1 class MyPage(Page): form_model = 'player' form_fields = ['ability_guess', 'ability_guess_mult'] @staticmethod def get_form_fields(player): if player.game_version == "math": return ['ability_guess', 'ability_guess_mult'] else: return ['ability_guess'] @staticmethod def vars_for_template(player: Player): return dict( game = player.game_version, round = player.round_number, given = Constants.choice_set[player.game_version]['given'], given2 = Constants.choice_set[player.game_version]['given2'], min_val = Constants.choice_set[player.game_version]['min_val'], max_val = Constants.choice_set[player.game_version]['max_val'] ) class ResultsWaitPage(WaitPage): pass @staticmethod def is_displayed(player: Player): return player.round_number == 1 page_sequence = [Intro, MyPage]