コード例 #1
0
ファイル: stt_proc.py プロジェクト: wnghks4745/MindsLAB
 def do_work(self, frames):
     print 'stt receive frames ({0})'.format(frames)
     header, body = frames
     hdr = common_pb2.Header()
     hdr.ParseFromString(header)
     audio = common_pb2.Audio()
     audio.ParseFromString(body)
     print 'Received request {0}, {1}'.format(hdr, audio)
     client = stt_client.SttClient(self.stt_addr)
     img_name, img_lang, img_sample_rate = hdr.model_params.split('-')
     hdr.status_id = util.ProcStatus.PS_INPROGRESS
     oracle = db_connection.Oracle()
     util.insert_proc_result(oracle, self.logger, hdr)
     if client.get_servers(_name=img_name, _lang=img_lang, _sample_rate=int(img_sample_rate)):
         pcm_filename = audio.filename
         if pcm_filename.endswith('wav'):
             # 화자 분리
             # https://www.nesono.com/node/275
             # sox infile.wav outfile.l.wav remix 1
             # wav 파일 pcm 파일로 전환, sox 에서는 raw 파일이 pcm 으로 취급
             pcm_filename = audio.filename[:-3] + 'raw'
             tfm = sox.Transformer()
             # 같은 파일이 다른 모델로 동시에 처리될 때
             if os.path.exists(pcm_filename):
                 pass
             else:
                 tfm.build(audio.filename, pcm_filename)
         result = client.detail_recognize(pcm_filename)
         if pcm_filename != audio.filename:
             print pcm_filename, audio.filename
             # TODO : CS 후처리
             # os.remove(pcm_filename)
         self.complete_cnt += 1
         # STT_RESULT 테이블에 기록
         stt_result_id = insert_stt_result(oracle, hdr, result)
         stt_result_detail = self.insert_stt_result_detail(oracle, hdr, stt_result_id, result)
         # FLOW_RESULT 테이블에 기록
         hdr.status_id = util.ProcStatus.PS_COMPLETED
         hdr.stt_result_id = stt_result_id
         util.insert_proc_result(oracle, self.logger, hdr)
         # 다음 처리할 프로세스로 데이타 전달
         self.log(logging.DEBUG, "stt result is {0}".format(result.txt))
         # self.sendto_router(info.flow_set, info.flow_id, info.call_id, result)
         # 여러문장 동시 전송
         stt_result = stt_pb2.SttResultDetail()
         stt_result.stt_result_id = stt_result_id
         for sentence in stt_result_detail:
             print sentence
             stt_result.sentence.add(stt_result_detail_id=sentence[0], sequence=sentence[1], sentence=sentence[2])
         # 전체 문장 한꺼번에 전송
         # stt_result = stt_pb2.SttResult()
         # stt_result.result = result.txt
         print stt_result.SerializeToString()
         new_body = stt_result.SerializeToString()
         self.sendto_router_ex(hdr, new_body)
     else:
         self.log(logging.DEBUG, 'CS Service unavailable')
         hdr.status_id = util.ProcStatus.PS_FAILED
         util.insert_proc_result(oracle, self.logger, hdr)
     oracle.disconnect()
