Skip to content

Commit

Permalink
remove unnecessary logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mbondyra committed Nov 3, 2020
1 parent 9f5d531 commit 910b2be
Showing 1 changed file with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,18 @@ export const movingAverage: ExpressionFunctionMovingAverage = {
return input;
}

const lastNValuesByBucket: Partial<Record<string, Array<number | undefined>>> = {};
const lastNValuesByBucket: Partial<Record<string, number[]>> = {};
return {
...input,
columns: resultColumns,
rows: input.rows.map((row) => {
const newRow = { ...row };

const bucketIdentifier = getBucketIdentifier(row, by);
const lastNValues = lastNValuesByBucket[bucketIdentifier];
const currentValue = newRow[inputColumnId];
const sanitizedLastNValues = lastNValues?.filter((v) => v != null) as number[];
if (sanitizedLastNValues != null && sanitizedLastNValues.length && currentValue != null) {
const sanitizedSum = sanitizedLastNValues.reduce(
(acc: number, current: number) => acc + current,
0
);
newRow[outputColumnId] = sanitizedSum / sanitizedLastNValues.length;
if (lastNValues != null && lastNValues.length && currentValue != null) {
const sum = lastNValues.reduce((acc, current) => acc + current, 0);
newRow[outputColumnId] = sum / lastNValues.length;
} else {
newRow[outputColumnId] = undefined;
}
Expand Down

0 comments on commit 910b2be

Please sign in to comment.