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

Reducers: Add in basic Percentile Support #85554

Merged
merged 14 commits into from
Apr 6, 2024
Merged

Conversation

timlevett
Copy link
Member

@timlevett timlevett commented Apr 3, 2024

What is this feature?

As a user I want to be able to quickly calculate various percentiles on my data, both in group by transformations and in legends, or wherever else reducers are used.

Screenshare.-.2024-04-03.1_11_18.PM.mp4

Update: Based off of offline chatter, changed to generate p1 through p99.

Why do we need this feature?

It's so nice to be able to understand percentiles as they a much better statistic than mean (averages). There is a joke, if Bill Gates walks into a bar, on average everyone is a millionaire. Its a mean joke... Having percentiles will help reduce (no pun intended) any misguidance that mean is giving people.

Who is this feature for?

Stats nerds, or anyone who is interested in learning better estimations.

Which issue(s) does this PR fix?:

Fixes #

Special notes for your reviewer:

Please check that:

  • It works as expected from a user's perspective.
  • If this is a pre-GA feature, it is behind a feature toggle.
  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.

@timlevett timlevett requested a review from a team as a code owner April 3, 2024 18:14
@timlevett timlevett requested review from leeoniya and baldm0mma and removed request for a team April 3, 2024 18:14
@grafana-delivery-bot grafana-delivery-bot bot added this to the 11.1.x milestone Apr 3, 2024
@timlevett timlevett added add to changelog no-backport Skip backport of PR labels Apr 3, 2024
@timlevett timlevett changed the title Reducers - Add in basic Percentile Support Reducers: Add in basic Percentile Support Apr 3, 2024
@@ -28,6 +28,106 @@ export enum ReducerID {
allIsNull = 'allIsNull',
allValues = 'allValues',
uniqueValues = 'uniqueValues',
p1 = 'p1',
Copy link
Contributor

Choose a reason for hiding this comment

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

Ooof, @timlevett you're right, this is rough! 😊 We could remove the p values and replace it with something like this?

function generatePercentiles() {
  const percentiles: { [key: string]: string } = {};
  for (let i = 1; i <= 99; i++) {
    percentiles[`p${i}`] = `p${i}`;
  }
  return percentiles;
}

export enum ReducerID {
  ...generatePercentiles(),
}

?

Copy link
Member Author

Choose a reason for hiding this comment

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

ah clever, i didn't know you could do that with an enum! TIL. Will change.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to do this but enum doesn't allow dynamic additions :(

Copy link
Contributor

Choose a reason for hiding this comment

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

TS, c'mon! Well, we tried! ;)

for (let i = 1; i < 100; i++) {
const percentile = i / 100;
const id = `p${i}` as ReducerID;
const nth = (n: number) => n>3&&n<21?"th":n%10===1?"st":n%10===2?"nd":n%10===3?"rd":"th";
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this.

Copy link
Member Author

Choose a reason for hiding this comment

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

You can thank the internet for that one 😂

Copy link
Contributor

@baldm0mma baldm0mma left a comment

Choose a reason for hiding this comment

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

LGTM!

@timlevett timlevett merged commit c47be31 into main Apr 6, 2024
18 checks passed
@timlevett timlevett deleted the timlevett/reducer-percentiles branch April 6, 2024 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants