tlog日志按渠道划分
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#!/usr/bin/env python # _*_ encoding: utf-8 _*_ # import sys #python3.0 #tlog日志分隔 #augustyang 2018-07-29 tlog = 'tlog.log' tapap_openid='taptap.txt' #taptap的openid tlog_name= sys.argv[1] #先游 tlog_name1= sys.argv[2] #taptap # tlog_name= 'xianyou.tlog' #先游 # tlog_name1= 'taptap.tlog' #taptap def taptap(): #tap的openid取出 open_list = [] with open(tapap_openid,'r+')as f: for i in f: open_list.append(i.strip()) return (open_list) def outer_qudao(): #取出其他渠道的openid outher_openid = [] with open(tlog,encoding='utf-8')as f: for i in f: vopenid = i.split('|')[6] outher_openid.append(vopenid) #所有的openid outher_openid = list(set(outher_openid)) diff_openid1 = list(set(outher_openid)^set(taptap())) #求出差异的openid return diff_openid1 def check_tlog(file_name,qudao): #找出对应渠道的日志文件 with open(file_name,'w+',encoding='utf-8') as ff: for openid in qudao(): with open(tlog, encoding='utf-8')as f: for i in f: vopenid = i.split('|')[6] if openid == vopenid: ff.write(i) if __name__ == "__main__": check_tlog(tlog_name1,taptap) #taptap check_tlog(tlog_name,outer_qudao) #先游
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#!/usr/bin/env python # _*_ encoding: utf-8 _*_ import sys tlog = 'tlog.log' tapap_openid='taptap.txt' tlog_name= sys.argv[1] #先游 tlog_name1= sys.argv[2] #taptap #file_name 先游 #file_name1 taptap #python2.6 # # def taptap(): #tap的openid open_list = [] with open(tapap_openid,'r+')as f: for i in f: open_list.append(i.strip()) return (open_list) def outer_qudao(): #取出其他渠道的openid outher_openid = [] with open(tlog)as f: for i in f: vopenid = i.split('|')[6] outher_openid.append(vopenid) #所有的openid outher_openid = list(set(outher_openid)) diff_openid1 = list(set(outher_openid)^set(taptap())) #求出差异的openid return diff_openid1 def check_tlog(file_name,qudao): #找出渠道的日志文件 with open(file_name,'w+') as ff: for openid in qudao(): with open(tlog)as f: for i in f: vopenid = i.split('|')[6] if openid == vopenid: ff.write(i) if __name__ == "__main__": check_tlog(tlog_name1,taptap) #taptap check_tlog(tlog_name,outer_qudao) #先游
注册用户
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#!/usr/bin/env python # _*_ encoding: utf-8 _*_ import sys,os,time,datetime begin_time = sys.argv[1] end_time = sys.argv[2] tlog = 'tlog.log' create_time = str(datetime.datetime.strptime("2018-07-12 12:00:00",'%Y-%m-%d %H:%M:%S')) #开服时间 # 注册用户的openid去重列表 def PlayerRegister_vopenid_list(): result = [] with open(tlog, 'r') as f: for i in f: if i.startswith("PlayerRegister"): dtEventTime = i.split('|')[2] #注册时间 vopenid = i.split('|')[6] if begin_time <= dtEventTime <= end_time: result.append(vopenid + '\n') return list(set(result)) if __name__ == "__main__": print('从'+begin_time+'到'+end_time+'时间内注册的用户数为:',len(PlayerRegister_vopenid_list()))
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#!/usr/bin/env python # _*_ encoding: utf-8 _*_ import sys,os,time,datetime tlog= sys.argv[1] begin_time = sys.argv[2] end_time = sys.argv[3] create_time = str(datetime.datetime.strptime("2018-08-16 12:00:00",'%Y-%m-%d %H:%M:%S')) #开服时间 # 注册用户的openid去重列表 def PlayerRegister_vopenid_list(): result = [] with open(tlog, 'r') as f: for i in f: if i.startswith("PlayerRegister"): dtEventTime = i.split('|')[2] #注册时间 vopenid = i.split('|')[6] if begin_time <= dtEventTime <= end_time: result.append(vopenid) return list(set(result)) if __name__ == "__main__": print '从'+begin_time+'到'+end_time+'时间内注册的用户数为:',len(PlayerRegister_vopenid_list())
留存
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#!/usr/bin/env python # _*_ encoding: utf-8 _*_ #augustyang 2018-07-29 #========================================= import sys,os,time,datetime from PlayerRegister_add import PlayerRegister_vopenid_list #导入规定时间内注册的用户list register_begin_time = sys.argv[1] #注册开始时间 register_end_time = sys.argv[2] #注册结束时间 login_time = sys.argv[3] #登录开始时间 logout_time = sys.argv[4] #登录结束时间 tlog = 'tlog.log' #PlayerLogin(登录) PlayerLogout(登出) ReturnFlow(后台反回上报登录信息) #========================================= #规定时间内用户的操作(方法) def User_operation (x,f): result = [] for i in f: if i.startswith(x): dtEventTime = i.split('|')[2] #登录时间 vopenid = i.split('|')[6] if login_time <= dtEventTime <= logout_time: result.append(vopenid + '\n') return list(set(result)) #返回用户列表 #某个时间段内所有登录,登出,returnflow,的openid去重_list def sum_login_openid_list(): with open(tlog,'r')as fn: login_openid_list = [] login_openid_list.extend(User_operation('PlayerLogin',fn)) login_openid_list.extend(User_operation('PlayerLogout',fn)) login_openid_list.extend(User_operation('ReturnFlow',fn)) login_openid_list = list(set(login_openid_list)) return login_openid_list #返回某个时间段内所有的用户列表(去重后的结果) if __name__ == "__main__": #留存用户数 def liucun_user(): #PlayerRegister_vopenid_list()注册用户list msg5 = [line for line in sum_login_openid_list() if line in PlayerRegister_vopenid_list()] return len(msg5) #注册用户数 registerenumbers = len(PlayerRegister_vopenid_list()) print(('从'+register_begin_time+'到'+register_end_time+'注册用户数:'),registerenumbers) print('留存用户数:',liucun_user()) if liucun_user() == 0 or registerenumbers == 0: print('留存没有数据') else: print('留存率:',"%.2f%%" %(float(liucun_user())/float(registerenumbers)*100))
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#!/usr/bin/env python # _*_ encoding: utf-8 _*_ #augustyang 2018-07-29 #python2.6 #========================================= import sys,os,time,datetime from PlayerRegister_add import PlayerRegister_vopenid_list #导入规定时间内注册的用户list tlog= sys.argv[1] register_begin_time = sys.argv[2] #注册开始时间 register_end_time = sys.argv[3] #注册结束时间 login_time = sys.argv[4] #登录开始时间 logout_time = sys.argv[5] #登录结束时间 #PlayerLogin(登录) PlayerLogout(登出) ReturnFlow(后台反回上报登录信息) #========================================= #规定时间内用户的操作(方法) def User_operation (x,f): result = [] for i in f: if i.startswith(x): dtEventTime = i.split('|')[2] #登录时间 vopenid = i.split('|')[6] if login_time <= dtEventTime <= logout_time: result.append(vopenid) return list(set(result)) #返回用户列表 #某个时间段内所有登录,登出,returnflow,的openid去重_list def sum_login_openid_list(): with open(tlog,'r')as fn: login_openid_list = [] login_openid_list.extend(User_operation('PlayerLogin',fn)) login_openid_list.extend(User_operation('PlayerLogout',fn)) login_openid_list.extend(User_operation('ReturnFlow',fn)) login_openid_list = list(set(login_openid_list)) return login_openid_list #返回某个时间段内所有的用户列表(去重后的结果) if __name__ == "__main__": #留存用户数 def liucun_user(): #PlayerRegister_vopenid_list()注册用户list msg5 = [line for line in sum_login_openid_list() if line in PlayerRegister_vopenid_list()] return len(msg5) #注册用户数 registerenumbers = len(PlayerRegister_vopenid_list()) print ('从'+register_begin_time+'到'+register_end_time+'注册用户数:'),registerenumbers print '留存用户数:',liucun_user() if liucun_user() == 0 or registerenumbers == 0: print '留存没有数据' else: print '留存率:',"%.2f%%" %(float(liucun_user())/float(registerenumbers)*100)