def notify_end(self, *o): logger.info('com:{0} start to receive log of the cmd: {1}'.format( self.com_device, o[0].content)) try: self.tmp_data = [format_time(), self.com_device, o[0]] start = int(round(time.time() * 1000)) lines = [ line.decode(encoding='utf-8').strip('\r\n\t') for line in self.serial_com.readlines() ] self.ave_t.append(int(round(time.time() * 1000)) - start) for line in lines: if line is None or line == '': continue logger.info('com:{0} receive info:{1}'.format( self.com_device, line)) if not corpus_conf.log_filter.need_filter(line): self.tmp_data.append(line) except Exception as e: logger.info('com:{0} failed to read log, err: {1}, {2}'.format( self.com_device, e, traceback.format_exc())) self.serial_com = serial.Serial(port=self.com_device, baudrate=115200, timeout=.01) self.notify_end(*o) logger.info('com:{0} receive info cost:{1}'.format( self.com_device, int(sum(self.ave_t) / len(self.ave_t)))) aq.send(self.tmp_data)
def write_default_log_2_csv(service): """ :type service: audio_identify.identify.AudioIdentify """ while service.can_write: for com, com_result_d in result_map.items(): if len(com_result_d) == 0: continue file_name = '{0}_{1}_{2}.csv'.format( corpus_conf.log_name_by_serial.get(com), corpus_conf.wav_count_one_cmder, format_time(parse_time(corpus_conf.start_time, format_2), format_3)) try: with open(os.path.join(corpus_conf.output_path, file_name), 'w+', encoding='utf-8') as wf: cmds_result = [v for _, v in dict(com_result_d).items()] row_format = write_csv_header(cmds_result, wf) for cmd_result in cmds_result: write_one_cmd_log(cmd_result, row_format, wf) except Exception as e: logger.error('Failed to write test result, err: %s, %s' % (e, traceback.format_exc())) sleep(10) else: logger.info('write csv thread finish...')
def output_wav_text(self): new_wav_mapping = LoadSource().parse_wav( get_wav_path(), corpus_conf.wav_count_one_cmder) for k, v in new_wav_mapping.items(): old_v = self.wav_mapping.get(k) if old_v is not None: if len(old_v) >= corpus_conf.wav_count_one_cmder: new_wav_mapping[k] = old_v[:corpus_conf. wav_count_one_cmder] else: new_wav_mapping[k] = old_v + v[:( corpus_conf.wav_count_one_cmder - len(old_v))] self.wav_mapping = new_wav_mapping file_name = '{0}_{1}_{2}.json'.format( corpus_conf.product, format_time(time_formatter="%y%m%d"), corpus_conf.wav_count_one_cmder) with codecs.open(os.path.join(corpus_conf.output_path, file_name), 'w+', encoding='utf-8') as wf: json.dump(self.wav_mapping, wf, cls=DefaultDecoder, indent=4, ensure_ascii=False) logger.info('export end, file name:{0}'.format(file_name))
def __init__(self, com_device): super().__init__() self.__start = True self.com_device = com_device self.thread_name = '{0}:{1}'.format('collector', self.com_device) self.serial_com = serial.Serial(port=self.com_device, baudrate=115200, timeout=.01) self.tmp_data = [format_time(), self.com_device] self.lock = threading.Lock() self.ave_t = []
def __init__(self): # 无上限为max, 无下限为min self.svm_list = [] self.likelihood_list = [] self.confidence_list = [] self.remote_host = r'' self.remote_port = 22 self.remote_username = '' self.remote_password = '' self.remote_base = r'' self.remote_result_dir = r'' self.cmd_path = r'' self.wav_path = r'' self.wav_schema = [] self.wav_load_mode = 1 self.retrieve_script = '' self.wav_count_one_cmder = 1 self.play_mode = 1 self.repeat_play_count = 1 self.amplify_volume = True self.play_separator = 2 # 语音播报间隔 self.first_read = '' self.log_filter = LogFilter() # 过滤掉包含关键字的日志 self.soft_root = os.path.join(os.path.dirname(__file__), '..', '..') self.output_path = os.path.join(self.soft_root, 'output') self.temp_path = os.path.join(self.soft_root, 'temp') if not os.path.exists(self.temp_path): os.mkdir(self.temp_path) if not os.path.exists(self.output_path): os.mkdir(self.output_path) self.log_name_by_serial = {} self.product = '' self.start_time = format_time(time_formatter=format_2)
if __name__ == '__main__': """ 手动分析日志生成csv结果 """ log_path = r'C:\Users\Administrator\Desktop\bstd_result\bslight_191220_test_log.log' class Service: def __init__(self): self.can_write = True corpus_conf.load_conf() s = Service() threading.Thread(target=write_default_log_2_csv, args=(s, ), daemon=True).start() with open(log_path, 'r', encoding='utf-8') as rf: for line in rf: re_str = r'cmd_info: (.*):(.*) -> log: (.*)' rst = re.match(re_str, line) if rst is not None: play_cmd = rst.group(1) wav_name = rst.group(2) log_info = rst.group(3) obj = AudioObj().set_v(wav_name, play_cmd, '') logs = [log.strip() for log in log_info.split('&&')] msg = [format_time(), 'COM12', obj, *logs] parse_default_log(msg) sleep(15) s.can_write = False
def on_notify(self, *o): with self.lock: self.tmp_data.insert(2, o[0]) aq.send(self.tmp_data) self.tmp_data = [format_time(), self.com_device]