コード例 #2
0
 def create_common_header(self, **kwargs):
     try:
         meta_info = kwargs.get('meta_info')
         header = common_pb2.Header()
         header.ticket_id = kwargs.get('ticket_id')
         header.call_id = kwargs.get('call_id')
         header.pipeline_id = kwargs.get('pipeline_id')
         header.pipeline_event_id = kwargs.get('pipeline_event_id')
         header.router_id = kwargs.get('router_id')
         header.proc_id = kwargs.get('proc_id')
         header.status_id = util.ProcStatus.PS_COMPLETED
         header.creator_id = CREATOR_ID
         header.call_metadata.call_id = kwargs.get('call_id')
         header.call_metadata.call_date = meta_info[0].strftime(
             '%Y-%m-%d') if meta_info[0] else 'None'
         header.call_metadata.project_code = meta_info[1]
         header.call_metadata.file_name = meta_info[2]
         header.call_metadata.call_type_code = meta_info[3]
         header.call_metadata.contract_no = meta_info[4] if meta_info[
             4] else 'None'
         header.call_metadata.record_key = meta_info[5] if meta_info[
             5] else 'None'
         header.call_metadata.start_time = str(meta_info[6])
         header.call_metadata.end_time = str(meta_info[7])
         header.call_metadata.duration = meta_info[8]
         header.call_metadata.cti_call_id = meta_info[9] if meta_info[
             9] else 'None'
         header.call_metadata.ruser_id = meta_info[10] if meta_info[
             10] else 'None'
         header.call_metadata.ruser_name = meta_info[11] if meta_info[
             11] else 'None'
         header.call_metadata.ruser_number = meta_info[12]
         header.call_metadata.cu_id = meta_info[13] if meta_info[
             13] else 'None'
         header.call_metadata.cu_name = meta_info[14] if meta_info[
             14] else 'None'
         header.call_metadata.cu_name_hash = meta_info[15] if meta_info[
             15] else 'None'
         header.call_metadata.cu_number = meta_info[16] if meta_info[
             16] else 'None'
         header.call_metadata.in_call_number = meta_info[17]
         header.call_metadata.biz_cd = meta_info[18]
         header.call_metadata.chn_tp = meta_info[19]
         header.call_metadata.file_sprt = meta_info[20]
         header.call_metadata.rec_ext = meta_info[21]
         header.call_metadata.creator_id = meta_info[24] if meta_info[
             24] else 'None'
         header.call_metadata.updator_id = meta_info[25] if meta_info[
             25] else 'None'
         header.call_metadata.speaker_code = kwargs.get('speaker_code')
         header.call_metadata.business_dcd = meta_info[26] if meta_info[
             26] else 'None'
         return header
     except Exception:
         self.logger.error(traceback.format_exc())
         raise Exception(traceback.format_exc())
コード例 #3
0
ファイル: nlp_proc.py プロジェクト: wnghks4745/MindsLAB
 def do_work(self, frames):
     header, body = frames
     hdr = common_pb2.Header()
     oracle = db_connection.Oracle()
     try:
         hdr.ParseFromString(header)
         # 통 문장 분석 시
         # stt_result = stt_pb2.SttResult()
         # 다중 문장 분석 시
         stt_result = stt_pb2.SttResultDetail()
         stt_result.ParseFromString(body)
         client = nlp_client.NlpClient()
         hdr.status_id = util.ProcStatus.PS_INPROGRESS
         oracle = db_connection.Oracle()
         util.insert_proc_result(oracle, self.logger, hdr)
         level1, level2 = hdr.model_params.split('_')
         rc = client.get_provider()
         if rc is not None:
             hdr.status_id = util.ProcStatus.PS_FAILED
             util.insert_proc_result(oracle, self.logger, hdr)
             self.log(logging.ERROR, rc)
             return
         nlp_result_list = nlp_pb2.nlpResultDetail()
         nlp_document = brain_nlp_pb2.Document()
         sentence_cnt = 0
         for sentence in stt_result.sentence:
             sentence_cnt += 1
             result = client.analyze(sentence.sentence, int(level1),
                                     int(level2))
             nlp_result_id = record_result(oracle, hdr, sentence, result)
             nlp_result_list.documentList.add(nlp_result_id=nlp_result_id,
                                              sentence=sentence.sentence,
                                              document=result[2])
             record_result_detail(oracle, hdr, result, nlp_result_id)
         print "{0} NLP Process Success".format(sentence_cnt)
         self.log(logging.INFO,
                  "{0} NLP Process Success".format(sentence_cnt))
         # Insert CS_PERFECT_SALES_CALL_LIST_TB
         if hdr.call_metadata.speaker_code == 'ST0002':
             if hdr.call_metadata.business_dcd in ['CJ0016', 'CJ0017']:
                 insert_perfect_sales_tb(oracle, hdr)
         hdr.status_id = util.ProcStatus.PS_COMPLETED
         util.insert_proc_result(oracle, self.logger, hdr)
         new_body = nlp_result_list.SerializeToString()
         self.sendto_router_ex(hdr, new_body)
     except grpc.RpcError as e:
         print 'grpc.RpcError: {0}'.format(e)
         hdr.status_id = util.ProcStatus.PS_FAILED
         util.insert_proc_result(oracle, self.logger, hdr)
         self.log(logging.ERROR, e)
     except Exception:
         hdr.status_id = util.ProcStatus.PS_FAILED
         util.insert_proc_result(oracle, self.logger, hdr)
         self.log(logging.ERROR, traceback.format_exc())
     finally:
         oracle.disconnect()
