Skip to content

Commit

Permalink
statistic output slightly modified (others-counting/-sorting)
Browse files Browse the repository at this point in the history
  • Loading branch information
hgoebl committed Nov 28, 2013
1 parent 316cd9c commit 534e1af
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ lib-cov
*.out
*.pid
*.gz
*.bak

pids
logs
Expand Down
18 changes: 11 additions & 7 deletions web/js/useragent-analyze.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,26 +148,30 @@
}

function transformObject(object, sum, maxItems) {
var data, others = sum;
var data, othersSum = sum, othersCount = 0;

data = Object.keys(object).map(function (key) {
var count = object[key];
others -= count;
othersSum -= count;
return {key: key, n: count};
});
data.sort(sortByN);
if (maxItems && data.length >= maxItems) {
if (maxItems && data.length > maxItems) {
data = data.filter(function (item, index) {
if (index < maxItems - 1) {
return true;
}
others += item.n;
othersSum += item.n;
++othersCount;
return false;
})
}
if (others > 0) {
data.push({key: '(others)', n: others});
data.sort(sortByN);
if (othersSum > 0) {
data.push({
key: othersCount ? '(others: ' + othersCount + ')' : '(others)',
n: othersSum
});
// data.sort(sortByN); do not sort, so others are always last
}
return data;
}
Expand Down

0 comments on commit 534e1af

Please sign in to comment.