from otree.api import * doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'our_experiment_2' PLAYERS_PER_GROUP = 2 NUM_ROUNDS = 1 #ENDOWMENT = 100 HOT_TREATMENT = 0 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): subject_id = models.StringField(label="你的ID:") test1_ans = models.IntegerField(label="你的回答:") test2_ans1 = models.IntegerField(label="你的回答:") test2_ans2 = models.IntegerField(label="你的回答:") count_test1_ans = models.IntegerField(initial=0) count_test2_ans1 = models.IntegerField(initial=0) count_test2_ans2 = models.IntegerField(initial=0) test1_ans_choice_record = models.StringField() test2_ans1_choice_record = models.StringField() test2_ans2_choice_record = models.StringField() # PAGES class subject_id(Page): form_model = 'player' form_fields = ['subject_id'] @staticmethod def vars_for_template(player): session = player.session experiment_time = session.config['experiment_time'] return dict( experiment_time = experiment_time, ) def waiting_too_long(player): participant = player.participant import time # assumes you set wait_page_arrival in PARTICIPANT_FIELDS. return time.time() - participant.wait_page_arrival > 60 def group_by_arrival_time_method(subsession, waiting_players): all_players = [p for p in waiting_players] if len(all_players) >= 2: # print('about to create a group') return [all_players[0], all_players[1]] for player in waiting_players: if waiting_too_long(player): # make a single-player group. return [player] class wait_page_group(WaitPage): group_by_arrival_time = True #def before_next_page(player, timeout_happened): #player.participant.id_in_group = player.id_in_group title_text = "敬請稍待" body_text = "系統正在為你分組" class role_result(Page): @staticmethod def vars_for_template(player): number_of_player = len(player.get_others_in_group()) + 1 return dict(number_of_player = number_of_player) @staticmethod def app_after_this_page(player, upcoming_apps): player_list = [p for p in player.get_others_in_group()] if len(player_list) == 0: return 'survey' class MyWaitPage(WaitPage): wait_for_all_groups = True title_text = "敬請稍待" body_text = "正在等待所有玩家進入本場實驗,你至多需要等待五分鐘。" class Payoff(Page): form_model = 'player' form_fields = ['test1_ans', 'count_test1_ans', 'test1_ans_choice_record'] #def is_displayed(player): #return player.participant.filter == True class Payoff_ans(Page): pass #def is_displayed(player): #return player.participant.filter == True #pass #@staticmethod #def error_message(player: Player, values): # if player.test1_ans != 10: # return "Game not finished yet" class Instruction(Page): form_model = 'player' form_fields = ['test2_ans1', 'count_test2_ans1', 'test2_ans1_choice_record'] #def is_displayed(player): #return player.participant.filter == True class Instruction_ans(Page): #def is_displayed(player): #return player.participant.filter == True pass class Instruction2(Page): form_model = 'player' form_fields = ['test2_ans2', 'count_test2_ans2', 'test2_ans2_choice_record'] #def is_displayed(player): #return player.participant.filter == True class Instruction_ans2(Page): pass #def is_displayed(player): #return player.participant.filter == True #@staticmethod #def before_next_page(player, timeout_happened): # player.participant.id_in_group = player.id_in_group class End(Page): pass page_sequence = [ #LanguageTest, subject_id, #wait_page_group, #role_result, MyWaitPage, Payoff, # Payoff_ans, Instruction, # Instruction_ans, Instruction2, # Instruction_ans2, #End ]