コード例 #4
0
ファイル: biz_worker.py プロジェクト: wnghks4745/MindsLAB
    def sendto_router(self, msg_hdr, flow_id, call_id, result):
        """
        Args:
            flow_set (str): The first parameter.
            flow_id (str): The second parameter.
            call_id (str): call_id
            result (protobuf): grpc result

        Returns:
            None
        """
        # Make Protobuf Message
        # input으로 들어왔던 메시지에 body값만 생성한뒤 라우터로
        # 보내면 router에서 flow_id, category, model값을 알아서
        # 교체해서 다음 프로세스로 전달한다
        msg_hdr = common_pb2.Header()
        self.router_socket.send_multipart([
            msg_hdr.SerializeToString(),
            msg_meta.SerializeToString(),
            msg_body.SerializeToString()
        ])
コード例 #5
0
ファイル: nlp_proc.py プロジェクト: wnghks4745/MindsLAB
 def do_work(self, frames):
     header, body = frames
     hdr = common_pb2.Header()
     oracle = db_connection.Oracle()
     try:
         hdr.ParseFromString(header)
         # 통 문장 분석 시
         # stt_result = stt_pb2.SttResult()
         # 다중 문장 분석 시
         stt_result = stt_pb2.SttResultDetail()
         stt_result.ParseFromString(body)
         client = nlp_client.NlpClient()
         hdr.status_id = util.ProcStatus.PS_INPROGRESS
         oracle = db_connection.Oracle()
         util.insert_proc_result(oracle, self.logger, hdr)
         level1, level2 = hdr.model_params.split('_')
         rc = client.get_provider()
         if rc is not None:
             hdr.status_id = util.ProcStatus.PS_FAILED
             util.insert_proc_result(oracle, self.logger, hdr)
             self.log(logging.ERROR, rc)
             return
         nlp_result_list = nlp_pb2.nlpResultDetail()
         nlp_document = brain_nlp_pb2.Document()
         sentence_cnt = 0
         for sentence in stt_result.sentence:
             sentence_cnt += 1
             try:
                 result = client.analyze(sentence.sentence, int(level1),
                                         int(level2))
             except Exception:
                 try:
                     result = client.analyze(sentence.sentence, int(level1),
                                             int(level2))
                 except Exception:
                     try:
                         result = client.analyze(sentence.sentence,
                                                 int(level1), int(level2))
                     except Exception:
                         self.log(
                             logging.ERROR,
                             "REC_ID = {0}, RFILE_NAME = {1}".format(
                                 hdr.call_metadata.record_key,
                                 hdr.call_metadata.file_name))
                         self.log(logging.ERROR, traceback.format_exc())
                         continue
             nlp_result_id = record_result(oracle, hdr, sentence, result)
             nlp_result_list.documentList.add(
                 nlp_result_id=nlp_result_id,
                 sequence=sentence.sequence,
                 sentence=sentence.sentence,
                 document=result[2],
                 start_time=sentence.start_time,
                 end_time=sentence.end_time,
                 stt_result_detail_id=sentence.stt_result_detail_id)
             try:
                 record_result_detail(oracle, hdr, result, nlp_result_id)
             except Exception:
                 continue
         self.log(logging.INFO,
                  "{0} NLP Process Success".format(sentence_cnt))
         hdr.status_id = util.ProcStatus.PS_COMPLETED
         util.insert_proc_result(oracle, self.logger, hdr)
         new_body = nlp_result_list.SerializeToString()
         self.sendto_router_ex(hdr, new_body)
     except grpc.RpcError:
         hdr.status_id = util.ProcStatus.PS_FAILED
         util.insert_proc_result(oracle, self.logger, hdr)
         self.log(
             logging.ERROR, "REC_ID = {0}, RFILE_NAME = {1}".format(
                 hdr.call_metadata.record_key, hdr.call_metadata.file_name))
         self.log(logging.ERROR, traceback.format_exc())
     except Exception:
         hdr.status_id = util.ProcStatus.PS_FAILED
         util.insert_proc_result(oracle, self.logger, hdr)
         self.log(logging.ERROR, traceback.format_exc())
     finally:
         oracle.disconnect()
