Skip to content

Commit

Permalink
Update slick.dataview.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding authored and mleibman committed Feb 5, 2012
1 parent d2839d3 commit 302780f
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions slick.dataview.js
Expand Up @@ -6,7 +6,8 @@
Aggregators: {
Avg: AvgAggregator,
Min: MinAggregator,
Max: MaxAggregator
Max: MaxAggregator,
Sum: SumAggregator
}
}
}
Expand Down Expand Up @@ -813,9 +814,9 @@
this.accumulate = function (item) {
var val = item[this.field_];
this.count_++;
if (val != null && val != NaN) {
if (val != null && val != "" && val != NaN) {
this.nonNullCount_++;
this.sum_ += 1 * val;
this.sum_ += parseFloat(val);
}
};

Expand All @@ -824,7 +825,7 @@
groupTotals.avg = {};
}
if (this.nonNullCount_ != 0) {
groupTotals.avg[this.field_] = this.sum_ / this.nonNullCount_;
groupTotals.avg[this.field_] = (this.sum_ / this.nonNullCount_)*100/100;
}
};
}
Expand All @@ -838,7 +839,7 @@

this.accumulate = function (item) {
var val = item[this.field_];
if (val != null && val != NaN) {
if (val != null && val != "" && val != NaN) {
if (this.min_ == null || val < this.min_) {
this.min_ = val;
}
Expand All @@ -862,7 +863,7 @@

this.accumulate = function (item) {
var val = item[this.field_];
if (val != null && val != NaN) {
if (val != null && val != "" && val != NaN) {
if (this.max_ == null || val > this.max_) {
this.max_ = val;
}
Expand All @@ -877,6 +878,27 @@
}
}

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

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

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

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

0 comments on commit 302780f

Please sign in to comment.