# -*- 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. B-食物链-经典并查集

    动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形.A吃B, B吃C,C吃A. 现有N个动物,以1-N编号.每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种. 有人用两种 ...

  2. MySQL之UNION与UNION ALL

    数据表中的数据如下: UNION: 可以获取books表与articles表中所有不同的title,如果两个表中title相同的只会显示一个.  UNION ALL : 可以获取books表与arti ...

  3. 通过JQuery的$.ajax()把 json 数据 post 给 PHP

    通过JQuery的$.ajax()把 json 数据 post 给 PHP时的几种情况: 无法在PHP中通过$_POST 以及 $_REQUEST 获取json数据,即 $json = $_POST[ ...

  4. js bind绑定事件

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. MATLAB细节笔记

    input函数 input('please input','s') 或者 input('please input').前者不管输入什么都会变成字符串,后者如果输入数字,那么matlab会识别成数字.如 ...

  6. java开发150个建议

    阅读目录 建议1:不要在常量和变量中出现易混淆的字母 建议2:莫让常量蜕变成变量 建议3:三元操作符的类型务必一致 建议4:避免带有变长参数的方法重载 建议5:别让null值和空值威胁到变长方法 建议 ...

  7. window10单机安装storm集群

    适合范围:storm自由开源的分布式实时计算系统,擅长处理海量数据.适合处理实时数据而不是批处理. 安装前的准备 1.安装zookeeper ①下载zookeeperhttps://zookeeper ...

  8. Dart 的function

    方法的定义 返回类型 方法名 (参数1 ,参数2 ,...){ 方法体 返回值 } => 的使用

  9. Measuring Text Difficulty Using Parse-Tree Frequency

    https://nlp.lab.arizona.edu/sites/nlp.lab.arizona.edu/files/Kauchak-Leroy-Hogue-JASIST-2017.pdf In p ...

  10. 关于java中为什么尽量把受检异常转化为非受检异常

    首先理解一下受检异常与非受检异常: 异常表示程序运行过程中可能出现的非正常状态,运行时异常表示虚拟机操作中可能遇到的异常,是一种常见的运行错误,只要程序设计的没有问题通常就不会发生.受检异常与程序的上 ...