def create_dock_windows(self): self.dock_view_list = ViewList() self.dock_view_list.select_item_index.connect(self.select_item_change) # self.view_dock_widget.setWidget(self.view_list) self.addDockWidget(Qt.RightDockWidgetArea, self.dock_view_list) self.dock_slice_info = InfoWidget() self.addDockWidget(Qt.LeftDockWidgetArea, self.dock_slice_info) self.dock_slice_info.setMinimumWidth(self.width * 0.5) self.dock_slice_info.setMinimumHeight(self.height * 0.4) self.dock_slice_tif = TifWidget() self.addDockWidget(Qt.LeftDockWidgetArea, self.dock_slice_tif) self.dock_slice_tif.setMinimumWidth(self.width * 0.5) self.dock_slice_tif.setFixedHeight(self.height * 0.5) self.dock_debug_info = DebugInfo() self.addDockWidget(Qt.LeftDockWidgetArea, self.dock_debug_info) self.dock_debug_info.setMinimumWidth(self.width * 0.5) self.dock_debug_info.setFixedHeight(self.height * 0.4) self.dock_debug_info.set_text_browser('') version_file = QFile("Version.txt") version_file.open(QIODevice.ReadOnly) ver_info = str(version_file.readAll(), encoding='utf-8') version_file.close() self.dock_debug_info.set_head_info(ver_info)
def __init__(self, verbose=False): self._verbose = verbose if self._verbose: A = DebugInfo() A.addInfo("Add dialog") print("Add dialog") self.question = cf.question_table self._filters = { "ownerId": cf.DEFAULT_ID, "userId": cf.DEFAULT_ID, "botId": cf.DEFAULT_ID, "dialog_context": cf.DEFAULT_CONTEXT, "dialog_answer": cf.DEFAULT_CONTEXT, "type": cf.AIMLTYPE } self._proj = { "_id": 0, "ownerId": 1, "userId": 1, "botId": 1, "dialog_context": 1, "dialog_answer": 1, "create_time": 1, "type": 1 } self._sort_by = [("create_time", -1)]
def __init__(self, verbose=False): self._verbose = verbose if self._verbose: A = DebugInfo() A.addInfo("Init CustomDB") print("Init CustomDB") self.ruleColl = Config.basic_ruleColl self._filters = {"userID": Config.DEFAULT_ID, "botID": Config.DEFAULT_ID} self._proj = {"_id": 0, "ruleID": 1, "matched": 1, "response": 1, "datetime": 1} self._sort_by = [("ruleID", -1)]
def Alice(userId, ownerId, botId, context): if context.strip() == "" or context == None: return "输入查询内容不能为空" userId, ownerId, botId = isNone(userId, ownerId, botId) A = DebugInfo() response, debug = alice.match(ownerId, userId, botId, time.asctime(time.localtime(time.time())), "AIML", context.encode("utf-8")) session = Dialog() A.addInfo(debug) session.insert(cf.dialog_table, ownerId, userId, botId, context.encode('utf-8'), response, cf.AIMLTYPE) history = session.getDialog(ownerId=ownerId, userId=userId, botId=botId, type=cf.AIMLTYPE) return A.context, userId, ownerId, botId, history, response
def alice_detail(): global userId global ownerId global botId A = DebugInfo() reload(sys) sys.setdefaultencoding('utf-8') context = request.form.get("context") if context == None or context == "": return redirect(url_for('alice')) timemark = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())) response, debug = result(ownerId, userId, botId,context.encode("utf-8"), timemark) A.addInfo(debug) session = Dialog() session.insert(cf.dialog_table, ownerId, userId, botId, context.encode('utf-8'), response, cf.AIMLTYPE) history = session.getDialog(ownerId=ownerId, userId=userId, botId=botId, type=cf.AIMLTYPE) return render_template('alice.html', history=history, yx_aiml=A.context, userId=userId, ownerId=ownerId, botId=botId)
def Custom(userId, ownerId, botId, context): if context.strip() == "" or context == None: return "输入查询内容不能为空" userId, ownerId, botId = isNone(userId, ownerId, botId) B = DebugInfo() cd = CustomDesign(verbose=True) response, debug = cd.match(ownerid=ownerId, userid=userId, botid=botId, timemark=time.asctime( time.localtime(time.time())), moduletype=cf.moduleType, query=context.encode('utf-8')) return response, debug
def getRules(self, collection, ownerID, userID, botID): try: self._filters["ownerID"] = ownerID self._filters["userID"] = userID self._filters["botID"] = botID cursor = _mongoDB.search( collection, self._filters, self._proj, self._sort_by, 0 ) if not cursor: A = DebugInfo() A.addInfo("Rule between {0} and {1} is None \n".format(userID, botID)) print("Rule between {0} and {1} is None ".format(userID, botID)) return {} retV = {} for ele in cursor: retV[ele["matched"]] = (ele["response"], ele["ruleID"]) return retV except KeyError as e: print(e) return {}
def setSingleRule(self, collection, ownerID, userID, botID, matched, response): """ 插入单条规则,成功则返回 1, 存在则返回 0 失败则返回 -1 :return: """ try: # is exist? data = { "ownerID": ownerID, "userID": userID, "botID": botID, "matched": matched, "response": response } is_exist = _mongoDB.count(collection, data) if is_exist: return 0 self._filters["ownerID"] = ownerID self._filters["userID"] = userID self._filters["botID"] = botID nextidx = _mongoDB.count(collection, self._filters) + 1 datetime = time.getCurrentTime() data["datetime"] = datetime data["ruleID"] = nextidx if self._verbose: A = DebugInfo() A.context += ("Insert", data) print ("Insert", data) result = _mongoDB.insert(collection, data) if result: return 1 else: return -1 except PyMongoTimeOutError as e: DebugInfo.context += "Custom Design:\n\t MongoDB Error: {0}".format(e) print("Custom Design:\n\t MongoDB Error: {0}".format(e)) return -1 except Exception as e: DebugInfo.context +="Custom Design:\n\t{0}".format(e) print ("Custom Design:\n\t{0}".format(e)) return -1
def insert(self, collection, ownerId, userId, botId, dialog_context, dialog_answer, type): try: if ownerId == None or ownerId == "": ownerId = cf.DEFAULT_ID if userId == None or userId == "": userId = cf.DEFAULT_ID if botId == None or botId == "": botId = cf.DEFAULT_ID if type == None or type == "": type = cf.AIMLTYPE data = { "ownerId": ownerId, "userId": userId, "botId": botId, "dialog_context": dialog_context, "dialog_answer": dialog_answer, "type": type } datetime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) data["create_time"] = datetime if self._verbose: A = DebugInfo() A.context += ("Insert", data) print("Insert", data) result = _mongoDB.insert(collection, data) if result: return 1 else: return -1 except PyMongoTimeOutError as e: DebugInfo.context += " dialog:\n\t MongoDB Error: {0}".format(e) print("dialog:\n\t MongoDB Error: {0}".format(e)) return -1 except Exception as e: DebugInfo.context += "dialog:\n\t{0}".format(e) print("dialog:\n\t{0}".format(e)) return -1
class DetectionWindow(QMainWindow): def __init__(self): super(DetectionWindow, self).__init__() self.slice_image_list = [] # 放置tif文件路径 self.setWindowTitle('胃癌组织病理辅助诊断系统') self.setGeometry(400, 200, 800, 600) self.showMaximized() self.width = self.width() self.height = self.height() # 菜单栏 self.menu_bar = self.menuBar() # 文件选项 self.menufile = QMenu("文件", self) self.menufile.setObjectName("menufile") self.menu_bar.addMenu(self.menufile) #导入 self.action_open_file = QAction('导入', self.menufile) self.action_open_file.setStatusTip('导入.') self.action_open_file.triggered.connect(self.open_file) self.menufile.addAction(self.action_open_file) #批量导入 self.action_batch_open = QAction('批量导入', self.menufile) self.action_batch_open.setStatusTip('批量导入') self.action_batch_open.triggered.connect(self.batch_open) self.menufile.addAction(self.action_batch_open) # 编辑 self.action_clear_info = QAction('分析', self) self.action_clear_info.setStatusTip('分析.') self.action_clear_info.triggered.connect(self.analysis) self.menu_bar.addAction(self.action_clear_info) # 可视化 self.action_visual = QAction('可视化', self) self.action_visual.setStatusTip('可视化.') self.action_visual.triggered.connect(self.visualize) self.menu_bar.addAction(self.action_visual) # 日志 self.dialog = QAction('日志', self) self.dialog.setStatusTip('日志.') self.dialog.triggered.connect(self.dialog_info) self.menu_bar.addAction(self.dialog) self.target_view = TargetView() self.setCentralWidget(self.target_view) self.target_view.setBackgroundBrush( QBrush(QColor(214, 214, 214), Qt.SolidPattern)) self.create_dock_windows() def create_dock_windows(self): self.dock_view_list = ViewList() self.dock_view_list.select_item_index.connect(self.select_item_change) # self.view_dock_widget.setWidget(self.view_list) self.addDockWidget(Qt.RightDockWidgetArea, self.dock_view_list) self.dock_slice_info = InfoWidget() self.addDockWidget(Qt.LeftDockWidgetArea, self.dock_slice_info) self.dock_slice_info.setMinimumWidth(self.width * 0.5) self.dock_slice_info.setMinimumHeight(self.height * 0.4) self.dock_slice_tif = TifWidget() self.addDockWidget(Qt.LeftDockWidgetArea, self.dock_slice_tif) self.dock_slice_tif.setMinimumWidth(self.width * 0.5) self.dock_slice_tif.setFixedHeight(self.height * 0.5) self.dock_debug_info = DebugInfo() self.addDockWidget(Qt.LeftDockWidgetArea, self.dock_debug_info) self.dock_debug_info.setMinimumWidth(self.width * 0.5) self.dock_debug_info.setFixedHeight(self.height * 0.4) self.dock_debug_info.set_text_browser('') version_file = QFile("Version.txt") version_file.open(QIODevice.ReadOnly) ver_info = str(version_file.readAll(), encoding='utf-8') version_file.close() self.dock_debug_info.set_head_info(ver_info) def open_file(self): try: file_path = QFileDialog.getOpenFileName( self, '选择图像文件', '.', # "All Files (*.*);; " "Tiff Image (*.tif;*.tiff);; " "General Image (*.bmp;*.jpg;*.png);;") # txt_path = QFileDialog.getOpenFileName(self, '选择检测结果', './images', # # "All Files (*.*);; " # "TXT (*.txt);;") # print(file_path) tif_list = [] image_path = file_path[0] image_name = image_path.split('.')[0].split('/')[-1] tif_list.append(image_name + "." + image_path.split('.')[-1]) self.dock_slice_tif.set_slice_view(tif_list) except: QMessageBox.critical(self, "错误", "导入失败", QMessageBox.Yes, QMessageBox.Yes) def batch_open(self): startDirectory = "C://" os.startfile(startDirectory) def analysis(self): self.target_view.clear_target_view() self.dock_view_list.clear_view_list() # self.dock_slice_info.clear_info() self.boxes_info.clear() self.slice_image_list.clear() def visualize(self): self.target_view.show_boxes() self.dock_view_list.set_slice_view(self.slice_image_list) def dialog_info(self): print(self) def select_item_change(self, connect): self.target_view.focus_box(int(connect)) box_info = self.boxes_info[connect] info_dict = {} info_dict['index'] = connect + 1 info_dict['position'] = '({}, {})'.format(box_info[0], box_info[1]) info_dict['width'] = box_info[2] - box_info[0] info_dict['height'] = box_info[3] - box_info[1] info_dict['score'] = box_info[4] self.dock_slice_info.set_info(info_dict)