Skip to content

Commit

Permalink
fix(case-aggregation): remove last generated age group
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMaruchu committed Jun 8, 2020
1 parent 64a04c4 commit 5ab1bf2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/aggregations/case.aggregations.js
@@ -1,7 +1,7 @@
import { Case } from '@codetanzania/ewea-case';
import { safeMergeObjects } from '@lykmapipo/common';
import { waterfall } from 'async';
import { map, isFunction, sortBy, uniqBy } from 'lodash';
import { map, isFunction, sortBy, uniqBy, slice } from 'lodash';

// start: constants
// order: base to specific
Expand All @@ -27,11 +27,11 @@ const AGE_GROUPS_LOWER_BOUNDARIES = [
160,
];

// generate all age groups from 0 to 200 years
// For shaping returned value
const NORMALIZED_AGE_GROUPS = map(
AGE_GROUPS_LOWER_BOUNDARIES,
(lowerBoundary) => {
// generate all age groups from 0 to 159 years
// Remove the last range 160 - 169 since it is not included in $buckets
// shape returned values to have a common structure for all ranges
const NORMALIZED_AGE_GROUPS = slice(
map(AGE_GROUPS_LOWER_BOUNDARIES, (lowerBoundary) => {
const upperBoundary =
lowerBoundary === 'Other' ? 'Other' : lowerBoundary + 9; // account for difference i.e 30 - 39
return {
Expand All @@ -40,7 +40,9 @@ const NORMALIZED_AGE_GROUPS = map(
lowerBoundary,
upperBoundary,
};
}
}),
0,
AGE_GROUPS_LOWER_BOUNDARIES.length - 1
);

const CASE_AGGREGATION_EXCLUDE = [];
Expand Down
2 changes: 1 addition & 1 deletion test/integration/case.aggregations.spec.js
Expand Up @@ -23,7 +23,7 @@ describe('EventCase Aggregations', () => {
expect(report.data.overall.ageGroups).to.exist.and.be.an('array');
expect(report.data.overall.occupations).to.exist.and.be.an('array');
expect(report.data.overall.nationalities).to.exist.and.be.an('array');
expect(report.data.overall.ageGroups).to.have.lengthOf(17);
expect(report.data.overall.ageGroups).to.have.lengthOf(16);
done(error, report);
});
});
Expand Down

0 comments on commit 5ab1bf2

Please sign in to comment.