from otree.api import * doc = """ Slider example """ class Constants(BaseConstants): name_in_url = 'slider' players_per_group = None topics = ['biology', 'comp_sci', 'education', 'engineering', 'finance', 'health', 'hist_geo', 'literature', 'nature_forestry_conservation', 'psych_cogn', 'verbal', 'vocal_technical'] num_topics = len(topics) num_rounds = len(topics) +1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): biology = models.FloatField() comp_sci = models.FloatField() education = models.FloatField() engineering = models.FloatField() finance = models.FloatField() health = models.FloatField() hist_geo = models.FloatField() literature = models.FloatField() nature_forestry_conservation = models.FloatField() psych_cogn = models.FloatField() verbal = models.FloatField() vocal_technical = models.FloatField() # Function def creating_session(subsession): import random if subsession.round_number == 1: for p in subsession.get_players(): round_numbers = list(range(1, Constants.num_rounds)) random.shuffle(round_numbers) # print(round_numbers) p.participant.vars['topic_rounds'] = dict(zip(Constants.topics, round_numbers)) print(p.participant.vars['topic_rounds']) print(p.participant.vars['topic_rounds']['vocal_technical']) # def creating_session(subsession: Subsession): # #https://groups.google.com/g/otree/c/xp1K2DrvePk # import random # if subsession.round_number == 1: # for p in subsession.get_players(): # p.total_rounds = Constants.num_rounds # round_numbers = list(range(1, Constants.num_topics+1)) # p.topic_rounds = dict(zip(Constants.topics, round_numbers)) # print(p.topic_rounds) # def creating_session(subsession: Subsession): # import random # if subsession.round_number == 1: # for p in subsession.get_players(): # p.total_rounds = Constants.num_rounds # round_numbers = list(range(1, Constants.num_rounds + 1)) # p.topic_rounds = dict(zip(Constants.topics, round_numbers)) # print(p.topic_rounds) # # for p in subsession.get_players(): # question_data = current_question(p) # print('question_data', question_data) # p.question_id = question_data['id'] # p.question = question_data['question'] # p.solution = question_data['solution'] # p.topic = question_data['topic'] # p.graphics_name = question_data['graphics_name'] # p.round_number_total = Constants.num_rounds # # if subsession.round_number == 1: # subsession.session.vars['questions'] = Constants.questions.copy() # ## to randomize the order of the questions, you could instead do: # for self in subsession.get_players(): # import random # randomized_questions = random.sample(Constants.questions, len(Constants.questions)) # print("randomized questions", randomized_questions) # self.participant.vars['questions'] = randomized_questions # PAGES class biology(Page): staticmethod def is_displayed(player): return player.round_number == player.participant.vars['topic_rounds']['biology'] form_model = 'player' form_fields = ['biology'] class comp_sci(Page): staticmethod def is_displayed(player): return player.round_number == player.participant.vars['topic_rounds']['comp_sci'] form_model = 'player' form_fields = ['comp_sci'] class education(Page): staticmethod def is_displayed(player): return player.round_number == player.participant.vars['topic_rounds']['education'] form_model = 'player' form_fields = ['education'] class engineering(Page): staticmethod def is_displayed(player): return player.round_number == player.participant.vars['topic_rounds']['engineering'] form_model = 'player' form_fields = ['engineering'] class finance(Page): staticmethod def is_displayed(player): return player.round_number == player.participant.vars['topic_rounds']['finance'] form_model = 'player' form_fields = ['finance'] class health(Page): staticmethod def is_displayed(player): return player.round_number == player.participant.vars['topic_rounds']['health'] form_model = 'player' form_fields = ['health'] class hist_geo(Page): staticmethod def is_displayed(player): return player.round_number == player.participant.vars['topic_rounds']['hist_geo'] form_model = 'player' form_fields = ['hist_geo'] class literature(Page): staticmethod def is_displayed(player): return player.round_number == player.participant.vars['topic_rounds']['literature'] form_model = 'player' form_fields = ['literature'] class nature_forestry_conservation(Page): staticmethod def is_displayed(player): return player.round_number == player.participant.vars['topic_rounds']['nature_forestry_conservation'] form_model = 'player' form_fields = ['nature_forestry_conservation'] class psych_cogn(Page): staticmethod def is_displayed(player): return player.round_number == player.participant.vars['topic_rounds']['psych_cogn'] form_model = 'player' form_fields = ['psych_cogn'] class verbal(Page): staticmethod def is_displayed(player): return player.round_number == player.participant.vars['topic_rounds']['verbal'] form_model = 'player' form_fields = ['verbal'] class vocal_technical(Page): staticmethod def is_displayed(player): return player.round_number == player.participant.vars['topic_rounds']['vocal_technical'] form_model = 'player' form_fields = ['vocal_technical'] class end_of_survey(Page): @staticmethod def is_displayed(player: Player): return player.round_number == Constants.num_rounds page_sequence = [biology, comp_sci, education, engineering, finance, health, hist_geo, literature, nature_forestry_conservation, psych_cogn, verbal, vocal_technical, end_of_survey]