import random import numpy as np from otree.api import ( Page, WaitPage, models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) from . import models def ccp(menu): lenchoices = len(menu) choices = [None]*lenchoices for a in range(0,lenchoices): choices[a] = str(str(menu[a][0]) +\ " portion(s) of chips and "+str(menu[a][1])\ + " portion(s) of peanuts") return models.StringField( choices = choices, label = '', widget = widgets.RadioSelect() ) doc = '' class Constants(BaseConstants): name_in_url = 'survey' players_per_group = None A_1 = [[7, 1],[4, 2],[1, 3]] A_2 = [[10, 1],[7, 2], [4, 3], [1, 4]] A_3 = [[7, 1],[5, 2],[3, 3], [1, 4]] A_4 = [[9, 1],[7, 2],[5, 3], [3, 4], [1, 5]] A_5 = [[5, 1], [4, 2], [3, 3], [2, 4], [1, 5]] A_6 = [[6, 1], [5, 2], [4, 3], [3, 4], [2, 5], [1, 6]] A_7 = [[7, 1], [6, 2], [5,3], [4,4], [3, 5], [2, 6], [1, 7]] A_8 = [[4, 1], [3, 3], [2 ,5], [1, 7]] A_9 = [[3, 1], [2, 4], [1, 7]] A_10 = [[5, 1], [4, 3], [3, 5], [2, 7], [1, 9]] A_11 = [[4, 1], [3, 4], [2, 7], [1,10]] A = [A_1, A_2, A_3, A_4, A_5, A_6, A_7, A_8, A_9, A_10, A_11] tasks = np.arange(0,len(A)) num_rounds = len(tasks) class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): age = models.IntegerField(label='What is your age', max=125, min=13) gender = models.StringField(choices=[['Male', 'Male'], ['Female', 'Female'], ['Prefer not to say', 'Prefer not to say']], label='What is your gender', widget=widgets.RadioSelect) name = models.StringField(label='What is your ficticious name?') example_question = models.StringField(choices=[['1 orange and 4 apples', '1 orange and 4 apples'], ['2 oranges and 3 apples', '2 oranges and 3 apples'], ['4 oranges and 1 apple', '4 oranges and 1 apple']], label='', widget=widgets.RadioSelect) A = Constants.A cc0 = ccp(A[0]) cc1 = ccp(A[1]) cc2 = ccp(A[2]) cc3 = ccp(A[3]) cc4 = ccp(A[4]) cc5 = ccp(A[5]) cc6 = ccp(A[6]) cc7 = ccp(A[7]) cc8 = ccp(A[8]) cc9 = ccp(A[9]) cc10 = ccp(A[10]) #cc = {} #for a in range(0,len(A)): # prob = ccp(A[a]) # cc['{0}'.format(a)] = prob # #globals()["cc{0}".format(a)] = prob #del a # FUNCTION def creating_session(subsession: Subsession): if subsession.round_number == 1: for p in subsession.get_players(): round_numbers = list(range(1, Constants.num_rounds + 1)) random.shuffle(round_numbers) p.participant.vars['task_rounds'] = dict(zip(Constants.tasks, round_numbers)) # PAGES # class Demographics(Page): # form_model = 'player' # form_fields = ['name', 'age', 'gender'] # class Instructions(Page): # form_model = 'player' # form_fields = ['example_question'] class CC0(Page): form_model = 'player' form_fields = ['cc0'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.vars['task_rounds'][0] class CC1(Page): form_model = 'player' form_fields = ['cc1'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.vars['task_rounds'][1] class CC2(Page): form_model = 'player' form_fields = ['cc2'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.vars['task_rounds'][2] class CC3(Page): form_model = 'player' form_fields = ['cc3'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.vars['task_rounds'][3] class CC4(Page): form_model = 'player' form_fields = ['cc4'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.vars['task_rounds'][4] class CC5(Page): form_model = 'player' form_fields = ['cc5'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.vars['task_rounds'][5] class CC6(Page): form_model = 'player' form_fields = ['cc6'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.vars['task_rounds'][6] class CC7(Page): form_model = 'player' form_fields = ['cc7'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.vars['task_rounds'][7] class CC8(Page): form_model = 'player' form_fields = ['cc8'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.vars['task_rounds'][8] class CC9(Page): form_model = 'player' form_fields = ['cc9'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.vars['task_rounds'][9] class CC10(Page): form_model = 'player' form_fields = ['cc10'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.vars['task_rounds'][10] page_sequence = [CC0, CC1, CC2, CC3, CC4, CC5, CC6, CC7, CC8, \ CC9, CC10]