def __init__(self, parent=None, methods=None): super(SimpleTestResultsDialog, self).__init__(parent) self.setWindowTitle("Grismo - Wyniki dla prostego testu") self.setMinimumWidth(500) self.results_count = 0 self.all_results = [] self.methods = methods central = QWidget() self.setCentralWidget(central) result_dialog_layout = QVBoxLayout() central.setLayout(result_dialog_layout) self.results_table = QTableWidget() result_dialog_layout.addWidget(self.results_table) self.results_table.setRowCount(len(methods)) self.results_table.setColumnCount(3) self.results_table.setColumnWidth(2, 200) self.results_table.setHorizontalHeaderLabels(["Metoda", "Wynik", "Czas [s]"]) for i in range(len(methods)): self.results_table.setItem(i, 0, QTableWidgetItem(methods[i])) # plot box x_axis_dict = dict(enumerate(methods)) x_axis = AxisItem(orientation='bottom') x_axis.setTicks([x_axis_dict.items()]) self.results_plot = PlotWidget(axisItems={'bottom': x_axis}) self.results_plot.setBackground('w') self.results_plot.setTitle("Porównanie metod dla wskazanych grafów") self.results_plot.setLabel('left', 'Czas obliczeń [s]', color='k', size=10) self.results_plot.setLabel('bottom', 'Metody ', color='k', size=10) self.results_plot.setMaximumWidth(600) self.results_plot.showGrid(y=True) result_dialog_layout.addWidget(self.results_plot) # prepare plot data pen = mkPen(color='k', width=2) self.plot_data = self.results_plot.plot([], [], pen=pen, symbol='+', symbolSize=10, symbolBrush='k')
def on_pushButton_3_clicked(self): """ Slot documentation goes here. """ # answers = [] # for answer in db['question_'+str(self.index)].find(): # text = answer['content'].replace('\n', '') # if 5 < len(text) < 100: # answers.append(text) answers = [ answer['content'].replace('\n', '') for answer in db['question_' + str(self.index)].find() ] Line1 = InfiniteLine(pos=0, pen=(255, 0, 0), angle=0, movable=False) Line2 = InfiniteLine(pos=0.5, pen=(0, 0, 255), angle=0, movable=False) Line3 = InfiniteLine(pos=1, pen=(0, 255, 0), angle=0, movable=False) import sys start = perf_counter() data = LSTM.get_result(answers, vec_path=sys.path[0] + '/lstm/vec_lstm.pkl', model_path=sys.path[0] + '/lstm/lstmModel.pkl') end = perf_counter() print('情感分析总用时:' + str(end - start) + 's') tricks = [(0, '消极'), (0.5, '中立'), (1, '积极')] strAxis = AxisItem(orientation='left', maxTickLength=3) strAxis.setTicks([ tricks, ]) visitor_count_plot = PlotWidget(axisItems={'left': strAxis}, background=None) visitor_count_plot.plot(y=data, pen=None, symbol='o') visitor_count_plot.showAxis('bottom', False) visitor_count_plot.addItem(Line1) visitor_count_plot.addItem(Line2) visitor_count_plot.addItem(Line3) visitor_count_plot.setObjectName("tab") # visitor_count_plot.enableAutoRange('x', x_axis_scale) self._add_analysis_tab(visitor_count_plot, '情感分析') self.pushButton_3.setEnabled(False)
def _load_analysis(self, x_axis_scale): this_question = db.question.find_one({'_id': self.index}) title = this_question['title'] content = this_question['content'] time_tuple = localtime(this_question['created_time']) question_created_time = "%d-%d-%d %d:%d:%d" % ( time_tuple.tm_year, time_tuple.tm_mon, time_tuple.tm_mday, time_tuple.tm_hour, time_tuple.tm_min, time_tuple.tm_sec) if content != '': self.textEdit.setText(title + '\n\n 提问时间:' + question_created_time + '\n 问题描述:\n' + content) else: self.textEdit.setText(title + '\n\n 提问时间:' + question_created_time) trend = db.question_trend.find_one({'_id': self.index}) time_trend = trend['time'] str_time = [] for num_time in time_trend: local_time = localtime(num_time) str_time.append("%d-%d\n%d:%d\n" % (local_time.tm_mon, local_time.tm_mday, local_time.tm_hour, local_time.tm_min)) ticks = [(i, j) for i, j in zip(time_trend, str_time)] rank_trend = trend['rank'] convert_rank = [51 - i for i in rank_trend] rank_ticks = [(i, j) for i, j in zip(convert_rank, rank_trend)] rankAxis = AxisItem(orientation='left') rankAxis.setTicks([ rank_ticks, ]) strAxis = AxisItem(orientation='bottom', maxTickLength=5) strAxis.setTicks([ ticks, ]) rank_plot = PlotWidget(axisItems={ 'bottom': strAxis, 'left': rankAxis }, background=None) rank_plot.setObjectName("tab") rank_plot.plot(x=time_trend, y=convert_rank, pen=(0, 255, 0), symbol='o') rank_plot.enableAutoRange('x', x_axis_scale) self._add_analysis_tab(rank_plot, '排名') heat_trend = trend['heat'] # strAxis.setStyle(autoExpandTextSpace=True) strAxis = AxisItem(orientation='bottom', maxTickLength=5) strAxis.setTicks([ ticks, ]) heat_plot = PlotWidget(axisItems={'bottom': strAxis}, background=None) heat_plot.setObjectName("tab") heat_plot.plot(x=time_trend, y=heat_trend, pen=(255, 0, 0), symbol='o') heat_plot.enableAutoRange('x', x_axis_scale) self._add_analysis_tab(heat_plot, '热度') answer_count_trend = trend['answer_count'] strAxis = AxisItem(orientation='bottom', maxTickLength=5) strAxis.setTicks([ ticks, ]) answer_count_plot = PlotWidget(axisItems={'bottom': strAxis}, background=None) answer_count_plot.setObjectName("tab") answer_count_plot.plot(x=time_trend, y=answer_count_trend, pen=(0, 0, 255), symbol='o') answer_count_plot.enableAutoRange('x', x_axis_scale) self._add_analysis_tab(answer_count_plot, '回答量') follower_count_trend = trend['follower_count'] strAxis = AxisItem(orientation='bottom', maxTickLength=5) strAxis.setTicks([ ticks, ]) follower_count_plot = PlotWidget(axisItems={'bottom': strAxis}, background=None) follower_count_plot.setObjectName("tab") follower_count_plot.plot(x=time_trend, y=follower_count_trend, pen=(19, 234, 201), symbolBrush=(19, 234, 201), symbol='o', symbolPen='w') follower_count_plot.enableAutoRange('x', x_axis_scale) self._add_analysis_tab(follower_count_plot, '关注数') visitor_count_trend = trend['visitor_count'] strAxis = AxisItem(orientation='bottom', maxTickLength=5) strAxis.setTicks([ ticks, ]) visitor_count_plot = PlotWidget(axisItems={'bottom': strAxis}, background=None) visitor_count_plot.setObjectName("tab") visitor_count_plot.plot(x=time_trend, y=visitor_count_trend, pen=(195, 46, 212), symbolBrush=(195, 46, 212), symbol='t', symbolPen='w') visitor_count_plot.enableAutoRange('x', x_axis_scale) self._add_analysis_tab(visitor_count_plot, '浏览量')