# -*- 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. 不会点git真不行啊.

    基本使用: // 进入项目根目录, git init // 接管你的项目文件夹, git status // 查看状态. 绿色已接管,红色未管理 git add . // 添加管理当前目录所有文件及子 ...

  2. [模板] 无旋Treap (C++ class)

    注意!本帖不是算法介绍!只是贴代码(逃) //嫌stdlib的rand太慢,手打了一个 /* Author: hotwords */ typedef unsigned int tkey; class ...

  3. .NET并行计算和并发11:并发接口 IProducerConsumerCollection

    using System; using System.Collections; using System.Collections.Generic; using System.Collections.C ...

  4. 解决 error: Your local changes to the following files would be overwritten by merge:XXXX

    版权声明:这可是本菇凉辛辛苦苦原创的,转载请记得带上我家地址,不要忘记了哈 ... https://blog.csdn.net/u011314442/article/details/78852547 ...

  5. python学习第四次笔记

    python学习第四次记录 列表list 列表可以存储不同数据类型,而且可以存储大量数据,python的限制是 536870912 个元素,64位python的限制是 1152921504606846 ...

  6. PAT—优化Java从控制台读取信息的速度

    PAT对Scanner类很不友好,会花费大量时间,导致运行时间超时.可采用下列代码优化时间 BufferedReader bf = new BufferedReader(new InputStream ...

  7. Vue组件中的问题

    错误信息: 提示信息含义:组件模板中只能包含一个根元素 解决办法:在模板元素内部增加块级元素div将这些元素标签包裹起来,如图所示

  8. String与Integer问题

    今天分享一下关于最近面试的问题,临近春节,而我在茫茫人海中奔波,今天面试了来到了中关村科技园,挺气派的,之前也是在外面看看,今天就去了,心里有点激动,恰好,正好赶上了上班时,看见它们的努力,我感到再累 ...

  9. python从零开始 -- 第0篇之Hello World!

    为什么选择python以及版本选择 学习资料 学习方法和路径 1. 为什么选择python以及版本选择: Python  好玩,强大,更多关于关于为什么选择Python,在  编程小白的第一本 Pyt ...

  10. Sublime 黑科技之——lorem快速输入

    需要一段文字填充某块演示的空间,但不管写什么文字都觉得不合适,那么这个黑科技你值的拥有. 在Sublime Text中,输入lorem,再按Tab键,即可快速输入一段无意义的占位字符: Lorem i ...