コード例 #6
0
ファイル: hmd_proc.py プロジェクト: wnghks4745/MindsLAB
 def do_work(self, frames):
     """ BizWorker 에서 호출하는 callback 함수"""
     header, body = frames
     hdr = common_pb2.Header()
     oracle = db_connection.Oracle()
     st = datetime.now()
     try:
         hdr.ParseFromString(header)
         hmd_client_obj = hmd_client.HmdClient(self.hmd_addr)
         project_code = hdr.call_metadata.project_code
         call_type_code = hdr.call_metadata.call_type_code
         speaker_code = hdr.call_metadata.speaker_code
         if speaker_code == 'ST0001':
             # RX(LEFT) 파일 고객
             file_dcd = 'FS0001'
         elif speaker_code == 'ST0002':
             # TX(RIGHT) 파일 상담사
             file_dcd = 'FS0002'
         else:
             file_dcd = 'FS0003'
         # PROJECT_CODE(CS OR TM), CALL_TYPE_CODE(IN OR OUTBOUND CALL), FILE_DCD(화자)
         # 기준으로 TA_HMD_MODEL_TB 에서 수행해야 할 HMD 목록을 가져온다.
         hmd_list = select_hmd_list(oracle, project_code, call_type_code,
                                    file_dcd)
         sentence_cnt = 0
         if hdr.model_params in hmd_list:
             nlp_result_detail = nlp_pb2.nlpResultDetail()
             nlp_result_detail.ParseFromString(body)
             # 관심 키워드
             if hdr.model_params in [
                     'interest_keyword_cs_hmd', 'interest_keyword_tm_hmd'
             ]:
                 for document in nlp_result_detail.documentList:
                     hmd_result = execute_hmd(document, hdr.model_params)
                     if len(hmd_result) > 0:
                         sentence_cnt += 1
                         insert_interest_hmd_result(oracle, hmd_result,
                                                    document, hdr)
             # 호전환 콜
             elif hdr.model_params == 'calltransfer_hmd':
                 for document in nlp_result_detail.documentList:
                     hmd_result = execute_hmd(document, hdr.model_params)
                     if len(hmd_result) > 0:
                         sentence_cnt += 1
                         insert_transfer_call_analysis_hmd_result(
                             oracle, hmd_result, hdr, document)
                         break
             # 관심 구간
             elif hdr.model_params in [
                     'interest_section_cs_hmd', 'interest_section_tm_hmd'
             ]:
                 hmd_result_list = list()
                 start_point_dict = dict()
                 for document in nlp_result_detail.documentList:
                     hmd_result = execute_hmd(document, hdr.model_params)
                     if len(hmd_result) > 0:
                         sentence_cnt += 1
                         hmd_result_list.append((hmd_result, document))
                         for cls in hmd_result.keys():
                             cat_list = cls.split('_')
                             if len(cat_list) != 3:
                                 continue
                             section_code, section_number, cust_yn = cat_list
                             if section_number == '001':
                                 if not section_code in start_point_dict:
                                     start_point_dict[section_code] = [
                                         document.sequence,
                                         document.start_time
                                     ]
                 insert_interest_section_hmd_result(oracle, hmd_result_list,
                                                    hdr, start_point_dict,
                                                    self.log)
             # 상담 유형 분류, 상담 유형별 스크립트 미준수율
             elif hdr.model_params in [
                     'call_driver_classify_cs_hmd',
                     'call_driver_classify_tm_hmd'
             ]:
                 total_category_dict = dict()
                 if hdr.model_params == 'call_driver_classify_cs_hmd':
                     name = 'call_driver_classify_cs'
                 else:
                     name = 'call_driver_classify_tm'
                 for document in nlp_result_detail.documentList:
                     hmd_result = execute_hmd(document, hdr.model_params)
                     if len(hmd_result) > 0:
                         sentence_cnt += 1
                         # 상담 유형 분류
                         category_dict = insert_call_driver_classify_hmd_result(
                             oracle, hmd_result, document, hdr, name)
                         for category in category_dict.keys():
                             if category not in total_category_dict:
                                 total_category_dict[category] = 1
                 if total_category_dict:
                     # 상담 유형별 스크립트 미준수율
                     category_list = total_category_dict.keys()
                     execute_call_driver_classify_script_quality(
                         oracle, category_list, nlp_result_detail, hdr,
                         hmd_client_obj)
             # 에러 콜
             elif hdr.model_params == 'error_call_hmd':
                 for document in nlp_result_detail.documentList:
                     hmd_result = execute_hmd(document, hdr.model_params)
                     if len(hmd_result) > 0:
                         sentence_cnt += 1
                         insert_error_call_hmd_result(
                             oracle, hmd_result, hdr, document)
                         break
             # 상담 품질 필수 문장
             elif hdr.model_params == 'require_sentence_hmd':
                 hmd_result_list = list()
                 if hdr.call_metadata.call_type_code == 'CT0001':
                     model_params = 'require_sentence_in_hmd'
                 else:
                     model_params = 'require_sentence_out_hmd'
                 for document in nlp_result_detail.documentList:
                     hmd_result = execute_hmd(document, model_params)
                     if len(hmd_result) > 0:
                         sentence_cnt += 1
                         hmd_result_list.append((hmd_result, document))
                 insert_require_sentence_hmd_result(oracle, hmd_result_list,
                                                    hdr)
             # 부정/민원/불만
             elif hdr.model_params in [
                     'negative_keyword_cs_hmd', 'negative_keyword_tm_hmd'
             ]:
                 for document in nlp_result_detail.documentList:
                     hmd_result = execute_hmd(document, hdr.model_params)
                     if len(hmd_result) > 0:
                         sentence_cnt += 1
                         insert_negative_keyword_hmd_result(
                             oracle, hmd_result, document, hdr)
             self.log(
                 logging.INFO,
                 "{0} {1} HMD Process REQUIRED TIME = {2}".format(
                     sentence_cnt, hdr.model_params,
                     str(datetime.now() - st)))
         hdr.status_id = util.ProcStatus.PS_COMPLETED
         util.insert_proc_result(oracle, self.logger, hdr)
         oracle.conn.commit()
     except grpc.RpcError as e:
         oracle.conn.rollback()
         hdr.status_id = util.ProcStatus.PS_FAILED
         util.insert_proc_result(oracle, self.logger, hdr)
         self.log(logging.ERROR, e)
     except Exception:
         oracle.conn.rollback()
         hdr.status_id = util.ProcStatus.PS_FAILED
         util.insert_proc_result(oracle, self.logger, hdr)
         self.log(logging.ERROR, traceback.format_exc())
     finally:
         oracle.disconnect()
