Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a new dataview aggregator for count. #1108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion slick.dataview.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
Avg: AvgAggregator,
Min: MinAggregator,
Max: MaxAggregator,
Sum: SumAggregator
Sum: SumAggregator,
Count: CountAggregator
}
}
}
Expand Down Expand Up @@ -1120,6 +1121,28 @@
}
}

function CountAggregator(field) {
this.field_ = field;

this.init = function () {
this.sum_ = 0;
};

this.accumulate = function (item) {
var val = item[this.field_];
if (val != null && val !== "") {
this.sum_ += 1
}
};

this.storeResult = function (groupTotals) {
if (!groupTotals.sum) {
groupTotals.sum = {};
}
groupTotals.sum[this.field_] = this.sum_;
}
}

// TODO: add more built-in aggregators
// TODO: merge common aggregators in one to prevent needles iterating

Expand Down