Skip to content

Commit

Permalink
[Feat] add stdev and variance aggregators
Browse files Browse the repository at this point in the history
Make use of D3 deviation and variance functions to add
stdev and variance options to the list of available
data aggregators.

This fails `yarn test-node`, however master also
fails with the same error.
  • Loading branch information
jefemagril committed Oct 28, 2019
1 parent 43ed075 commit 7d81876
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/constants/default-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,9 @@ export const AGGREGATION_TYPES = {
maximum: 'maximum',
minimum: 'minimum',
median: 'median',
stdev: 'stdev',
sum: 'sum',
variance: 'variance',
// ordinal
mode: 'mode',
countUnique: 'count unique'
Expand All @@ -364,15 +366,19 @@ export const linearFieldAggrScaleFunctions = {
[AGGREGATION_TYPES.maximum]: [SCALE_TYPES.quantize, SCALE_TYPES.quantile],
[AGGREGATION_TYPES.minimum]: [SCALE_TYPES.quantize, SCALE_TYPES.quantile],
[AGGREGATION_TYPES.median]: [SCALE_TYPES.quantize, SCALE_TYPES.quantile],
[AGGREGATION_TYPES.sum]: [SCALE_TYPES.quantize, SCALE_TYPES.quantile]
[AGGREGATION_TYPES.stdev]: [SCALE_TYPES.quantize, SCALE_TYPES.quantile],
[AGGREGATION_TYPES.sum]: [SCALE_TYPES.quantize, SCALE_TYPES.quantile],
[AGGREGATION_TYPES.variance]: [SCALE_TYPES.quantize, SCALE_TYPES.quantile]
},

[CHANNEL_SCALES.sizeAggr]: {
[AGGREGATION_TYPES.average]: [SCALE_TYPES.linear, SCALE_TYPES.sqrt, SCALE_TYPES.log],
[AGGREGATION_TYPES.maximum]: [SCALE_TYPES.linear, SCALE_TYPES.sqrt, SCALE_TYPES.log],
[AGGREGATION_TYPES.minimum]: [SCALE_TYPES.linear, SCALE_TYPES.sqrt, SCALE_TYPES.log],
[AGGREGATION_TYPES.median]: [SCALE_TYPES.linear, SCALE_TYPES.sqrt, SCALE_TYPES.log],
[AGGREGATION_TYPES.sum]: [SCALE_TYPES.linear, SCALE_TYPES.sqrt, SCALE_TYPES.log]
[AGGREGATION_TYPES.stdev]: [SCALE_TYPES.linear, SCALE_TYPES.sqrt, SCALE_TYPES.log],
[AGGREGATION_TYPES.sum]: [SCALE_TYPES.linear, SCALE_TYPES.sqrt, SCALE_TYPES.log],
[AGGREGATION_TYPES.variance]: [SCALE_TYPES.linear, SCALE_TYPES.sqrt, SCALE_TYPES.log]
}
};

Expand Down
6 changes: 5 additions & 1 deletion src/utils/aggregate-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import {min, max, mean, median, sum} from 'd3-array';
import {deviation, min, max, mean, median, sum, variance} from 'd3-array';
import {AGGREGATION_TYPES} from 'constants/default-settings';

const getFrenquency = data => data.reduce((uniques, val) => {
Expand Down Expand Up @@ -53,8 +53,12 @@ export function aggregate(data, technique) {
return min(data);
case AGGREGATION_TYPES.median:
return median(data);
case AGGREGATION_TYPES.stdev:
return deviation(data);
case AGGREGATION_TYPES.sum:
return sum(data);
case AGGREGATION_TYPES.variance:
return variance(data);
default:
return data.length;
}
Expand Down
20 changes: 20 additions & 0 deletions test/fixtures/state-saved-v1-6.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
// Copyright (c) 2019 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

export const savedStateWIthNonValidFilters = {
datasets: [
{
Expand Down

0 comments on commit 7d81876

Please sign in to comment.