from otree.api import * from csv import reader class C(BaseConstants): NAME_IN_URL = 'survey' PLAYERS_PER_GROUP = None PAPERCUPS_TEMPLATE = '_templates/global/papercups.html' NUM_ROUNDS = 1 course = ['principle', 'intermediate', 'game', 'theory', 'exp'] # course = [ # dict(name='principle', label="個體經濟學原理(原名:經濟學原理與實習上)"), # dict(name='intermediate', label="個體經濟學"), # dict(name='theory', label="個體經濟理論"), # dict(name='game', label="經濟系開設之賽局相關選修課程(例如:賽局論)"), # dict(name='exp', label="實驗經濟學"), # dict(name='none', label="我未曾修過以上任一門課程"), # ] class Subsession(BaseSubsession): pass class Group(BaseGroup): pass def get_department_lst(): with open('_static/experiment/department_list.csv', 'r', encoding="utf-8") as f: lst = f.read().strip().split("\n") lst = [(x, x) for x in lst] return lst # with open('_static/experiment/department_list.csv', 'r', encoding="utf-8") as csv_file: # csv_reader = reader(csv_file) # # Passing the csv_reader object to list() to get a list of lists # list_of_rows = list(csv_reader) # return list_of_rows class Player(BasePlayer): age = models.IntegerField(label='你的年齡是:', min=17, max=99, required = True) gender = models.StringField( choices=[['Male', '生理男'], ['Female', '生理女'], ['Other', '其他']], label='你的生理性別是:', widget=widgets.RadioSelect, required = True ) blood_type = models.StringField( choices=[['A', 'A型'], ['B', 'B型'], ['O', 'O型'], ['AB', 'AB型'], ['Other', '其他']], label='你的血型是:', required = True ) identity = models.BooleanField( choices=[['True', '台灣本地生'], ['False', '非台灣本地生(例如:僑生、外籍交換學生等)']], label='你是否為台灣本地生?', widget=widgets.RadioSelect, required = True ) grade = models.StringField( choices=[['1', '大學部1年級'], ['2', '大學部2年級'], ['3', '大學部3年級'], ['4', '大學部4年級'], ['5', '大學部5年級以上'], ['6', '碩士班'], ['7', '博士班'], ['8', '其他']], label='你的年級是:', required = True ) #from django.core.validators import MinLengthValidator #class Volume(models.Model): #department = models.CharField('Volume Number', max_length=4, validators=[MinLengthValidator(4)]) # department = models.StringField( # label='你的學號第四至七碼是:', # #max_length = 4, # required = True, # ) department = models.StringField( label='你的系所是:', required = True, choices=get_department_lst() ) #number_of_courses = models.StringField( # choices=[['1', '個體經濟學原理(原經濟學原理與實習上)'], ['2', '個體經濟學'], ['3', '賽局論'], ['4', '個體經濟理論(僅限經濟系選修)'], ['5', '實驗經濟學']], # label='請問你目前為止修過幾堂經濟學相關課程?', #) decision_rule = models.LongStringField( label='請問在實驗過程中,你是如何決定「繼續」或「停下」?', required = True ) # principle = models.BooleanField(initial=False, blank=True) # intermediate = models.BooleanField(initial=False, blank=True) # theory = models.BooleanField(initial=False, blank=True) # game = models.BooleanField(initial=False, blank=True) # exp = models.BooleanField(initial=False, blank=True) # none = models.BooleanField(initial=False, blank=True) # num_selected = models.IntegerField(initial=0) principle = models.BooleanField( choices=[['True', '是'], ['False', '否']], label='你是否修過個體經濟學原理(原名:經濟學原理與實習上)?', widget=widgets.RadioSelect, required = True ) intermediate = models.BooleanField( choices=[['True', '是'], ['False', '否']], label='你是否修過個體經濟學?', widget=widgets.RadioSelect, required = True ) game = models.BooleanField( choices=[['True', '是'], ['False', '否']], label='你是否修過經濟系開設之賽局相關選修課程(例如:賽局論)?', widget=widgets.RadioSelect, required = True ) theory = models.BooleanField( choices=[['True', '是'], ['False', '否']], label='你是否修過個體經濟理論?', widget=widgets.RadioSelect, required = True ) exp = models.BooleanField( choices=[['True', '是'], ['False', '否']], label='你是否修過實驗經濟學?', widget=widgets.RadioSelect, required = True ) # possible solution for multiple choices:(中文無法顯示) #https://s3.amazonaws.com/otreehub/browsable_source/1e38462b-46c7-4ca1-bca5-536462f90131/multi_select/index.html # demand_effect = models.StringField( # label='請你猜測本實驗的目的為何:', # ) # def department_error_message(player, value): # if len(value) != 4: # return '請輸入一組四位數的系所代碼!' # FUNCTIONS # PAGES class Exp_survey1(Page): form_model = 'player' form_fields = ['age','gender','identity','grade','department','decision_rule'] @staticmethod def is_displayed(player:Player): participant = player.participant return participant.drop == False and participant.single == False class Exp_survey2(Page): form_model = 'player' form_fields = ['principle', 'intermediate', 'game', 'theory', 'exp'] # @staticmethod # def get_form_fields(player: Player): # return [course['name'] for course in C.course] # @staticmethod # def error_message(player: Player, values): # for course in C.course: # if values[course['name']]: # player.num_selected += 1 # if player.num_selected < 1: # return "請勾選至少一個選項!" # elif player.none == True and player.num_selected != 1: # return "系統偵測到錯誤:你已勾選「我未曾修過以上任一門課程」,因此不得再勾選其他選項。" @staticmethod def is_displayed(player:Player): participant = player.participant return participant.drop == False and participant.single == False class personal_account(Page): @staticmethod def is_displayed(player:Player): participant = player.participant return participant.drop == False class message(Page): @staticmethod def is_displayed(player:Player): participant = player.participant return participant.drop == True page_sequence = [ Exp_survey1, Exp_survey2, message, personal_account, ]