Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add percentile function for p-quantile #342

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/Expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ e.g.
| currentBreaksEnd(Dataset): Date | End date of current breaks |
| average(Dataset): number | Average value of the dataset |
| median(Dataset): number | Median value of the dataset |
| percentile(Dataset, percentile): number | Percentile-quantile value of the dataset |
| variance(Dataset): number | Variance value of the dataset |

### Functions Accept Dataset and Return Dataset
Expand Down
4 changes: 4 additions & 0 deletions src/expr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,10 @@ const fnMapDatasetToValue: FnMapDatasetToValue = {
// return number
return d3.median(dataset.getValues());
},
percentile: function (dataset, percentage, renderInfo) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work since expression functions can only accept dataset and renderInfo. I checked locally and it won't even compile when I run npm run dev. I would suggest instead looking at the RenderInfo class and adding a new field there to hold percentage. Then your dataView code would look something like:

searchType: dvField
searchTarget: dataviewTarget
folder: /diary
endDate: 2021-01-03
percentage: 0.6
summary:
    template: '60-percentile value: {{percentage(dataset(0))::.1f}} <-- should be 29.6'

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After you have made changes, I strongly encourage you to run npm run dev and then open up the example folder in Obsidian so you can verify it works (this is what I do with every new feature submitted)

// return number
return d3.quantile(dataset.getValues(), percentage / 100);
},
variance: function (dataset, renderInfo) {
// return number
return d3.variance(dataset.getValues());
Expand Down