from otree.api import * c = cu doc = 'POP広告の属性が消費者の衝動買いに寄与する効用値' class C(BaseConstants): NAME_IN_URL = 'POP_Conjoint' PLAYERS_PER_GROUP = None NUM_ROUNDS = 10 S = (21111, 21101, 21011, 21001, 20111, 20101, 20011, 20001, 11111, 11101, 11011, 11001, 10111, 10101, 10011, 10001, 21110, 21100, 21010, 21000, 20110, 20100, 20010, 20000, 11110, 11100, 11010, 11000, 10110, 10100, 10010, 10000) class Subsession(BaseSubsession): pass def creating_session(subsession: Subsession): session = subsession.session for p in subsession.get_players(): import random tmp = random.sample(C.S,2) p.x = tmp[0] p.y = tmp[1] class Group(BaseGroup): pass class Player(BasePlayer): x = models.IntegerField() y = models.IntegerField() L1 = models.IntegerField() L2 = models.IntegerField() L3 = models.IntegerField() L4 = models.IntegerField() L5 = models.IntegerField() R1 = models.IntegerField() R2 = models.IntegerField() R3 = models.IntegerField() R4 = models.IntegerField() R5 = models.IntegerField() Choice = models.IntegerField(choices=[[11, '左'], [12, '右']]) Player_number = models.StringField() def Zokusei_suizyun_L(player: Player): import math player.L1 = math.floor(player.x/10000) player.L2 = math.floor((player.x-10000*player.L1)/1000) player.L3 = math.floor((player.x-10000*player.L1-1000*player.L2)/100) player.L4 = math.floor((player.x-10000*player.L1-1000*player.L2-100*player.L3)/10) player.L5 = player.x-10000*player.L1-1000*player.L2-100*player.L3-10*player.L4 def Zokusei_suizyun_R(player: Player): import math player.R1 = math.floor(player.y/10000) player.R2 = math.floor((player.y-10000*player.R1)/1000) player.R3 = math.floor((player.y-10000*player.R1-1000*player.R2)/100) player.R4 = math.floor((player.y-10000*player.R1-1000*player.R2-100*player.R3)/10) player.R5 = player.y-10000*player.R1-1000*player.R2-100*player.R3-10*player.R4 class Player_number(Page): form_model = 'player' form_fields = ['Player_number'] @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Introduction(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number == 1 class Choice(Page): form_model = 'player' form_fields = ['Choice'] @staticmethod def before_next_page(player: Player, timeout_happened): Zokusei_suizyun_L(player) Zokusei_suizyun_R(player) @staticmethod def vars_for_template(player): return dict( image_path_left='POP/{}.gif'.format(player.x), image_path_right='POP/{}.gif'.format(player.y) ) class Final(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): return player.round_number ==10 page_sequence = [Introduction, Choice, Final]