from otree.api import * from datetime import datetime from numpy import random doc = """ Consent forms, if the participants refuse to take part in, then exit. """ class C(BaseConstants): NAME_IN_URL = 'consent_forms' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): consent_no = models.IntegerField(initial = 0) pass class Group(BaseGroup): pass class Player(BasePlayer): is_agree = models.BooleanField(initial=False) name = models.StringField(label="姓名") gender = models.IntegerField(label="性别", choices=[ [1, '男'], [2, '女'] ] ) age = models.IntegerField(label="年龄",min=18, max=50) group_no = models.IntegerField(label = "组号",min=1, max=1000) who_receive = models.IntegerField(label="", choices=[ [1, '玩家4'], [2, '玩家2'] ] ) question_giving1 = models.IntegerField(label="在这个回合中,玩家 1 得到多少点数?", choices = [0,10,15,20,25]) question_giving2 = models.IntegerField(label="在这个回合中,玩家 2 得到多少点数?", choices = [0,10,15,20,25]) question_giving3 = models.IntegerField(label="在这个回合中,玩家 3 得到多少点数?", choices = [0,10,15,20,25]) question_giving4 = models.IntegerField(label="在这个回合中,玩家 4 得到多少点数?", choices = [0,10,15,20,25]) def question_giving1_error_message(player, value): print('You chose ', value) if value != 15: return '此问题答案错误,请重新作答。' def question_giving2_error_message(player, value): print('You chose ', value) if value != 25: return '此问题答案错误,请重新作答。' def question_giving3_error_message(player, value): print('You chose ', value) if value != 10: return '此问题答案错误,请重新作答。' def question_giving4_error_message(player, value): print('You chose ', value) if value != 0: return '此问题答案错误,请重新作答。' class ConsentForm(Page): form_model = 'player' form_fields = ['is_agree'] @staticmethod def before_next_page(player,timeout_happened): if player.is_agree: player.subsession.consent_no += 1 class RefusePage(Page): @staticmethod def is_displayed(player: Player): return (not player.is_agree) class Demographics(Page): form_model = 'player' form_fields = ['name','gender','age'] @staticmethod def before_next_page(player, timeout_happened): player.participant.label = player.name + '_' + datetime.today().strftime('%Y-%m-%d') class InstructionsText(Page): pass class Check(Page): form_model = 'player' form_fields = ['who_receive','question_giving1','question_giving2','question_giving3','question_giving4'] class InstructionsGraphics(Page): pass class InputPage(Page): @staticmethod def before_next_page(player,timeout_happened): import time player.participant.arrival_at_waiting = time.time() page_sequence = [ConsentForm, RefusePage, Demographics, InstructionsText, Check, InstructionsGraphics, InputPage ]