Skip to content

Commit

Permalink
[common] provide a method to merge metric by name
Browse files Browse the repository at this point in the history
  • Loading branch information
ar2rsawseen committed Jul 27, 2015
1 parent 49bbb87 commit 072a6f5
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions frontend/express/public/javascripts/countly/countly.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,29 @@

return {"chartData":_.compact(tableData)};
};

countlyCommon.mergeMetricsByName = function(chartData, metric){
var uniqueNames = {},
data;
for(var i = 0; i < chartData.length; i++){
data = chartData[i];
if(data[metric] && !uniqueNames[data[metric]]){
uniqueNames[data[metric]] = data
}
else{
for(var key in data){
if(typeof data[key] == "string")
uniqueNames[data[metric]][key] = data[key];
else if(typeof data[key] == "number"){
if(!uniqueNames[data[metric]][key])
uniqueNames[data[metric]][key] = 0;
uniqueNames[data[metric]][key] += data[key];
}
}
}
}
return _.values(uniqueNames);
};

// Extracts top three items (from rangeArray) that have the biggest total session counts from the db object.
countlyCommon.extractBarData = function (db, rangeArray, clearFunction) {
Expand Down

0 comments on commit 072a6f5

Please sign in to comment.