iptv
# -*- coding: utf-8 -*-
import datetime, time, json, re, os
#from pwd import getpwnam
#quality
str_quality = ''.join(['{StartTime}|||{SubscriberID}', \
'|'*11, '{Bitrate}|{MOSAvg}|{DF}|{MLR}||||', '{CPUUsageHistogram}|', \
'{ProfilePlayoutSecondsHistogram_M}', '|'*8, '{ProfilePlayoutSecondsHistogram_m}', \
'|'*8, '{PlayDuration_M}|{BadDuration_M}|{PlayDuration_S}|{BadDuration_S}||||', \
'{CurrentPlaySuccNum_CurrentPlayErrNum}|{CurrentPlaySuccNum}', '|'*11, \
'{TVGuideReqNum}|{TVGuideSuccessNum}|{TVGuideDelayAvg}|||||', \
'{StallingCount_S}|{StallingDuration_S}||', \
'{BufferTrack_A}|{BufferTrack_M}|{BufferTrack_m}|||', \
'{RTTTrack_A}|{RTTTrack_M}|{RTTTrack_m}|{LostRatioTrack_A}|{LostRatioTrack_M}|{LostRatioTrack_m}', \
'|'*7, '{RAMUsageHistogram_A}|{RAMUsageHistogram_M}|{RAMUsageHistogram_m}|{DiskUsage}', \
'|'*6, '{DownloadSpeed_A}|{DownloadSpeed_M}|{DownloadSpeed_m}||||', \
'{UpBandWidthHistogram_A}|{UpBandWidthHistogram_M}|{UpBandWidthHistogram_m}|', \
'{DownBandWidthHistogram_A}|{DownBandWidthHistogram_M}|{DownBandWidthHistogram_m}||', \
'{URL}|{ServiceType}|{URL_IP}||||', '{DeviceSupplier}||||\n'])
#behavior
str_behavior = ''.join(['{StartTime}|{SubscriberID}', \
'|'*7, '{ServiceType}', '|'*9, '{PlayDuration_M}', \
'|'*19, '{URL}|{URL_IP}||||\n'])
#CPU, RAM
c_r = [0.1, 0.35, 0.6, 0.75, 0.85, 0.95]
#up
up = [125, 375, 750, 1500, 3000, 5000]
#down, ProfilePlayoutSecondsHistogram
down = [1000, 3500, 7500, 15000, 35000, 60000]
pattern = re.compile(r'http://(\d+.\d+.\d+.\d+)/.*')
#get the log file path
def get_log_path(path):
for fpathe,dirs,fs in os.walk(path):
for f in fs:
if f.endswith('.log'):
return os.path.join(fpathe, f)
def get_his_MIN(lis):
for x in lis:
if x != 0:
return lis.index(x)
return 0
def get_his_MAX(lis):
for x in lis[::-1]:
if x != 0:
return lis.index(x)
return 0
#CPU, RAM, up down
def get_his_AVE_R_C(lis):
s = int(100*(0.1*lis[0]+0.35*lis[1]+0.6*lis[2]+0.75*lis[3]+0.85*lis[4]+0.95*lis[5]))
if sum(lis) != 0:
return int (s/ sum(lis))
else:
return 0
def get_up_AVE(lis):
s = int(125*lis[0]+375*lis[1]+750*lis[2]+1500*lis[3]+3000*lis[4]+5000*lis[5])
if sum(lis) != 0:
return int(s / sum(lis))
else:
return 0
def get_down_AVE(lis):
s = int(1000*lis[0]+3500*lis[1]+7500*lis[2]+15000*lis[3]+35000*lis[4]+60000*lis[5])
if sum(lis) != 0:
return int(s / sum(lis))
else:
return 0 #get max PlayDuration time < 300
def get_max_PlayDuration(lis_b_p):
lis_b_p_ = [x for x in lis_b_p if x[0] < x[1] and x[1] <= 300]
if not lis_b_p_:
return 300
else:
return max(lis_b_p_, key=lambda x:x[0])[1] def get_sum_PlayDuration(lis_p):
lis_p_ = [x for x in lis_p if x <= 300]
if sum(lis_p_) <= 300:
return sum(lis_p_)
return 300
#get the max badduration value,make sure the value is smaller than playduration
def get_max_BadDuration(lis_b_p):
lis_b_p_ = [x for x in lis_b_p if x[0] < x[1] and x[1] <= 300]
if not lis_b_p_:
return 0
else:
return max(lis_b_p_, key=lambda x:x[0])[0] def get_sum_BadDuration(lis_b, sum_p):
lis_b_ = [x for x in lis_b if x <= 300]
if sum(lis_b_) < sum_p:
return sum(lis_b_)
else:
return sum_p #recursively get all the dict of a json line
def get_outcome_iter(dict_):
for key, value in dict_.items():
if isinstance(value, dict):
yield from get_outcome_iter(value)
elif isinstance(value, list):
for v in value:
yield from get_outcome_iter(v)
else:
yield key, value def get_dict_str(json_2_dict):
str_quality_tmp, str_behavior_tmp = str_quality, str_behavior
str_quality_dict = dict(StartTime='', SubscriberID='',
Bitrate='', MOSAvg='', DF='', MLR='', CPUUsageHistogram='',
ProfilePlayoutSecondsHistogram_M='', ProfilePlayoutSecondsHistogram_m='',
PlayDuration_M='', BadDuration_M='', PlayDuration_S='', BadDuration_S='',
CurrentPlaySuccNum_CurrentPlayErrNum='', CurrentPlaySuccNum='',
TVGuideReqNum='', TVGuideSuccessNum='', TVGuideDelayAvg='',
StallingCount_S='', StallingDuration_S='',
BufferTrack_A='', BufferTrack_M='', BufferTrack_m='',
RTTTrack_A='', RTTTrack_M='', RTTTrack_m='',
LostRatioTrack_A='', LostRatioTrack_M='', LostRatioTrack_m='',
RAMUsageHistogram_A='', RAMUsageHistogram_M='', RAMUsageHistogram_m='', DiskUsage='',
DownloadSpeed_A='', DownloadSpeed_M='', DownloadSpeed_m='',
UpBandWidthHistogram_A='', UpBandWidthHistogram_M='', UpBandWidthHistogram_m='',
DownBandWidthHistogram_A='', DownBandWidthHistogram_M='', DownBandWidthHistogram_m='',
URL='', ServiceType='', URL_IP='', DeviceSupplier='') str_behavior_dict = dict(StartTime='', SubscriberID='',ServiceType='',
PlayDuration_M='', URL='', URL_IP='') str_dict_tmp = dict(StartTime=[], SubscriberID=[], Bitrate=[],
MOSAvg=[], DF=[], MLR=[], CPUUsageHistogram=[],
ProfilePlayoutSecondsHistogram=[], PlayDuration=[], BadDuration=[],
CurrentPlaySuccNum=[], CurrentPlayErrNum=[],
TVGuideReqNum=[], TVGuideSuccessNum=[], TVGuideDelayAvg=[],
StallingCount=[], StallingDuration=[],
BufferTrack=[], RTTTrack=[], LostRatioTrack=[], RAMUsageHistogram=[],
DiskUsage=[], DownloadSpeed=[], UpBandWidthHistogram=[], DownBandWidthHistogram=[],
URL=[], ServiceType=[], DeviceSupplier=[]) Histogram_list = ['CPUUsageHistogram', 'RAMUsageHistogram', 'UpBandWidthHistogram',
'ProfilePlayoutSecondsHistogram', 'DownBandWidthHistogram',
'RTTTrack', 'LostRatioTrack', 'BufferTrack'] line_dict = get_outcome_iter(json_2_dict)
for key, value in line_dict:
if value == None or value == '':
continue
if key in Histogram_list:
value = [int(x) for x in value.split(',')]
if key in str_dict_tmp:
str_dict_tmp[key].append(value) if str_dict_tmp['StartTime']:
str_quality_dict['StartTime'] = str_dict_tmp['StartTime'][0]
str_behavior_dict['StartTime'] = str_dict_tmp['StartTime'][0]
if str_dict_tmp['SubscriberID']:
str_quality_dict['SubscriberID'] = str_dict_tmp['SubscriberID'][0]
str_behavior_dict['SubscriberID'] = str_dict_tmp['SubscriberID'][0]
if str_dict_tmp['Bitrate']:
str_quality_dict['Bitrate'] = round(max(str_dict_tmp['Bitrate']) / 1024, 2)
if str_dict_tmp['MOSAvg']:
str_quality_dict['MOSAvg'] = round(str_dict_tmp['MOSAvg'][0] / 10, 1)
if str_dict_tmp['DF']:
str_quality_dict['DF'] = int(str_dict_tmp['DF'][0] / 1000)
if str_dict_tmp['MLR']:
str_quality_dict['MLR'] = round(str_dict_tmp['MLR'][0] / 1000000, 1)
if str_dict_tmp['CPUUsageHistogram']:
str_quality_dict['CPUUsageHistogram'] = get_his_AVE_R_C(str_dict_tmp['CPUUsageHistogram'][0])
if str_dict_tmp['ProfilePlayoutSecondsHistogram']:
str_quality_dict['ProfilePlayoutSecondsHistogram_M'] = \
down[get_his_MAX(str_dict_tmp['ProfilePlayoutSecondsHistogram'][0])]
str_quality_dict['ProfilePlayoutSecondsHistogram_m'] = \
down[get_his_MIN(str_dict_tmp['ProfilePlayoutSecondsHistogram'][0])] if str_dict_tmp['PlayDuration'] and str_dict_tmp['BadDuration']:
lis_b_p = list(zip(str_dict_tmp['BadDuration'], str_dict_tmp['PlayDuration']))
str_quality_dict['PlayDuration_M'] = get_max_PlayDuration(lis_b_p)
str_quality_dict['PlayDuration_S'] = get_sum_PlayDuration(str_dict_tmp['PlayDuration'])
str_behavior_dict['PlayDuration_M'] = str_quality_dict['PlayDuration_M']
str_quality_dict['BadDuration_M'] = get_max_BadDuration(lis_b_p)
str_quality_dict['BadDuration_S'] = \
get_sum_BadDuration(str_dict_tmp['BadDuration'], str_quality_dict['PlayDuration_S']) if str_dict_tmp['CurrentPlaySuccNum'] and str_dict_tmp['CurrentPlayErrNum']:
str_quality_dict['CurrentPlaySuccNum_CurrentPlayErrNum'] = \
str_dict_tmp['CurrentPlaySuccNum'][0] + str_dict_tmp['CurrentPlayErrNum'][0]
str_quality_dict['CurrentPlaySuccNum'] = str_dict_tmp['CurrentPlaySuccNum'][0]
if str_dict_tmp['TVGuideReqNum']:
str_quality_dict['TVGuideReqNum'] = str_dict_tmp['TVGuideReqNum'][0]
if str_dict_tmp['TVGuideSuccessNum']:
str_quality_dict['TVGuideSuccessNum'] = str_dict_tmp['TVGuideSuccessNum'][0]
if str_dict_tmp['TVGuideDelayAvg']:
str_quality_dict['TVGuideDelayAvg'] = str_dict_tmp['TVGuideDelayAvg'][0]
if str_dict_tmp['StallingDuration']:
str_quality_dict['StallingDuration_S'] = sum(str_dict_tmp['StallingDuration'])
if str_dict_tmp['StallingCount']:
str_quality_dict['StallingCount_S'] = sum(str_dict_tmp['StallingCount'])
if str_dict_tmp['BufferTrack']:
str_quality_dict['BufferTrack_A'] = sum(str_dict_tmp['BufferTrack'][0])
str_quality_dict['BufferTrack_M'] = max(str_dict_tmp['BufferTrack'][0])
str_quality_dict['BufferTrack_m'] = min(str_dict_tmp['BufferTrack'][0])
if str_dict_tmp['RTTTrack']:
str_quality_dict['RTTTrack_A'] = sum(str_dict_tmp['RTTTrack'][0])
str_quality_dict['RTTTrack_M'] = max(str_dict_tmp['RTTTrack'][0])
str_quality_dict['RTTTrack_m'] = min(str_dict_tmp['RTTTrack'][0])
if str_dict_tmp['LostRatioTrack']:
str_quality_dict['LostRatioTrack_A'] = \
sum(str_dict_tmp['LostRatioTrack'][0]) / (1000000 * len(str_dict_tmp['LostRatioTrack'][0]))
str_quality_dict['LostRatioTrack_M'] = max(str_dict_tmp['LostRatioTrack'][0]) / 1000000
str_quality_dict['LostRatioTrack_m'] = min(str_dict_tmp['LostRatioTrack'][0]) / 1000000
if str_dict_tmp['RAMUsageHistogram']:
str_quality_dict['RAMUsageHistogram_A'] = get_his_AVE_R_C(str_dict_tmp['RAMUsageHistogram'][0])
str_quality_dict['RAMUsageHistogram_M'] = int(c_r[get_his_MAX(str_dict_tmp['RAMUsageHistogram'][0])] * 100)
str_quality_dict['RAMUsageHistogram_m'] = int(c_r[get_his_MIN(str_dict_tmp['RAMUsageHistogram'][0])] * 100)
if str_dict_tmp['DiskUsage']:
str_quality_dict['DiskUsage'] = str_dict_tmp['DiskUsage'][0]
if str_dict_tmp['DownloadSpeed']:
str_quality_dict['DownloadSpeed_A'] = sum(str_dict_tmp['DownloadSpeed']) / len(str_dict_tmp['DownloadSpeed'])
str_quality_dict['DownloadSpeed_M'] = max(str_dict_tmp['DownloadSpeed'])
str_quality_dict['DownloadSpeed_m'] = min(str_dict_tmp['DownloadSpeed'])
if str_dict_tmp['UpBandWidthHistogram']:
str_quality_dict['UpBandWidthHistogram_A'] = get_up_AVE(str_dict_tmp['UpBandWidthHistogram'][0])
str_quality_dict['UpBandWidthHistogram_M'] = up[get_his_MAX(str_dict_tmp['UpBandWidthHistogram'][0])]
str_quality_dict['UpBandWidthHistogram_m'] = up[get_his_MIN(str_dict_tmp['UpBandWidthHistogram'][0])]
if str_dict_tmp['DownBandWidthHistogram']:
str_quality_dict['DownBandWidthHistogram_A'] = get_down_AVE(str_dict_tmp['DownBandWidthHistogram'][0])
str_quality_dict['DownBandWidthHistogram_M'] = down[get_his_MAX(str_dict_tmp['DownBandWidthHistogram'][0])]
str_quality_dict['DownBandWidthHistogram_m'] = down[get_his_MIN(str_dict_tmp['DownBandWidthHistogram'][0])]
if str_dict_tmp['URL']:
URL_index = str_dict_tmp['PlayDuration'].index(str_quality_dict['PlayDuration_M']) \
if str_quality_dict['PlayDuration_M'] != 300 else 0
str_quality_dict['URL'] = str_dict_tmp['URL'][URL_index]
str_behavior_dict['URL'] = str_quality_dict['URL']
str_quality_dict['URL_IP'] = pattern.search(str_quality_dict['URL']).group(1)
str_behavior_dict['URL_IP'] = str_quality_dict['URL_IP']
if str_dict_tmp['ServiceType']:
if str_dict_tmp['ServiceType'][0] == 'LiveTV':
str_dict_tmp['ServiceType'][0] = 'BTV'
if str_dict_tmp['ServiceType'][0] != 'BTV' and str_dict_tmp['ServiceType'][0] != 'VOD':
str_dict_tmp['ServiceType'][0] = 'PLAYBACK'
str_quality_dict['ServiceType'] = str_dict_tmp['ServiceType'][0]
str_behavior_dict['ServiceType'] = str_quality_dict['ServiceType']
if str_dict_tmp['DeviceSupplier']:
str_quality_dict['DeviceSupplier'] = str_dict_tmp['DeviceSupplier'][0] str_quality_tmp = str_quality_tmp.format(**str_quality_dict)
str_behavior_tmp = str_behavior_tmp.format(**str_behavior_dict)
return str_quality_tmp, str_behavior_tmp def get_outcome_files(path_file_source, path_outcome):
if path_file_source != None:
ftime = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
path_file_outcome = path_outcome + 'isa_stb_quality_' + ftime + '.dat'
with open(path_file_outcome, 'a') as f_quality, \
open(path_file_source, 'r') as f:
for line in f:
if line == '<==SPLIT==>\n':
continue
json_2_dict = json.loads(line)
outcome = get_dict_str(json_2_dict)
f_quality.write(outcome[0])
#appserver_uid = getpwnam('appserver')[2]
#appserver_gid = getpwnam('appserver')[3]
#os.chown(path_file_outcome, appserver_uid, appserver_gid)
#os.remove(path_file_source)#delete log files if __name__ == '__main__':
#path_source = '/home/omc/'#folder contains log file
#path_outcome = '/srv/smartcare/share/data/fbb/src/vcem/xDR'#folder contains dat file
path_source = 'C:\\Users\\l00429182\\Desktop\\'
path_outcome = 'C:\\Users\\l00429182\\Desktop\\'
path_file_source = get_log_path(path_source)#log files that found in 5 mins
print(path_file_source)
get_outcome_files(path_file_source, path_outcome)
iptv的更多相关文章
- IPTV中的EPG前端优化
先看一下IPTV相关情况: l 目前TPTV市场情况 a) 截止今年2月,全国IPTV总用户数达3630.2万,我国移动互联网用户规模接近9亿,人均月接入量近300M,8M宽带达半数,光纤近4成. 图 ...
- IPTV小窗口播放视频 页面焦点无法移动的解决方法
在IPTV高清页面中,小窗口播放视频时,在某些机顶盒上(如高清中兴.高清大亚4904)会出现焦点无法移动现象,即按键无响应.被这个bug困扰了很久,虽然我知道解决方法,但只知其然,不知其所以然.今天做 ...
- 北邮iptv用WindowsMediaplayer打不开的解决的方法
前言:之前我的iptv能够用,可是有次我安装了realplayer,它就偷偷把iptv文件的默认打开方式给篡改了,卸载了 realplayer之后,iptv不能直接用 ...
- ITU-T G.1080 IPTV的体验质量(QoE)要求 (Quality of experience requirements for IPTV services)
IPTV的服务质量(QoE)要求 Quality of experience requirements for IPTV services Summary This Recommendation de ...
- ITU-T G.1081 IPTV性能监测点 (Performance monitoring points for IPTV)
ITU-T 建议书 G.1081 IPTV性能监测点 Performance monitoring points for IPTV Summary Successful deployment of I ...
- 移动iptv安装三方软件
1.思路: 分为硬件和软件. a.硬件是ttl直接上串口,弄得比较复杂,且容易损坏盒子,先不考虑 b.软件:抓包获取iptv的请求数据,将移动光猫的iptv出口接到交换机上,电脑和盒子接入到同一个交 ...
- 华为4K机顶盒EC6108V9U从原联通更换为电信的IPTV账号成功经验
4K设备直接在淘宝上买30块钱升级4K机顶盒,i视视手机app控制电视和手机投屏 硬件设备:EC6108V9U由X省联通更换为四川电信 采坑经验: 1.要从现有的机顶盒获取mac地址.stbid.ip ...
- 中兴iptv机顶盒破解教程图文:亲测中兴B760EV3、B860A、B860AV1.1完美安装应用!非ttl破解![转]
一直以为中兴的这几个盒子只能通过ttl来破解,不过现在再也不用这么麻烦了,有了这个工具,前后破解不超3分钟!理论上支持所有中兴的iptv机顶盒的破解! 亲测中兴B760EV3.B860A.B860AV ...
- 用EasyDarwin进行IPTV rtsp mpeg-ts smil流的转发和分发直播服务
对RTSP/RTP的转发和分发一直都是EasyDarwin的基础功能,尤其是在安防行业中,EasyDarwin非常贴合安防监控的需求,但一直未尝试用EasyDarwin进行IPTV的RTSP流进行转发 ...
- IPTV系统的VOD与TV业务性能测试
IPTV的未来发展正在成为业界的焦点话题.据市场研究公司MRG的统计,全球IPTV用户将由2004年的200万增加至2010年的2000万,预计全球IPTV市场2005-2010年的复合增长率为102 ...
随机推荐
- reduce/filter/map/zip/isinstance/list列表推导式
- O2O淘宝优惠券代码总结
一.数据集预处理 1.数据读入 import pandas as pd import numpy as np import datetime as date import datetime as dt ...
- CPM、CPC、CPA、CPS、CPL、CPR 是什么意思 -解析互联网广告术语
CPA CPS CPA/CPS常见的推广方式 CPA和CPSCPA,CPS CPS与CPA CPA.CPSCPA.CPS产品教 CPA CPS什么意思 CPACPS是什么 1. CPM(Cost p ...
- 搜索表字段包含某字符串的SQL和监控Oracle数据库的SQL。
1.第一个SQL 背景:需要找到SQL Server数据库中,包含某个字符串的表,输出表和包含该字符串的列. )='=' --这里填要搜索的字符串 DECLARE @sql NVARCHAR(MAX) ...
- Leetcode-1.两数之和
题目描述: 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但是,你不能重复利用这个数 ...
- 逆元知识普及(扫盲篇) —— from Judge
watch out 本文是博主的 csdn 上搬过来的,格式有点崩,看不下去的可以去 博主的 csdn上看(上面 格式会好很多,并且有些公式也用 $\LaTeX$ update 上去了) 最近有点颓 ...
- MinGW GCC 8.3.1 2019年2月23日 出炉啦
GNU 2019-02-22 发布了 GCC 8.3 https://gcc.gnu.org/onlinedocs/8.3.0/ 有详细的说明 MinGW 上可用的 GCC 8.3.1 版本下载地址 ...
- Access提示Insert Into 语法错误解决办法总结
1.关键字:如果你的数据库的表的设计包含了Access包含的关键字,则在插入的时候会出现“Insert Into 语法错误” 例如: string sqlText = String.Format(&q ...
- js数据结构与算法——集合
<script> function Set(){ var items = {};//使用对象表示集合,因为js对象不允许一个键指向两个不同的值,保证集合里面的匀速唯一性 this.add ...
- router-link 返回上页 和 新窗口打开链接
1.如果使用了Vue-router的话,就可以用 this.$router.go(-1) 实现返回: 2.如果没使用vue-router,就可以用 window.history.go(-1) 实现返回 ...