# -*- coding: utf-8-*- #
import sys
import os
import io
import json
reload(sys)
sys.setdefaultencoding('utf-8') def unicode_convert(input):
if isinstance(input, dict):
return {unicode_convert(key): unicode_convert(value) for key, value in input.iteritems()}
elif isinstance(input, list):
return [unicode_convert(element) for element in input]
elif isinstance(input, unicode):
return input.encode('utf-8')
else:
return input filter=["Dm.log.wf"] #设置过滤后的文件类型 当然可以设置多个类型 def all_path(dirname): result = []#所有的文件 for maindir, subdir, file_name_list in os.walk(dirname): # print("1:",maindir) #当前主目录
# print("2:",subdir) #当前主目录下的所有目录
# print("3:",file_name_list) #当前主目录下的所有文件 for filename in file_name_list:
apath = os.path.join(maindir, filename)#合并成一个完整路径
ext = os.path.splitext(apath)[0] # 获取文件后缀 [0]获取的是除了文件名以外的内容
ext = ext.split('/')
ext = ext[5] if ext in filter:
result.append(apath) return result if __name__ == "__main__":
print sys.getdefaultencoding()
result = all_path("/home/work/yangq/dm_analysis")
for file_log in result:
print "*****************************************"
print file_log
f = open(file_log, "r")
f_new = open("/home/work/yangq/dm_analysis/result", "a+")
f_new_error = open("/home/work/yangq/dm_analysis/error", "a+")
haproxy_list = f.readlines()
dm_statistics="dm_statistics"
f_new.write(file_log + "\n")
f_new.write("###################################################################" + "\n")
f_new_error.write(file_log + "\n")
f_new_error.write("###################################################################" + "\n")
for line in haproxy_list:
if dm_statistics in line:
#print sys._getframe().f_lineno
#print line
strlist = line.split('dm_statistics: ')
sss = strlist[1]
#test2 = unicode_convert(json.loads(sss))
try:
test2 = json.loads(sss.decode('utf-8'))
except UnicodeDecodeError as w:
f_new_error.write(line)
f_new_error.write("有特殊自符" + "\n")
continue
except ValueError:
f_new_error.write(line)
f_new_error.write("ValueError" + "\n")
continue f_new.write("query:" + str(test2['req']['query']) + " ")
if 'recommend_word' in test2['latency']:
f_new.write("recommend_word:" + str(test2['latency']['recommend_word']) + " ")
if 'um' in test2['latency']:
f_new.write("um:" + str(test2['latency']['um']) + " ")
if 'se' in test2['latency']:
f_new.write("se:" + str(test2['latency']['se']) + " ")
if 'ia' in test2['latency']:
f_new.write("ia:" + str(test2['latency']['ia']) + " ")
if 'ir' in test2['latency']:
f_new.write("ir:" + str(test2['latency']['ir']) + " ")
if 'dm' in test2['latency']:
f_new.write("dm:" + str(test2['latency']['dm']) + " ")
if 'chat' in test2['latency']:
f_new.write("chat:" + str(test2['latency']['chat']) + " ")
if 'ACTION_CALCULATE.calc' in test2['detail_latency']:
f_new.write("ACTION_CALCULATE.calc: " + str(test2['detail_latency']['nli']['ACTION_CALCULATE.calc']) + "\n")
f_new.write("\n")
#try:
# f_new.write("query:" + str(test2['req']['query']) + " " + \
# "recommend_word:" + str(test2['latency']['recommend_word']) + \
# " " "um:" + str(test2['latency']['um']) + " " + \
# "se:" + str(test2['latency']['se']) + " " + \
# "ia:" + str(test2['latency']['ia']) + " " + \
# "ir:" + str(test2['latency']['ir']) + " " + \
# "dm:" + str(test2['latency']['dm']) + " " + \
# "chat:" + str(test2['latency']['chat']) + " " + \
# "ACTION_CALCULATE.calc: " + str(test2['detail_latency']['nli']['ACTION_CALCULATE.calc']) + "\n")
#except KeyError as e:
# f_new_error.write(line)
# f_new_error.write("losing key:" + str(e) + "\n")
# continue
f.close()
f_new.close()
f_new_error.close()
pass

dm_analysis的更多相关文章

随机推荐

  1. ubuntu安装ssh-service出现无法依赖的解决

    (1)首先先确认下ubuntu系统是否已经安装ssh(通常ubuntu中默认是安装的) 通过命令进行查看:$dpkg -l | grep ssh这里我们可以看到,系统显示已经安装了openssh-cl ...

  2. Open Daylight integration with OpenStack: a tutorial

    Open Daylight integration with OpenStack: a tutorial How to deploy OpenDaylight and integrate it wit ...

  3. Qt设置创建部分半透明,上面控件不透明

    //头文件#pragma once #include <QWidget> #include "ui_widgetFullAD.h" class widgetFullAD ...

  4. python基础一之课后作业:编写登录接口

    1 # Author : Mamba 2 3 #python基础一之课后作业:编写登录接口 4 5 # 输入用户名密码 6 # 认证成功后显示欢迎信息 7 # 用户名3次输入错误后,退出程序 8 # ...

  5. java 基础代码

    /** * Created by y0n on 2017/4/17. * 1.输出控制台传递的默认参数 */public class JavaDay001_1 { public static void ...

  6. DG Switch over

    DG切换迁移Switch over切换文档 本篇文档,整体结构:1.切换前检查确认2.DG切换角色操作3.切换后检查确认 目录:一.切换前检查确认1.数据库版本2.DG架构,IP信息及切换角色前后3. ...

  7. AT24C0X I2C通信原理

    /********************************************************************** * AT24C0X I2C通信原理 * 说明: * 之前 ...

  8. HTML标记语言

    一.html的文档结构 html含义为超文本标记语言,html文档重要由4个标签来组成就是<html>  <head>  <title>  <body> ...

  9. 把一个给定的值存储到一个整数中指定的几个位《C与指针5.8.5》

    编写一个函数,把一个给定的值存储到一个整数中指定的几个位.它的原型如下: int store_bit_field(int original_value, int value_to_store, uns ...

  10. margin外边距属性

    外边距属性: 设置元素与元素之间的距离(外边距),4个方向(上右下左). margin:长度值|百分比|auto margin-top margin-right margin-bottom margi ...