因为要丛UE文档中过滤关键字来统计解码时间,第一次自己完成了一个自动化统计的小工具,用起来颇有成就感。
UE文件的内如如下:
需要丛这份关键字中过滤红色标记的两个关键字,取 一个关键字的最后一位,和取一个关键字的最后3位,然后在excel表格中记录,并将值转为十进制
代码实现如下,虽然代码没那么简洁,但是功能是实现了
#coding :utf-8
#_author_=del
import os,sys
import re
import csv
import random
#import xlsxwriter
import xlwt
fdir = "E:/内部项目文档/2G扫码/多轴联动/亮度100%vivo/s002 29cm.trc" #文件路径
f1 = open(fdir,'r',errors='ignore')
keywordA ="number"
keywordB ="80800"
decoderesult = []
decodetime = []
data1=f1.readlines() #一次读取所有内容并按行返回列表
f1.close()
f2 = open('decode.txt', 'w')
f2s = open('result.txt','w')
f3 = open('time.txt','w')
f3s = open('decodetiem.txt','w')
# workbook = xlsxwriter.Workbook('解码时间.xls')
# worksheet = workbook.add_chartsheet('sheet1')
writebook = xlwt.Workbook()
sheet = writebook.add_sheet('sheet1')
headings = ['第N帧识别到','识读时间','识读时间(ms)'] #设置表头
for line in data1:
if keywordA in line:
# numlist = line.split('\t')
print(line)
f2.write(line+'\n')
f2s.write(line[-2:-1]+'\n')
decoderesult.append(int(line[-2:-1]))
f2.close()
f2s.close()
# print(decoderesult)
# for x in range(len(decoderesult)):---#列出 decoderusult数据的内容
# print(decoderesult[x])
# x+1
for line in data1:
if keywordB in line:
print(line)
if line[-4:-1] !='000'and line[-4:-1] !='001':
f3.write(line+'\n')
f3s.write(line[-4:-1]+'\n')
decodetime.append((line[-4:-1]))
f3.close()
f3s.close()
# print(decodetime)
# for y in range(len(decodetime)):
# print(decodetime[y])
# y+1
print(decoderesult)
print(decodetime)
print(len(decodetime),len(decoderesult))
if len(decoderesult)==len(decodetime):
i = 0 # 行
j = 0 #列
count = 0 #计数
for value in range(len(headings)):
sheet.write(i, j + value, headings[value]) # 写入excel,i行j+value列
i = 1
j = 0
skip = 0 #跳过的行
for v in range(len(decoderesult)): #遍历decoderesult数组
if decoderesult[v] == 1:
if count ==0:
sheet.write(i+v-skip,j+0,1)
else:
sheet.write(i+v-skip,j+0,count+1)
print(decodetime[v])
sheet.write(i+v-skip,j+1,decodetime[v])
sheet.write(i+v-skip,j+2,int(decodetime[v], 16))
count = 0
else:
count += 1
skip +=1
else:
print("解码次数和时间次数不匹配")
writebook.save('解码时间.xls')