コード例 #7
0
def main():
    """
    Router process
    """
    global LOGGER
    LOGGER.info('Router Process started...')
    conf = Config()
    conf.init('biz.conf')
    backend_map = dict()
    pipeline_info = util.create_pipeline_info()
    tree_map = pipeline_info['tree']
    category_list = [
        ('STT', conf.get('stt.pull.port'), conf.get('stt.router.port')),
        ('HMD', conf.get('hmd.pull.port'), conf.get('hmd.router.port')),
        ('NLP', conf.get('nlp.pull.port'), conf.get('nlp.router.port')),
        ('DNN', conf.get('dnn.pull.port'), conf.get('dnn.router.port'))
    ]
    process_list = list()
    for category, frontend_port, backend_port in category_list:
        p = BizRouter(category, frontend_port, backend_port)
        p.start()
        backend_map[category] = zmq.Context().socket(zmq.PUSH)
        backend_map[category].connect(
            'tcp://127.0.0.1:{0}'.format(frontend_port))
        process_list.append(p)
    # PULLER
    frontend = zmq.Context().socket(zmq.PULL)
    # For clients
    frontend.bind("tcp://*:{0}".format(conf.get('router.pull.port')))
    cli_socket = zmq.Context().socket(zmq.REP)
    cli_socket.bind('ipc:///tmp/biz_cli.zmq')
    poller = zmq.Poller()
    poller.register(frontend, zmq.POLLIN)
    poller.register(cli_socket, zmq.POLLIN)
    while True:
        oracle = db_connection.Oracle()
        socks = dict(poller.poll(1 * 1000))
        if socks.get(frontend) == zmq.POLLIN:
            header, body = frontend.recv_multipart()
            hdr = common_pb2.Header()
            hdr.ParseFromString(header)
            LOGGER.debug('FRONT(PULL) received info : {0}'.format(hdr))
            # Select tree
            tree = tree_map[hdr.pipeline_id]
            for child in tree.children(hdr.router_id):
                # data: model_params, proc_id, proc_name, router_id, model_id, config_id, proc_meta, model_name, proc_type_code
                model_params = child.data[0]
                proc_id = child.data[1]
                proc_name = child.data[2]
                #                router_id = child.data[3]
                #                model_id = child.data[4]
                #                config_id = child.data[5]
                #                config_meta = child.data[6]
                #                proc_meta = child.data[7]
                #                model_name = child.data[8]
                #                proc_type_code = child.data[9]
                # Make Proto buf Message
                hdr.router_id = child.identifier
                hdr.proc_id = proc_id
                hdr.status_id = util.ProcStatus.PS_WAITING
                hdr.model_params = model_params
                header = hdr.SerializeToString()
                LOGGER.debug('NEXT FLOW info : {0}'.format(hdr))
                if 'HMD' in proc_name:
                    proc_name = 'HMD'
                backend_map[proc_name].send_multipart([header, body])
                util.insert_proc_result(oracle, LOGGER, hdr)
                LOGGER.debug('Sent message to worker')
        elif socks.get(cli_socket) == zmq.POLLIN:
            cmd = cli_socket.recv()
            LOGGER.info('Get cmd : {0}'.format(cmd))
            if cmd == 'reload':
                pipeline_info = util.create_pipeline_info()
                tree_map = pipeline_info['tree']
                cli_socket.send('success')
            else:
                LOGGER.error('Invalid Command')
                cli_socket.send('failed')
        oracle.disconnect()
