Skip to content

Commit

Permalink
fix(core/reports): fix some expression utils functions
Browse files Browse the repository at this point in the history
  • Loading branch information
robzan8 committed Feb 21, 2023
1 parent d6aabee commit 9320297
Show file tree
Hide file tree
Showing 3 changed files with 219 additions and 346 deletions.
42 changes: 42 additions & 0 deletions projects/core/models/src/utils/expression-utils.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Xlsreport indicators and functions

This file documents the scripting language that can be used inside xlsreport to define indicators and
lists all the functions that are available in the language.

`ALL_VALUES_OF(forms, $field)`
Returns an array containing all the values that the specified field takes in the forms.
The values are converted to strings.

`COUNT_FORMS(forms, $expression?)`
Returns the number of forms for which expression evaluates to true,
for the form itself or for any of its repetitions.

`COUNT_REPS(forms, $expression?)`
Counts the forms and all of their repetitions for which the expression evaluates to true.

`COUNT_FORMS_UNIQUE(forms, $field, $expression?)`
TODO: rename to COUNT_UNIQUE_VALUES
Counts the different values that the specified field takes in the forms (and their repetitions).

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

`SUM(forms, $field, $expression?)`
Aggregates and sums the values of the specified field.
An optional expression can be added to filter which forms to take for the sum.

`MEAN(forms, $field, $expression?)`
Computes the mean of the values of the specified field.
An optional expression can be added to filter which forms to take for the sum.

`MAX(forms, $field, $expression?)`
Computes the max value of the field.
An optional expression can be added to filter which forms to take for the sum.

`MEDIAN(forms, $field, $expression?)`
Computes the median value of the field.
An optional expression can be added to filter which forms to take for the sum.

`MODE(forms, $field, $expression?)`
Computes the mode value of the field.
An optional expression can be added to filter which forms to take for the sum.
2 changes: 1 addition & 1 deletion projects/core/models/src/utils/expression-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('COUNT_FORMS', () => {
describe('MEAN', () => {
it('should calculate the mean of a value in dataset', () => {
const result = MEAN(forms, 'dog_puppies');
const dog_puppies_mean = '2';
const dog_puppies_mean = 2;
expect(result).toBe(dog_puppies_mean);
});
});

0 comments on commit 9320297

Please sign in to comment.