python打卡记录去重_python根据uuid去重,获取请求重各种动作的次数

#!/usr/bin/python

# -*- coding: utf-8 -*-

#RUN     // 程序启动

#EXIT    // 程序退出

#START   // 热点启动

#STOP    // 热点停止

#ONL     // 客户端上线

#OFFL    // 客户端下线

#INSTALL //安装

#UNINSTALL //卸载

import re

#模式匹配UUID

patternUid=re.compile(r'(\w){8}-(\w){4}-(\w){4}-(\w){4}-(\w){12}')

#定义Uid字典,用来排重

uid={}

#用来统计各种动作的次数

actionCount={

"a=RUN":0,

"a=EXIT":0,

"a=START":0,

"a=STOP":0,

"a=ONL":0,

"a=OFFL":0,

"a=INSTALL":0,

"a=UNINSTALL":0

}

for k,v in actionCount.iteritems():

with open("C:/Users/Administrator/Desktop/python/result.txt") as f:

for line in f:

if patternUid.search(line):

uidName=patternUid.search(line).group()

if k in line:

if uid.has_key(uidName):

pass

else:

uid[uidName]=1

actionCount[k]+=1

uid.clear()

for k,v in actionCount.iteritems():

print k ,actionCount[k]

----------------------------------

结果时间:

C:\Python27\python.exe C:/Users/Administrator/Desktop/python/test3.py

a=EXIT 42

a=START 404

a=INSTALL 0

a=STOP 228

a=UNINSTALL 0

a=RUN 45

a=ONL 274

a=OFFL 229

total time is : 2.03400015831

优化方法二#!/usr/bin/python

# -*- coding: utf-8 -*-

#RUN     // 程序启动

#EXIT    // 程序退出

#START   // 热点启动

#STOP    // 热点停止

#ONL     // 客户端上线

#OFFL    // 客户端下线

#INSTALL //安装

#UNINSTALL //卸载

import re

import time

import sys

start_time=time.time()

#模式匹配UUID

patternUid=re.compile(r'(\w){8}-(\w){4}-(\w){4}-(\w){4}-(\w){12}')

#定义时间

yesterday=time.strftime('%Y-%m-%d',time.localtime(time.time()-24*60*60))

#定义Uid字典,用来排重

uid={}

actionCount={

"a=RUN":0,

"a=EXIT":0,

"a=START":0,

"a=STOP":0,

"a=ONL":0,

"a=OFFL":0,

"a=INSTALL":0,

"a=UNINSTALL":0,

"a=AUTORUN":0

}

with open("C:/Users/Administrator/Desktop/python/28.log") as f:

for line in f:

if patternUid.search(line):

uidName=patternUid.search(line).group()

for k,v in actionCount.iteritems():

if k in line:

if uid.has_key(uidName+k):

uid[uidName+k]+=1

else:

uid[uidName+k]=1

actionCount[k]+=1

for k,v in actionCount.iteritems():

print k,v

end_time=time.time()

print "total time is:",end_time-start_time

---------------------------------

结果时间:

C:\Python27\python.exe C:/Users/Administrator/Desktop/python/test4.py

a=EXIT 42

a=START 404

a=INSTALL 0

a=AUTORUN 236

a=STOP 228

a=UNINSTALL 0

a=RUN 45

a=ONL 274

a=OFFL 229

total time is: 0.287000179291

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值