from otree.api import * import pandas as pd doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'Senti_Weibo' PLAYERS_PER_GROUP = None NUM_ROUNDS = 300 file=pd.read_excel("./Senti_Weibo/情感分析_20220831.xlsx") # answer = [[0, '附带效益'], [1, '全球问题'], [2, '科学问题'], [3, '政治问题'], [4, '道德问题'], [5, '经济问题'], [6, '能源问题'],[7,'无关'],[8,'尚未确定']] answer_1 = [[0, '反对'], [1, '支持'], [2, '中立'],[3, '无关']] answer_2 = [[0, '积极'], [1, '消极'], [2, '中立'],[3, '无关']] class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): c=C() # answer = c.answer answer_2 = c.answer_2 answer_1 = c.answer_1 df=c.file # multi_label = models.MultipleChoiceModelField( # choices=answer, # label='请根据以上所给信息,对给出的微博内容标注框架分类?', # min_choices=1, # max_choices=3, # ) # Label = models.StringField( # choices=answer, # label='请根据以上所给信息,对给出的微博内容标注框架分类?', # widget=widgets.RadioSelect, # ) Label_1 = models.StringField( choices=answer_1, label='请给出该条微博的态度分类?', widget=widgets.RadioSelect, ) Label_2 = models.StringField( choices=answer_2, label='请给出该条微博的情感分类?', widget=widgets.RadioSelect, ) Label_0 = models.StringField( choices=[[0, '需要'], [1, '不需要']], label='是否需要显示机器预测结果?', initial=0 ) # Choices_0 = models.BooleanField( # blank=True, # initial=False, # label='0 附带效益', # widget = widgets.RadioSelect, # ) # Choices_1 = models.BooleanField( # blank=True, # initial=False, # label='1 全球问题', # widget=widgets.RadioSelect, # ) # Choices_2 = models.BooleanField( # blank=True, # initial=False, # label='2 科学问题', # widget=widgets.RadioSelect, # ) # Choices_3 = models.BooleanField( # blank=True, # initial=False, # label='3 政治问题', # widget=widgets.RadioSelect, # ) # Choices_4 = models.BooleanField( # blank=True, # initial=False, # label='4 道德问题', # widget=widgets.RadioSelect, # ) # Choices_5 = models.BooleanField( # blank=True, # initial=False, # label='5 经济问题', # widget=widgets.RadioSelect, # ) # Choices_6 = models.BooleanField( # blank=True, # initial=False, # label='6 能源问题', # widget=widgets.RadioSelect, # ) # Choices_7 = models.BooleanField( # blank=True, # initial=False, # label='7 无关问题', # widget=widgets.RadioSelect, # ) # Choices_8 = models.BooleanField( # blank=True, # initial=False, # label='8 尚未确定', # widget=widgets.RadioSelect, # ) # PAGES class MyPage1(Page): form_model = 'player' form_fields = ['Label_1'] # form_fields = ['Choices_0', 'Choices_1', 'Choices_2', 'Choices_3', 'Choices_4', 'Choices_5', 'Choices_6', 'Choices_7', 'Choices_8'] @staticmethod def vars_for_template(player): r_num = player.round_number r_data_0 = player.df.loc[r_num-1] r_data = r_data_0.tolist() return dict( ID=r_data[0], content_weibo=r_data[3], ID_weibo=r_data[1], time_weibo=r_data[4], sort_weibo=r_data[5], method_weibo=r_data[7], predict_weibo_att=r_data[8], predict_weibo_sen = r_data[9] ) class MyPage2(Page): form_model = 'player' form_fields = ['Label_2'] # form_fields = ['Choices_0', 'Choices_1', 'Choices_2', 'Choices_3', 'Choices_4', 'Choices_5', 'Choices_6', 'Choices_7', 'Choices_8'] @staticmethod def vars_for_template(player): r_num = player.round_number r_data_0 = player.df.loc[r_num-1] r_data = r_data_0.tolist() return dict( ID=r_data[0], content_weibo=r_data[3], ID_weibo=r_data[1], time_weibo=r_data[4], sort_weibo=r_data[5], method_weibo=r_data[7], predict_weibo_att= r_data[8], predict_weibo_sen = r_data[9] ) class Results(Page): form_model = 'player' @staticmethod def vars_for_template(player): return dict( num=player.round_number ) @staticmethod def is_displayed(player): return player.round_number % 20 == 0 class Display_predict(Page): form_model = 'player' form_fields = ['Label_0'] @staticmethod def vars_for_template(player): r_num = player.round_number r_data_0 = player.df.loc[r_num - 1] r_data = r_data_0.tolist() return dict( ID=r_data[0], content_weibo=r_data[3], ID_weibo=r_data[1], time_weibo=r_data[4], sort_weibo=r_data[5], method_weibo=r_data[7], predict_weibo_att=r_data[8], predict_weibo_sen=r_data[9], num=player.round_number) @staticmethod def is_displayed(player): return player.round_number > 250 or (player.round_number > 100 and player.round_number < 151) page_sequence = [Display_predict, MyPage1, MyPage2, Results]