コード例 #8
0
 def do_work(self, frames):
     header, body = frames
     hdr = common_pb2.Header()
     hdr.ParseFromString(header)
     nlp_result = nlp_pb2.nlpResultDetail()
     nlp_result.ParseFromString(body)
     self.log(logging.INFO, "Message (pipeline_event_id:{0}) received".format(hdr.pipeline_event_id))
     client = dnn_client.ClassifierClient(self.dnn_addr)
     oracle = db_connection.Oracle()
     try:
         hdr.status_id = util.ProcStatus.PS_INPROGRESS
         util.insert_proc_result(oracle, self.logger, hdr)
         img_name, img_lang = hdr.model_params.split('-')
         if client.get_server(img_name, img_lang):
             detect_cnt = 0
             call_date = '' if hdr.call_metadata.call_date == 'None' else hdr.call_metadata.call_date
             for document in nlp_result.documentList:
                 nlp_id = document.nlp_result_id
                 nlp_result = document.sentence
                 summary = client.get_class(nlp_result)
                 summary.c1_top = summary.c1_top.replace("'", "\'")
                 if summary.c1_top == 'voc':
                     detect_cnt += 1
                 self.log(logging.DEBUG, "NLP_ID[{0}] DNN result is {1}".format(nlp_id, summary.c1_top))
             dnn_classify_code = 'voc' if detect_cnt > 0 else 'normal'
             query = """
                 INSERT INTO TA_DNN_RESULT_TB
                 (
                     CALL_DATE,
                     CALL_ID,
                     SPEAKER_CODE,
                     DNN_CLASSIFY_CODE,
                     DETECT_CNT,
                     CREATED_DTM,
                     UPDATED_DTM,
                     CREATOR_ID,
                     UPDATOR_ID
                 )
                 VALUES
                 (
                     TO_DATE(:1, 'YYYY/MM/DD'),
                     :2, :3, :4, :5, SYSDATE,
                     SYSDATE, :6, :7
                 )
             """
             bind = (
                 call_date,
                 hdr.call_id,
                 hdr.call_metadata.speaker_code,
                 dnn_classify_code,
                 detect_cnt,
                 hdr.creator_id,
                 hdr.creator_id,
             )
             oracle.cursor.execute(query, bind)
             oracle.conn.commit()
             hdr.status_id = util.ProcStatus.PS_COMPLETED
             util.insert_proc_result(oracle, self.logger, hdr)
         else:
             self.log(logging.ERROR, "Classifier Service unavailable")
             hdr.status_id = util.ProcStatus.PS_FAILED
             util.insert_proc_result(oracle, self.logger, hdr)
         oracle.disconnect()
     except grpc.RpcError as e:
         hdr.status_id = util.ProcStatus.PS_FAILED
         util.insert_proc_result(oracle, self.logger, hdr)
         self.log(logging.ERROR, e)
     except Exception:
         hdr.status_id = util.ProcStatus.PS_FAILED
         util.insert_proc_result(oracle, self.logger, hdr)
         self.log(logging.ERROR, traceback.format_exc())
