from otree.api import * doc = """ This application provides a webpage instructing participants how to get paid. Examples are given for the lab and Amazon Mechanical Turk (AMT). """ class C(BaseConstants): NAME_IN_URL = 'intro' PLAYERS_PER_GROUP = 3 NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): treatment = models.StringField() class Player(BasePlayer): age = models.IntegerField(label="Berapa usia Anda?", min=18, max=99, blank=True) education = models.IntegerField( label="Apa jenjang pendidikan tertinggi Anda?", widget=widgets.RadioSelectHorizontal, choices=[ [1, "SD"], [2, "SMP"], [3, "SMA"], [4, "S1/S2/S3"]]) gender = models.IntegerField(label="Apa jenis kelamin Anda?", widget=widgets.RadioSelectHorizontal, choices=[[1, "Laki-laki"], [2, "Perempuan"]]) province = models.IntegerField(label="Apa Provinsi Anda?", # widget = widgets.RadioSelectHorizontal, choices=[[1, "Aceh"], [2, "Sumatera Utara"], [3, "Sumatera Barat"], [4, "Riau"], [5, "Jambi"], [6, "Sumatera Selatan"], [7, "Bengkulu"], [8, "Lampung"], [9, "Bangka Belitung"], [10, "Kepulauan Riau"], [11, "DKI Jakarta"], [12, "Jawa Barat"], [13, "Jawa Tengah"], [14, "DI Yogyakarta"], [15, "Jawa Timur"], [16, "Banten"], [17, "Bali"], [18, "NTB"], [19, "NTT"], [20, "Kalimantan Barat"], [21, "Kalimantan Tengah"], [22, "Kalimantan Selatan"], [23, "Kalimantan Timur"], [24, "Kalimantan Utara"], [25, "Sulawesi Utara"], [26, "Sulawesi Tengah"], [27, "Sulawesi Selatan"], [28, "Sulawesi Tenggara"], [29, "Gorontalo"], [30, "Sulawesi Barat"], [31, "Maluku"], [32, "Maluku Utara"], [33, "Papua Barat"], [34, "Papua"]]) religion = models.IntegerField(label="Apa agama Anda?", widget=widgets.RadioSelectHorizontal, choices=[[1, "Islam"], [2, "Kristen (Protestan)"], [3, "Katholik"], [4, "Hindu"], [5, "Buddha"], [6, "Lain-lain"]]) ethnicity = models.IntegerField(label="Apa suku/etnis Anda?", widget=widgets.RadioSelectHorizontal, choices=[[1, "Jawa"], [2, "Sunda"], [3, "Melayu"], [4, "Madura"], [5, "Bugis"], [6, "Betawi"], [7, "Batak"], [8, "Minang"], [9, "Bali"], [10, "Lain-lain"]]) is_age = models.BooleanField(label="Apakah Anda berusia 18 tahun atau lebih?", choices=[ [True, "Iya"], [False, "Tidak"]]) is_consent = models.BooleanField(label="Apakah Anda setuju untuk berpartisipasi dalam penelitian ini?", choices=[ [True, "Iya, bersedia"], [False, "Tidak, saya tidak bersedia"]]) # FUNCTIONS def creating_session(subsession: Subsession): session = subsession.session # Old code # import itertools # treatments = itertools.cycle(["random", "merit", "patronage"]) # Logic of selecting a random remaining treatment import random treatments = ["random", "merit", "patronage"] # empty treatment list is not accounted for in logic below remaining_treatments = list(range(len(treatments))) # integer array keeping track of remaining treatments that are unassigned for group in subsession.get_groups(): if not remaining_treatments: # Case when remaining_treatments list is empty -> meaning all treatments have been already been assigned once before remaining_treatments = list(range(len(treatments))) # resetting the list random_treatment_index = random.choice(remaining_treatments) group.treatment = treatments[random_treatment_index] print('set condition to', group.treatment) remaining_treatments.remove(random_treatment_index) session.past_groups = [] for group in subsession.get_groups(): treatment = group.treatment session.past_groups.append(treatment) # PAGES class ConsentPage(Page): form_model = "player" form_fields = ["is_age", "is_consent"] class GameEnd(Page): ### Display only to participants who pass all 2 mandatory conditions @staticmethod def is_displayed(player): return player.is_age == False or player.is_consent == False class SurveyPre(Page): form_model = "player" form_fields = ["age","gender", "education", "province", "religion", "ethnicity"] @staticmethod def before_next_page(player: Player, timeout_happened): participant = player.participant participant.age = player.age participant.gender = player.gender participant.education = player.education participant.province = player.province participant.religion = player.religion participant.ethnicity = player.ethnicity page_sequence = [ConsentPage,GameEnd, SurveyPre]