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 ''' class Constants(BaseConstants): name_in_url = 'treatment' players_per_group = None num_rounds = 1 ######################################################## Correct = 5 # 無意味 Incorrect = 0 error = 0 time_20 = 20 time = 10 treatment1_left2_template = 'treatment/treatment1_left2.html' treatment1_right2_template = 'treatment/treatment1_right2.html' treatment1_left4_template = 'treatment/treatment1_left4.html' treatment1_right4_template = 'treatment/treatment1_right4.html' treatment2_left2_template = 'treatment/treatment2_left2.html' treatment2_right2_template = 'treatment/treatment2_right2.html' treatment2_left4_template = 'treatment/treatment2_left4.html' treatment2_right4_template = 'treatment/treatment2_right4.html' treatment3_left2_template = 'treatment/treatment3_left2.html' treatment3_right2_template = 'treatment/treatment3_right2.html' treatment3_left4_template = 'treatment/treatment3_left4.html' treatment3_right4_template = 'treatment/treatment3_right4.html' control1_left2_template = 'treatment/control1_left2.html' control1_right2_template = 'treatment/control1_right2.html' control1_left4_template = 'treatment/control1_left4.html' control1_right4_template = 'treatment/control1_right4.html' control2_left2_template = 'treatment/control2_left2.html' control2_right2_template = 'treatment/control2_right2.html' control2_left4_template = 'treatment/control2_left4.html' control2_right4_template = 'treatment/control2_right4.html' control3_left2_template = 'treatment/control3_left2.html' control3_right2_template = 'treatment/control3_right2.html' control3_left4_template = 'treatment/control3_left4.html' control3_right4_template = 'treatment/control3_right4.html' instructions_template = 'treatment/instructions.html' treatment1_left2_choice_template = 'treatment/treatment1_left2_choice.html' treatment1_right2_choice_template = 'treatment/treatment1_right2_choice.html' treatment1_left4_choice_template = 'treatment/treatment1_left4_choice.html' treatment1_right4_choice_template = 'treatment/treatment1_right4_choice.html' treatment2_left2_choice_template = 'treatment/treatment2_left2_choice.html' treatment2_right2_choice_template = 'treatment/treatment2_right2_choice.html' treatment2_left4_choice_template = 'treatment/treatment2_left4_choice.html' treatment2_right4_choice_template = 'treatment/treatment2_right4_choice.html' treatment3_left2_choice_template = 'treatment/treatment3_left2_choice.html' treatment3_right2_choice_template = 'treatment/treatment3_right2_choice.html' treatment3_left4_choice_template = 'treatment/treatment3_left4_choice.html' treatment3_right4_choice_template = 'treatment/treatment3_right4_choice.html' control1_left2_choice_template = 'treatment/control1_left2_choice.html' control1_right2_choice_template = 'treatment/control1_right2_choice.html' control1_left4_choice_template = 'treatment/control1_left4_choice.html' control1_right4_choice_template = 'treatment/control1_right4_choice.html' control2_left2_choice_template = 'treatment/control2_left2_choice.html' control2_right2_choice_template = 'treatment/control2_right2_choice.html' control2_left4_choice_template = 'treatment/control2_left4_choice.html' control2_right4_choice_template = 'treatment/control2_right4_choice.html' control3_left2_choice_template = 'treatment/control3_left2_choice.html' control3_right2_choice_template = 'treatment/control3_right2_choice.html' control3_left4_choice_template = 'treatment/control3_left4_choice.html' control3_right4_choice_template = 'treatment/control3_right4_choice.html' instructions_template = 'treatment/instructions.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"] list_quiz = [1,2,3] list_experiment = [1,2,3,4,5,6] # 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 # Treatmentの並びが決まる class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): type = models.StringField() key_price = models.StringField() point = models.IntegerField() decision = models.StringField( choices=[ ["A_right2","A_right2"], ["A_right4","A_right4"], ["A_left2","A_left2"], ["A_left4","A_left2"], ["B_right2","B_right2"], ["B_right4","B_right4"], ["B_left2","B_left2"], ["B_left4","B_left2"], ["time_error ", "time_error"] ], widget=widgets.RadioSelect, doc="""This is player decision""" ) type1 = models.StringField() key_price1 = models.StringField() type2 = models.StringField() key_price2 = models.StringField() type3 = models.StringField() key_price3 = models.StringField() type4 = models.StringField() key_price4 = models.StringField() type5 = models.StringField() key_price5 = models.StringField() type6 = models.StringField() point1 = models.IntegerField() point2 = models.IntegerField() point3 = models.IntegerField() point4 = models.IntegerField() point5 = models.IntegerField() point6 = models.IntegerField() decision1 = models.StringField() decision2 = models.StringField() decision3 = models.StringField() decision4 = models.StringField() decision5 = models.StringField() decision6 = models.StringField() key_price6 = models.StringField() exp_number = models.IntegerField() ###################Quiz################### quiz_number = models.IntegerField() Q1 = models.StringField(initial=None, choices=[['A','A'], ['B','B']] ) # 計算 #Q2 = models.StringField(initial=None, # choices=['10秒', '13秒','15秒', '20秒'], # label="制限時間で正しいのは、", # widget=widgets.RadioSelect) #Q3 = models.StringField(initial=None, # choices=['0ポイント','5ポイント','10ポイント'], # label="制限時間の10秒が過ぎた時点で店の選択ができなかった場合、あなたが獲得するポイントは、", # widget=widgets.RadioSelect) # 計算 ############Demographics################## age = models.IntegerField(label="あなたの年齢を教えてください.(答えたくない場合、120を選択してください。)", min=0, max=121) gender = models.StringField(initial=None, choices=['男性', '女性', 'その他', '答えない'], label='あなたの性別を教えてください.', widget=widgets.RadioSelect) edu = models.StringField(initial=None, choices=['中学校卒業', '高校卒業', '専門学校(短期大学)卒業', '大学卒業', '大学院修士課程(博士前期課程)修了','大学院博士課程(博士後期課程)修了', '答えない'], label='あなたの最終学歴を教えてください.', widget=widgets.RadioSelect) understand = models.StringField(initial=None, choices=['1. とても苦手', '2.どちらかといえば苦手', '3.普通', '4.どちらかといえば得意', '5. とても得意', '答えない'], label='数字を計算をすることは苦手ですか?', widget=widgets.RadioSelect) #device = models.StringField(initial=None, # choices=['ノートPC','デスクトップ端末'], # #choices=['スマホ', 'ノートPC', 'タブレット端末', 'デスクトップ端末'], # label='あなたは今どの端末を使っていますか?', # widget=widgets.RadioSelect) # PAGES class Introduction_0(Page): @staticmethod def before_next_page(player: Player, timeout_happened): player.exp_number = Constants.list_experiment.copy()[0] player.participant.vars["exp_number"] = player.exp_number player.quiz_number = Constants.list_quiz.copy()[0] player.participant.vars["quiz_number"] = player.quiz_number class Introduction(Page): @staticmethod def before_next_page(player: Player,timeout_happened): treatment_info = player.participant.vars["treatment"][0] player.type = treatment_info['type'] player.participant.vars["type"] = player.type key_info = random.choice(Constants.key.copy()) player.key_price = key_info player.participant.vars["key_price"]=player.key_price player.type1 = player.type player.key_price1 = player.key_price player.exp_number = Constants.list_experiment.copy()[0] player.participant.vars["exp_number"] = player.exp_number player.quiz_number = Constants.list_quiz.copy()[1] player.participant.vars["quiz_number"] = player.quiz_number class Quiz1(Page): timeout_seconds = Constants.time_20 @staticmethod def vars_for_tempalte(player:Player): return dict( x = player.participant.vars["quiz_number"] ) class Quiz1_1(Page): form_model="player" form_fields=["Q1"] @staticmethod def vars_for_tempalte(player:Player): return dict( x = player.participant.vars["quiz_number"] ) @staticmethod def error_message(player:Player, values): if values["Q1"] == 'A': return '回答が違います。もう一度回答してください。' else: pass @staticmethod def before_next_page(player: Player, timeout_happened): player.quiz_number = Constants.list_quiz.copy()[2] player.participant.vars["quiz_number"] = player.quiz_number #class Quiz_time(Page): # form_model="player" # form_fields=["Q2","Q3"] # def vars_for_tempalte(player:Player): # return dict( # x = player.participant.vars["quiz_number"] # )# # @staticmethod # def error_message(player:Player, values): # if values["Q2"] != '15秒': # return '回答が違います。もう一度回答してください。' # else: # pass # if values["Q3"] != '0ポイント': # return '回答が違います。もう一度回答してください。' # else: # pass # @staticmethod # def before_next_page(player: Player, timeout_happened): # player.quiz_number = Constants.list_quiz.copy()[2] # player.participant.vars["quiz_number"] = player.quiz_number class start(Page): def vars_for_tempalte(player:Player): return dict( x = player.participant.vars["quiz_number"] ) class Page1(Page): timeout_seconds = Constants.time_20 @staticmethod def vars_for_template(player: Player): return dict( treatment_type = player.participant.vars["type"] , key_price =player.participant.vars["key_price"], x = player.participant.vars["exp_number"] ) class choice1(Page): timeout_seconds = Constants.time form_model="player" form_fields=["decision"] @staticmethod def vars_for_template(player: Player): player.key_price =player.participant.vars["key_price"] return dict( treatment_type = player.participant.vars["type"] , key_price =player.participant.vars["key_price"], x = player.participant.vars["exp_number"] ) class Wait2(Page): pass @staticmethod def before_next_page(player: Player,timeout_happened): if timeout_happened: player.decision = "time_error" treatment_info = player.participant.vars["treatment"][1] player.type = treatment_info['type'] player.participant.vars["type"] = player.type key_info = random.choice(Constants.key.copy()) player.key_price = key_info player.participant.vars["key_price"]=player.key_price player.type2 = player.type player.key_price2 = player.key_price exp1 = dict(A_right2=Constants.Correct, B_right2=Constants.Incorrect, A_left2=Constants.Incorrect, B_left2=Constants.Correct, A_right4=Constants.Correct, B_right4=Constants.Incorrect, A_left4=Constants.Incorrect, B_left4=Constants.Correct, time_error=Constants.error ) player.decision1 = player.decision player.point = exp1[player.decision] player.point1 = exp1[player.decision] player.exp_number = Constants.list_experiment.copy()[1] player.participant.vars["exp_number"] = player.exp_number #################################################################################### class Page2(Page): timeout_seconds = Constants.time_20 @staticmethod def vars_for_template(player: Player): return dict( treatment_type = player.participant.vars["type"] , key_price =player.participant.vars["key_price"], x = player.participant.vars["exp_number"] ) class choice2(Page): timeout_seconds = Constants.time form_model="player" form_fields=["decision"] @staticmethod def vars_for_template(player: Player): return dict( treatment_type = player.participant.vars["type"] , key_price =player.participant.vars["key_price"], x = player.participant.vars["exp_number"] ) @staticmethod def before_next_page(player: Player,timeout_happened): if timeout_happened: player.decision = "time_error" treatment_info = player.participant.vars["treatment"][2] player.type = treatment_info['type'] player.participant.vars["type"] = player.type key_info = random.choice(Constants.key.copy()) player.key_price = key_info player.participant.vars["key_price"]=player.key_price player.type3 = player.type player.key_price3 = player.key_price exp2 = dict(A_right2=Constants.Correct, B_right2=Constants.Incorrect, A_left2=Constants.Incorrect, B_left2=Constants.Correct, A_right4=Constants.Correct, B_right4=Constants.Incorrect, A_left4=Constants.Incorrect, B_left4=Constants.Correct, time_error=Constants.error ) player.decision2 = player.decision player.point += exp2[player.decision] player.point2 = exp2[player.decision] player.exp_number = Constants.list_experiment.copy()[2] player.participant.vars["exp_number"] = player.exp_number class Wait3(Page): pass class Page3(Page): timeout_seconds = Constants.time_20 @staticmethod def vars_for_template(player: Player): return dict( treatment_type = player.participant.vars["type"] , key_price =player.participant.vars["key_price"], x = player.participant.vars["exp_number"] ) class choice3(Page): timeout_seconds = Constants.time form_model="player" form_fields=["decision"] @staticmethod def vars_for_template(player: Player): return dict( treatment_type = player.participant.vars["type"] , key_price =player.participant.vars["key_price"], x = player.participant.vars["exp_number"] ) @staticmethod def before_next_page(player: Player,timeout_happened): if timeout_happened: player.decision = "time_error" treatment_info = player.participant.vars["treatment"][3] player.type = treatment_info['type'] player.participant.vars["type"] = player.type key_info = random.choice(Constants.key.copy()) player.key_price = key_info player.participant.vars["key_price"]=player.key_price player.type4 = player.type player.key_price4 = player.key_price exp3 = dict(A_right2=Constants.Correct, B_right2=Constants.Incorrect, A_left2=Constants.Incorrect, B_left2=Constants.Correct, A_right4=Constants.Correct, B_right4=Constants.Incorrect, A_left4=Constants.Incorrect, B_left4=Constants.Correct, time_error=Constants.error ) player.decision3 = player.decision player.point3 = exp3[player.decision] player.point += exp3[player.decision] player.participant.vars["point"] = player.point player.exp_number = Constants.list_experiment.copy()[3] player.participant.vars["exp_number"] = player.exp_number class Wait4(Page): pass class Page4(Page): timeout_seconds = Constants.time_20 @staticmethod def vars_for_template(player: Player): return dict( treatment_type = player.participant.vars["type"] , key_price =player.participant.vars["key_price"], x = player.participant.vars["exp_number"] ) class choice4(Page): timeout_seconds = Constants.time form_model="player" form_fields=["decision"] @staticmethod def vars_for_template(player: Player): return dict( treatment_type = player.participant.vars["type"] , key_price =player.participant.vars["key_price"], x = player.participant.vars["exp_number"] ) ################################################################################## @staticmethod def before_next_page(player: Player,timeout_happened): if timeout_happened: player.decision = "time_error" treatment_info = player.participant.vars["treatment"][4] player.type = treatment_info['type'] player.participant.vars["type"] = player.type key_info = random.choice(Constants.key.copy()) player.key_price = key_info player.participant.vars["key_price"]=player.key_price player.type5 = player.type player.key_price5 = player.key_price exp4 = dict(A_right2=Constants.Correct, B_right2=Constants.Incorrect, A_left2=Constants.Incorrect, B_left2=Constants.Correct, A_right4=Constants.Correct, B_right4=Constants.Incorrect, A_left4=Constants.Incorrect, B_left4=Constants.Correct, time_error=Constants.error ) player.decision4 = player.decision player.point4 = exp4[player.decision] player.point += exp4[player.decision] player.participant.vars["point"] = player.point player.exp_number = Constants.list_experiment.copy()[4] player.participant.vars["exp_number"] = player.exp_number class Wait5(Page): pass class Page5(Page): timeout_seconds = Constants.time_20 @staticmethod def vars_for_template(player: Player): return dict( treatment_type = player.participant.vars["type"] , key_price =player.participant.vars["key_price"], x = player.participant.vars["exp_number"] ) class choice5(Page): timeout_seconds = Constants.time form_model="player" form_fields=["decision"] @staticmethod def vars_for_template(player: Player): return dict( treatment_type = player.participant.vars["type"] , key_price =player.participant.vars["key_price"], x= player.participant.vars["exp_number"] ) ################################################################################# @staticmethod def before_next_page(player: Player,timeout_happened): if timeout_happened: player.decision = "time_error" treatment_info = player.participant.vars["treatment"][-1] player.type = treatment_info['type'] player.participant.vars["type"] = player.type key_info = random.choice(Constants.key.copy()) player.key_price = key_info player.participant.vars["key_price"]=player.key_price player.type6 = player.type player.key_price6 = player.key_price exp5 = dict(A_right2=Constants.Correct, B_right2=Constants.Incorrect, A_left2=Constants.Incorrect, B_left2=Constants.Correct, A_right4=Constants.Correct, B_right4=Constants.Incorrect, A_left4=Constants.Incorrect, B_left4=Constants.Correct, time_error=Constants.error ) player.decision5 = player.decision player.point5 = exp5[player.decision] player.point += exp5[player.decision] player.participant.vars["point"] = player.point player.exp_number = Constants.list_experiment.copy()[5] player.participant.vars["exp_number"] = player.exp_number class Wait6(Page): pass class Page6(Page): timeout_seconds = Constants.time_20 @staticmethod def vars_for_template(player: Player): return dict( treatment_type = player.participant.vars["type"] , key_price =player.participant.vars["key_price"], x = player.participant.vars["exp_number"] ) class choice6(Page): timeout_seconds = Constants.time form_model="player" form_fields=["decision"] @staticmethod def vars_for_template(player: Player): return dict( treatment_type = player.participant.vars["type"] , key_price =player.participant.vars["key_price"], x = player.participant.vars["exp_number"] ) ################################################################################# @staticmethod def before_next_page(player: Player,timeout_happened): if timeout_happened: player.decision = "time_error" exp6 = dict(A_right2=Constants.Correct, B_right2=Constants.Incorrect, A_left2=Constants.Incorrect, B_left2=Constants.Correct, A_right4=Constants.Correct, B_right4=Constants.Incorrect, A_left4=Constants.Incorrect, B_left4=Constants.Correct, time_error=Constants.error ) player.decision6 = player.decision player.point6 = exp6[player.decision] player.point += exp6[player.decision] player.participant.vars["point"] = player.point class Results(Page): @staticmethod def vars_for_template(player: Player): return dict( point = player.participant.vars["point"] ) class Demographics(Page): form_model = 'player' form_fields = ['age', 'gender', 'edu', 'understand'] class finish(Page): pass page_sequence = [Introduction_0,Introduction,Quiz1,Quiz1_1,start, Page1, choice1, Wait2, Page2, choice2, Wait3, Page3, choice3, Wait4, Page4, choice4, Wait5, Page5, choice5, Wait6, Page6, choice6, Results,Demographics,finish]