コード例 #9
0
 def create_common_header(self, **kwargs):
     try:
         meta_info = kwargs.get('meta_info')
         cntc_user_info = kwargs.get('cntc_user_info')
         header = common_pb2.Header()
         header.ticket_id = kwargs.get('ticket_id')
         header.call_id = kwargs.get('call_id')
         header.pipeline_id = kwargs.get('pipeline_id')
         header.pipeline_event_id = kwargs.get('pipeline_event_id')
         header.router_id = kwargs.get('router_id')
         header.proc_id = kwargs.get('proc_id')
         header.status_id = util.ProcStatus.PS_COMPLETED
         header.creator_id = CREATOR_ID
         header.call_metadata.call_date = meta_info[0].strftime(
             '%Y-%m-%d') if meta_info[0] else 'None'
         header.call_metadata.project_code = meta_info[1]
         header.call_metadata.file_name = meta_info[2]
         header.call_metadata.call_type_code = meta_info[3]
         header.call_metadata.record_key = meta_info[4] if meta_info[
             4] else 'None'
         header.call_metadata.start_time = str(meta_info[5])
         header.call_metadata.end_time = str(meta_info[6])
         header.call_metadata.duration = meta_info[7]
         header.call_metadata.ruser_id = meta_info[8] if meta_info[
             8] else 'None'
         header.call_metadata.ruser_name = meta_info[9] if meta_info[
             9] else 'None'
         header.call_metadata.mktn_id = str(
             meta_info[10]) if meta_info[10] else 'None'
         header.call_metadata.org_c = str(
             meta_info[11]) if meta_info[11] else 'None'
         header.call_metadata.list_id = str(
             meta_info[12]) if meta_info[12] else 'None'
         header.call_metadata.cu_id = str(
             meta_info[13]) if meta_info[13] else 'None'
         header.call_metadata.cu_name = meta_info[14] if meta_info[
             14] else 'None'
         header.call_metadata.poly_no = meta_info[15] if meta_info[
             15] else 'None'
         header.call_metadata.cont_date = meta_info[16] if meta_info[
             16] else 'None'
         header.call_metadata.speaker_code = kwargs.get('speaker_code')
         header.call_metadata.cntc_user_depart_c = cntc_user_info[
             0] if cntc_user_info[0] else 'None'
         header.call_metadata.cntc_user_depart_nm = cntc_user_info[
             1] if cntc_user_info[1] else 'None'
         header.call_metadata.cntc_user_part_c = cntc_user_info[
             2] if cntc_user_info[2] else 'None'
         header.call_metadata.cntc_user_part_nm = cntc_user_info[
             3] if cntc_user_info[3] else 'None'
         header.call_metadata.ivr_serv_nm = cntc_user_info[
             4] if cntc_user_info[4] else 'None'
         for cntc_cls_dict in kwargs.get('cntc_cls_double_dict').values():
             header.cntc_cls_list.add(
                 cntc_lcls_c=cntc_cls_dict['cntc_lcls_c'],
                 cntc_lcls_nm=cntc_cls_dict['cntc_lcls_nm'],
                 cntc_md_clas_c=cntc_cls_dict['cntc_md_clas_c'],
                 cntc_md_clas_nm=cntc_cls_dict['cntc_md_clas_nm'])
         return header
     except Exception:
         self.logger.error(traceback.format_exc())
         raise Exception(traceback.format_exc())
