from otree.api import * import random c = Currency doc = """ For Mutliple products with relative bias """ ''' - treatment = 1,2,3,control1,control2,control3 - 配置と順番 = right2,right4,left2,left4 ''' # step1 ## treatmentと順番と配置をランダムに決定 class Constants(BaseConstants): name_in_url = 'micromodel_random' players_per_group = None num_rounds = 1 time = 15 treatment1_left2_template = 'micromodel_random/treatment1_left2.html' treatment1_right2_template = 'micromodel_random/treatment1_right2.html' treatment1_left4_template = 'micromodel_random/treatment1_left4.html' treatment1_right4_template = 'micromodel_random/treatment1_right4.html' treatment2_left2_template = 'micromodel_random/treatment2_left2.html' treatment2_right2_template = 'micromodel_random/treatment2_right2.html' treatment2_left4_template = 'micromodel_random/treatment2_left4.html' treatment2_right4_template = 'micromodel_random/treatment2_right4.html' treatment3_left2_template = 'micromodel_random/treatment3_left2.html' treatment3_right2_template = 'micromodel_random/treatment3_right2.html' treatment3_left4_template = 'micromodel_random/treatment3_left4.html' treatment3_right4_template = 'micromodel_random/treatment3_right4.html' #24 pattern treatment = [ dict(type="1"), dict(type="2"), dict(type="3"), dict(type="c1"), dict(type="c2"), dict(type="c3") ] key = ["right2","right4","left2","left4"] # Function def creating_session(subsession): for p in subsession.get_players(): treatment_variable = Constants.treatment.copy() random.shuffle(treatment_variable) p.participant.vars["treatment"]=treatment_variable print(p.participant.vars["treatment"]) # Treatmentの並びが決まる class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): type = models.StringField() key_price = models.StringField() # PAGES class Introduction(Page): @staticmethod def before_next_page(player: Player,timeout_happened): treatment_info = player.participant.vars["treatment"][0] print("treatment",treatment_info) player.type = treatment_info['type'] player.participant.vars["type"] = player.type print(player.type) key_info = random.choice(Constants.key.copy()) print("key",key_info) player.key_price = key_info player.participant.vars["key_price"]=player.key_price print(player.key_price) class Page1(Page): timeout_seconds = Constants.time @staticmethod def vars_for_template(player: Player): return dict( treatment_type = player.participant.vars["type"] , key_price =player.participant.vars["key_price"], ) @staticmethod def before_next_page(player: Player,timeout_happened): treatment_info = player.participant.vars["treatment"][1] print("treatment",treatment_info) player.type = treatment_info['type'] player.participant.vars["type"] = player.type print(player.type) key_info = random.choice(Constants.key.copy()) print("key",key_info) player.key_price = key_info player.participant.vars["key_price"]=player.key_price print(player.key_price) class Page2(Page): @staticmethod def vars_for_template(player: Player): return dict( treatment_type = player.participant.vars["type"] , key_price =player.participant.vars["key_price"], ) @staticmethod def before_next_page(player: Player,timeout_happened): treatment_info = player.participant.vars["treatment"][2] print("treatment",treatment_info) player.type = treatment_info['type'] player.participant.vars["type"] = player.type print(player.type) key_info = random.choice(Constants.key.copy()) print("key",key_info) player.key_price = key_info player.participant.vars["key_price"]=player.key_price print(player.key_price) class Page3(Page): @staticmethod def vars_for_template(player: Player): return dict( treatment_type = player.participant.vars["type"] , key_price =player.participant.vars["key_price"], ) @staticmethod def before_next_page(player: Player,timeout_happened): treatment_info = player.participant.vars["treatment"][3] print("treatment",treatment_info) player.type = treatment_info['type'] player.participant.vars["type"] = player.type print(player.type) key_info = random.choice(Constants.key.copy()) print("key",key_info) player.key_price = key_info player.participant.vars["key_price"]=player.key_price print(player.key_price) class Page4(Page): @staticmethod def vars_for_template(player: Player): return dict( treatment_type = player.participant.vars["type"] , key_price =player.participant.vars["key_price"], ) @staticmethod def before_next_page(player: Player,timeout_happened): treatment_info = player.participant.vars["treatment"][4] print("treatment",treatment_info) player.type = treatment_info['type'] player.participant.vars["type"] = player.type print(player.type) key_info = random.choice(Constants.key.copy()) print("key",key_info) player.key_price = key_info player.participant.vars["key_price"]=player.key_price print(player.key_price) class Page5(Page): @staticmethod def vars_for_template(player: Player): return dict( treatment_type = player.participant.vars["type"] , key_price =player.participant.vars["key_price"], ) @staticmethod def before_next_page(player: Player,timeout_happened): treatment_info = player.participant.vars["treatment"][5] print("treatment",treatment_info) player.type = treatment_info['type'] player.participant.vars["type"] = player.type print(player.type) key_info = random.choice(Constants.key.copy()) print("key",key_info) player.key_price = key_info player.participant.vars["key_price"]=player.key_price print(player.key_price) class Page6(Page): @staticmethod def vars_for_template(player: Player): return dict( treatment_type = player.participant.vars["type"] , key_price =player.participant.vars["key_price"], ) page_sequence = [Introduction,Page1,Page2,Page3,Page4,Page5,Page6]