
tpRegisterQOSType("onPlaylistEnd","ALL","QOSMPS_handlePLEnd");var QOSMPS_baseUrl="http://release.theplatform.com/tracker.log"
var QOSMPS_qs="";var QOSMPS_baseCount=0;var QOSMPS_baseClips=new Array();function QOSMPS_handlePLEnd(pl)
{QOSMPS_baseCount=0;QOSMPS_baseClips.length=0;QOSMPS_qs="?type=qos&ver=1";if(pl.currentDate!=undefined)QOSMPS_appendStr_qs("d",pl.currentDate);if(pl.userName!=undefined)QOSMPS_appendStr_qs("un",pl.userName);if(pl.countryCode!=undefined)QOSMPS_appendStr_qs("cc",pl.countryCode);if(pl.regionCode!=undefined)QOSMPS_appendStr_qs("rc",pl.regionCode);if(pl.browser!=undefined)QOSMPS_appendStr_qs("br",pl.browser);if(pl.operatingSystem!=undefined)QOSMPS_appendStr_qs("os",pl.operatingSystem);if(pl.feed!=undefined)QOSMPS_appendStr_qs("p",pl.feed);if(pl.player!=undefined)QOSMPS_appendStr_qs("pl",pl.player);if(pl.affiliate!=undefined)QOSMPS_appendStr_qs("af",pl.affiliate);if(pl.playlistID!=undefined)QOSMPS_appendStr_qs("prid",pl.playlistID);for(var i=0;i<pl.clips.length;i++)
{QOSMPS_parseClip(pl.clips[i]);}
if(QOSMPS_baseClips.length>1)QOSMPS_parseAggregate(pl.playlistID)
QOSMPS_sendData(QOSMPS_qs);}
function QOSMPS_parseClip(c)
{var bc=c.baseClip;var isC=false;for(var i=0;i<QOSMPS_baseClips.length;i++)
{if(QOSMPS_baseClips[i].releaseID==bc.releaseID)
{if(c.isAd)
{QOSMPS_appendStr_qs("c"+QOSMPS_baseCount,"1");break;}
else
{return;}}}
QOSMPS_baseClips.push(bc);if(bc.releaseID!=undefined)QOSMPS_appendStr_qs("rid"+QOSMPS_baseCount,bc.releaseID);if(bc.title!=undefined&&bc.title!=null&&bc.title!="null")QOSMPS_appendStr_qs("t"+QOSMPS_baseCount,bc.title);if(bc.author!=undefined&&bc.author!=null&&bc.author!="null")QOSMPS_appendStr_qs("a"+QOSMPS_baseCount,bc.author);if(bc.releaseLength!=undefined)QOSMPS_appendStr_qs("l"+QOSMPS_baseCount,bc.releaseLength);if(bc.bitrate!=undefined&&bc.bitrate!=NaN&&bc.bitrate!="NaN")QOSMPS_appendStr_qs("b"+QOSMPS_baseCount,bc.bitrate);if(bc.loadTime!=undefined)QOSMPS_appendStr_qs("lt"+QOSMPS_baseCount,bc.loadTime);if(bc.trueLength==undefined&&c.baseClip.releaseLength!=undefined)bc.trueLength=bc.releaseLength;if(bc.lengthPlayed!=undefined)
{var percentPlayed=QOSMPS_round((bc.lengthPlayed/bc.trueLength)*100,2);if(percentPlayed>100)percentPlayed=100;if(!isNaN(percentPlayed))
{QOSMPS_appendStr_qs("pp"+QOSMPS_baseCount,percentPlayed);}}
if(bc.rebufferingTime!=undefined)
{var percentRebuff=QOSMPS_round((bc.rebufferingTime/(bc.rebufferingTime+bc.lengthPlayed))*100,2);QOSMPS_appendStr_qs("pr"+QOSMPS_baseCount,percentRebuff);}
var percentBW;if(bc.connectionBitrate!=undefined)
{if(bc.trueBitrate==undefined&&bc.bitrate!=undefined)bc.trueBitrate==bc.bitrate/1000;percentBW=QOSMPS_round((bc.connectionBitrate/bc.trueBitrate)*100,2);if(!isNaN(percentBW))
{if(percentBW>100)percentBW=100;}
else
{percentBW=100;}}
else
{percentBW=100;}
if(bc.lengthPlayed!=undefined&&bc.lengthPlayed>0)
{bc.percentBW=percentBW;QOSMPS_appendStr_qs("pb"+QOSMPS_baseCount,percentBW)}
else
{bc.percentBW=undefined;}
if(bc.lengthPlayed!=undefined&&bc.lengthPlayed>0)QOSMPS_appendStr_qs("lp"+QOSMPS_baseCount,bc.lengthPlayed);QOSMPS_baseCount++;}
function QOSMPS_parseAggregate(plid)
{if(plid!=undefined)QOSMPS_appendStr_qs("rid"+QOSMPS_baseCount,plid);var loadTime=QOSMPS_baseClips[0].loadTime;var trueLength=0;var lengthPlayed=0;var percentBW=100;var bwLength=0;var rebuffTime=0;var bwCalcArray=new Array();for(var i=0;i<QOSMPS_baseClips.length;i++)
{var bc=QOSMPS_baseClips[i];if(bc.trueLength!=undefined)trueLength+=bc.trueLength;if(bc.lengthPlayed!=undefined)
{if(bc.lengthPlayed>bc.trueLength)bc.lengthPlayed=bc.trueLength;lengthPlayed+=bc.lengthPlayed;}
if(bc.rebufferingTime!=undefined)rebuffTime+=bc.rebufferingTime;if(bc.percentBW!=undefined)
{var bwObj=new Object();bwObj.percentBW=bc.percentBW;bwObj.trueLength=bc.trueLength;bwCalcArray.push(bwObj);bwLength+=bc.trueLength;}}
var compositeBW=0;if(bwLength>0)
{for(var i=0;i<bwCalcArray.length;i++)
{var bwObj=bwCalcArray[i];var percentTotal=bwObj.trueLength/bwLength;compositeBW+=bwObj.percentBW*percentTotal}}
if(compositeBW>100)compositeBW=100;if(trueLength>0)QOSMPS_appendStr_qs("l"+QOSMPS_baseCount,trueLength);if(loadTime!=undefined)QOSMPS_appendStr_qs("lt"+QOSMPS_baseCount,loadTime);if(lengthPlayed>0&&trueLength>0)
{var percentPlayed=QOSMPS_round((lengthPlayed/trueLength)*100,2);if(percentPlayed>100)percentPlayed=100;if(!isNaN(percentPlayed))QOSMPS_appendStr_qs("pp"+QOSMPS_baseCount,percentPlayed);}
if(rebuffTime>0&&trueLength>0)
{var percentRebuff=QOSMPS_round((rebuffTime/(rebuffTime+lengthPlayed))*100,2);if(!isNaN(percentRebuff))QOSMPS_appendStr_qs("pr"+QOSMPS_baseCount,percentRebuff);}
if(compositeBW>0)QOSMPS_appendStr_qs("pb"+QOSMPS_baseCount,QOSMPS_round(compositeBW,2));if(lengthPlayed>0)QOSMPS_appendStr_qs("lp"+QOSMPS_baseCount,lengthPlayed);}
function QOSMPS_appendStr_qs(name,value)
{QOSMPS_qs+="&"+name+"="+value;}
function QOSMPS_sendData(qString)
{var theUrl=QOSMPS_baseUrl+qString;tpQOSSendURL(theUrl);QOSMPS_qs=""}
function QOSMPS_round(num,power)
{var mult=Math.pow(10,power);var raw=num*mult;raw=Math.round(raw);return raw/mult;}