# -*- 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的更多相关文章

  1. IPTV中的EPG前端优化

    先看一下IPTV相关情况: l 目前TPTV市场情况 a) 截止今年2月,全国IPTV总用户数达3630.2万,我国移动互联网用户规模接近9亿,人均月接入量近300M,8M宽带达半数,光纤近4成. 图 ...

  2. IPTV小窗口播放视频 页面焦点无法移动的解决方法

    在IPTV高清页面中,小窗口播放视频时,在某些机顶盒上(如高清中兴.高清大亚4904)会出现焦点无法移动现象,即按键无响应.被这个bug困扰了很久,虽然我知道解决方法,但只知其然,不知其所以然.今天做 ...

  3. 北邮iptv用WindowsMediaplayer打不开的解决的方法

    前言:之前我的iptv能够用,可是有次我安装了realplayer,它就偷偷把iptv文件的默认打开方式给篡改了,卸载了                  realplayer之后,iptv不能直接用 ...

  4. 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 ...

  5. 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 ...

  6. 移动iptv安装三方软件

    1.思路:  分为硬件和软件. a.硬件是ttl直接上串口,弄得比较复杂,且容易损坏盒子,先不考虑 b.软件:抓包获取iptv的请求数据,将移动光猫的iptv出口接到交换机上,电脑和盒子接入到同一个交 ...

  7. 华为4K机顶盒EC6108V9U从原联通更换为电信的IPTV账号成功经验

    4K设备直接在淘宝上买30块钱升级4K机顶盒,i视视手机app控制电视和手机投屏 硬件设备:EC6108V9U由X省联通更换为四川电信 采坑经验: 1.要从现有的机顶盒获取mac地址.stbid.ip ...

  8. 中兴iptv机顶盒破解教程图文:亲测中兴B760EV3、B860A、B860AV1.1完美安装应用!非ttl破解![转]

    一直以为中兴的这几个盒子只能通过ttl来破解,不过现在再也不用这么麻烦了,有了这个工具,前后破解不超3分钟!理论上支持所有中兴的iptv机顶盒的破解! 亲测中兴B760EV3.B860A.B860AV ...

  9. 用EasyDarwin进行IPTV rtsp mpeg-ts smil流的转发和分发直播服务

    对RTSP/RTP的转发和分发一直都是EasyDarwin的基础功能,尤其是在安防行业中,EasyDarwin非常贴合安防监控的需求,但一直未尝试用EasyDarwin进行IPTV的RTSP流进行转发 ...

  10. IPTV系统的VOD与TV业务性能测试

    IPTV的未来发展正在成为业界的焦点话题.据市场研究公司MRG的统计,全球IPTV用户将由2004年的200万增加至2010年的2000万,预计全球IPTV市场2005-2010年的复合增长率为102 ...

随机推荐

  1. ThinkPHP—URL的访问以及各种方法的操作

    1.URL访问 ThinkPHP采用单一入口模式访问应用,对应用的所有请求都定向到应用的入口文件,系统会从URL参数中解析当前请求的模块.控制器和操作,下面是一个标准的URL访问格式: 第一种访问方式 ...

  2. web前端效率提升之浏览器与本地文件的映射-遁地龙卷风

    1.chrome浏览器,机制是拦截url, 1.在浏览器Element中调节的css样式可以直接同步到本地文件,反之亦然,浏览器会重新加载css,省去刷新 2.在source面板下对js的编辑可以同步 ...

  3. [Kubernetes]说说 Service 与 Ingress

    在 Kubernetes 中, Service 有三种对外暴露的方法,但是由于每个 Service 都要有一个负载均衡的服务,所以采用 Service 的话,会造成既浪费成本又高的现象.对于用户来说, ...

  4. centos定时删除指定日期之前的文件

    * 5 * * * find /tmp/* -name "yhwl_task.log*" -ctime +3 -exec rm -rf {} \; * 5 * * * find / ...

  5. C#中上下文Context的理解

    上下文指的是 进程间占有的资源空间. 当一个进程时间片到了或者资缺的时候就会让出cpu 当另一个进程开始始用CPU之前,系统要保存即将退出进程的执行状态,以便轮到时间片或有资源的时候现场恢复.这就所谓 ...

  6. Springboot+Mybaits之两张表同时插入数据

    项目需求是,一张表添加数据的同时,另外一张表也需要添加数据,话不多说,直接上代码. 1.Controller,我把两个DTO直接放到一个@RequestBody中.其中throws是后台获取当前时间抛 ...

  7. python之地基(二)

    上一个阶段呢,我们已经学习了python的数据的类型.今天呢,我们来学习各种各样的运算符. 一.基本运算符 a = 10    b = 20 运算符号 描述 示例 + 加——两个对象相加 a+b 输出 ...

  8. datatable 给某一列添加title属性

    简单描述:采用datatable拼接的表格,没有title属性,嗯就是这个情况,直接上代码 代码: //js代码$("#toAdd").click("click" ...

  9. nginx代理 (带着请求头)

    当你获得云服务器之后, 你有这样一个需求:当你要访问一个url的时候,这个URL只能在人家的云服务器上访问(比如百度),所以你要买百度的BCC,你可能在想在BCC起服务,那样有点麻烦,直接使用ngin ...

  10. mybatis的xml中sql语句中in的写法(迭代遍历)

    这里使用 foreach标签 <foreach  item="item" collection="listTag" index="index&q ...