Skip to content

Commit

Permalink
fix(core/reports): improve expression utils API and performance
Browse files Browse the repository at this point in the history
  • Loading branch information
robzan8 committed Mar 16, 2023
1 parent 3209b56 commit fe3e277
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 213 deletions.
3 changes: 3 additions & 0 deletions projects/core/models/src/utils/expression-utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Returns an array containing all the values that the specified field takes in the
The values are converted to strings.
An optional expression can be added to filter which forms to consider in the computation.

`FIRST(forms, expression, dateField = "created_at")`
Evaluates the expression in the first form by date.

`LAST(forms, expression, dateField = "created_at")`
Evaluates the expression in the last form by date.

Expand Down
4 changes: 2 additions & 2 deletions projects/core/models/src/utils/expression-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ describe('ALL_VALUES_OF', () => {

describe('SUM', () => {
it('should sum the values of one field in dataset', () => {
const result = SUM(forms, 'dog_puppies', 'to_check === true');
const result = SUM(forms, 'dog_puppies', (form: any) => form.to_check === true);
const dog_puppies = 5;
expect(result).toBe(dog_puppies);
});

it('should sum the values of one field in repeating slide', () => {
const result = SUM(forms, 'score', 'to_check === true');
const result = SUM(forms, 'score', (form: any) => form.to_check === true);
const score = 18;
expect(result).toBe(score);
});
Expand Down

0 comments on commit fe3e277

Please sign in to comment.