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

Conversation

lulunac27a
Copy link
Contributor

Description

Add percentile function for datasets with p-quantile based from an array of numbers. percentile value is 0 to 100.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

  • If this is a new feature, did you add files to the examples directory to demonstrate the feature?
  • If this is a new feature, did you add documentation to the docs directory for the feature?

@lazyguru lazyguru added the enhancement New feature or request label Apr 4, 2024
@lazyguru lazyguru self-requested a review April 4, 2024 05:32
Copy link
Collaborator

@lazyguru lazyguru left a comment

Choose a reason for hiding this comment

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

Hi @lulunac27a, could you please add/update test files in the example vault that both demonstrates this function being used but also works as a way to test that it is working? You can either add a new file or update https://github.com/pyrochlore/obsidian-tracker/blob/master/examples/TestExpression.md to include usage of the new function and then update a few of the files in the diary directory to use as the dataset

20-percentile of [12, 25, 48] is 17.2 and 60-percentile of [12, 25, 48] is 29.6
@lulunac27a
Copy link
Contributor Author

lulunac27a commented Apr 5, 2024

I added the test expressions.

@@ -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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants