You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
varintMin=null,intMax=null,intTotal=0,intCount=0;varobjUniqueValues={};varfnOnMessage=function(objMsg){//assuming objMsg.value is a numberif(objMsg.value>intMax||intMax===null){intMax=objMsg.value;}if(objMsg.value<intMin||intMin===null){intMin=objMsg.value;}intTotal+=objMsg.value;intCount++;if(typeofobjUniqueValues[objMsg.value]==='undefined'){objUniqueValues[objMsg.value]=1;}else{objUniqueValues[objMsg.value]=++;}}
Example of keeping track of time windows
varupdateWindows=function(arrData,objStat){//console.log(arrData,objStat);//does a new bucket need to be created?//var intNow=Date.now(); //shouldnt be needed, can use lsif(objStat.windows.current.fs<objStat.ls-60000){//take current bucket, snapshot it to historyobjStat.windows.minute.push(objStat.windows.current);//re-init current bucketobjStat.windows.current=_.defaults({},objDefaults[objStat.type]());if(objStat.windows.hasOwnProperty('hour')&&objStat.windows.ts_hour<objStat.ls-360000){//loop through minutes and drop off anything older than an hourobjStat.windows.minute=_.filterOld(objStat.windows.minute,'fs',360000);//then take the remaining ones to aggregate into an hourobjStat.windows.hour.push(aggStats[objStat.type](objStat.windows.minute));objStat.windows.ts_hour=objStat.ls;}if(objStat.windows.hasOwnProperty('day')&&objStat.windows.ts_hour<objStat.ls-86400000){//loop through minutes and drop off anything older than an hourobjStat.windows.hour=_.filterOld(objStat.windows.hour,'fs',86400000);//then take the remaining ones to aggregate into an hourobjStat.windows.day.push(aggStats[objStat.type](objStat.windows.hour));objStat.windows.ts_day=objStat.ls;}}//process currentobjStat.windows.current=updateStats[objStat.type](arrData,objStat.windows.current);returnobjStat;};
Example Streaming Data population for multiple time increment horizontal bar chart
//init the arraysvararrDays=[],arrHours=[],arrMinutes=[],arrSeconds=[];variSeconds=0,iMinutes=0,iHours=0,iDays=0;//small utility function to get the sum for an arrayvarfnSum=function(arrIn){varintSum=0;for(vari=0;i<arrIn.length;i++){intSum+=arrIn[i];}returnintSum;};varfnOnMessage=function(intVal){//assuming 1 value and function call per secondarrSeconds.push(intVal);if(iSeconds>59){//add minutevarintSum=fnSum(arrSeconds);arrMinutes.push(intSum/60);iSeconds=0;if(iMinutes>59){//add hourvarintSum=fnSum(arrSeconds);arrHours.push(intSum/3600);iMinutes=0;if(iHours>23){//add dayvarintSum=fnSum(arrSeconds);//divide by number of seconds to normalize to average/secondarrDays.push(intSum/86400);iHours=0;}iHours++;}iMinutes++;}iSeconds++;}
Example Angular HTML to display multiple inline simple charts