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 = 'micro' players_per_group = None num_rounds = 1 time = 200 treatment1_left2_template = 'micro/treatment1_left2.html' treatment1_right2_template = 'micro/treatment1_right2.html' #24 pattern treatment = [ dict(type="1") ] key = ["right2","left2"] # 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 treatment1_left2(Page): pass class treatment1_left4(Page): pass class timer(Page): pass 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) page_sequence = [treatment1_left2,timer,Introduction,Page1]