コード例 #10
0
ファイル: dnn_proc.py プロジェクト: wnghks4745/MindsLAB
 def do_work(self, frames):
     header, body = frames
     hdr = common_pb2.Header()
     hdr.ParseFromString(header)
     nlp_result = nlp_pb2.nlpResultDetail()
     nlp_result.ParseFromString(body)
     self.log(logging.INFO, "Message (pipeline_event_id:{0}) received".format(hdr.pipeline_event_id))
     client = dnn_client.ClassifierClient(self.dnn_addr)
     oracle = db_connection.Oracle()
     try:
         hdr.status_id = util.ProcStatus.PS_INPROGRESS
         util.insert_proc_result(oracle, self.logger, hdr)
         img_name, img_lang = hdr.model_params.split('-')
         if client.get_server(img_name, img_lang):
             for document in nlp_result.documentList:
                 nlp_id = document.nlp_result_id
                 nlp_result = document.sentence
                 summary = client.get_class(nlp_result)
                 summary.c1_top = summary.c1_top.replace("'", "\'")
                 query = """
                 INSERT INTO TA_DNN_RESULT_TB
                 (
                     NLP_RESULT_ID,
                     DNN_CLASSIFY_CODE,
                     PROBABILITY,
                     CREATED_DTM,
                     UPDATED_DTM,
                     CREATOR_ID,
                     UPDATOR_ID
                 )
                 VALUES
                 (
                     :1, :2, :3,
                     SYSDATE, SYSDATE,
                     :4, :5
                 )
                 """
                 bind = (
                     nlp_id,
                     summary.c1_top,
                     summary.probability_top,
                     hdr.creator_id,
                     hdr.creator_id,
                 )
                 oracle.cursor.execute(query, bind)
                 oracle.conn.commit()
                 self.log(logging.DEBUG, "DNN result is {0}".format(summary))
                 hdr.status_id = util.ProcStatus.PS_COMPLETED
                 util.insert_proc_result(oracle, self.logger, hdr)
         else:
             self.log(logging.ERROR, "Classifier Service unavailable")
             hdr.status_id = util.ProcStatus.PS_FAILED
             util.insert_proc_result(oracle, self.logger, hdr)
         oracle.disconnect()
     except grpc.RpcError as e:
         hdr.status_id = util.ProcStatus.PS_FAILED
         util.insert_proc_result(oracle, self.logger, hdr)
         self.log(logging.ERROR, e)
     except Exception:
         hdr.status_id = util.ProcStatus.PS_FAILED
         util.insert_proc_result(oracle, self.logger, hdr)
         self.log(logging.ERROR, traceback.format_exc())