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 a metric rating property #246

Merged
merged 1 commit into from Jul 22, 2022
Merged

Add a metric rating property #246

merged 1 commit into from Jul 22, 2022

Conversation

philipwalton
Copy link
Member

This PR address #2 by adding a new rating property to the Metric object.

interface Metric {
  /**
   * The rating as to whether the metric value is within the "good",
   * "needs improvement", or "poor" thresholds of the metric.
   */
  rating: 'good' | 'ni' | 'poor';
  
  // ...
}

Note: I opted to use "ni" rather than the full string "needs improvement" because I felt it was awkward to have such a long value with a space in it. I'm open to feedback or suggestions on that though.

Comment on lines 20 to 28
const getRating = (value: number, thresholds: number[]) => {
if (value > thresholds[1]) {
return 'poor';
}
if (value > thresholds[0]) {
return 'ni';
}
return 'good';
};
Copy link
Member

Choose a reason for hiding this comment

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

Should we check its >= 0 before returning good?

Maybe return null or such like if < 0

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 don't think we have to. This function is only ever called from within a conditional that check if metric.value >= 0 (see line 40).

Copy link
Member

Choose a reason for hiding this comment

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

Seems a good safety check to add in case that ever becomes not there case?

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 don't want to type that it could be string | null, because I think that would unnecessarily concern users of the library (especially TypeScript users).

I think to handle your concern it's better to have a test that checks that case rather than building it into the code (that users have to download even though it's not currently needed). There are lots of tests currently that make sure the metric value is greater than or equal to 0, and those would all start failing if that were ever not the case.

Copy link
Member

Choose a reason for hiding this comment

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

Ah typescript! Must learn that…

Not a big deal, so fine to resolve this. Plus arguably a negative number IS a “good” score by the metric definitions 😄And the bug if that ever happens is upstream not in this function.

Alternatively could also return “unknown”.

Copy link
Member

@tunetheweb tunetheweb left a comment

Choose a reason for hiding this comment

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

LGTM!

@Tiggerito
Copy link

For my solution, I calculated the rating and returned an object like this:

return {
rating: 'ni',
name: 'Needs Improvement'
}

For my GA4 implementation, I sent both values as metric_rating and metric_status. The latter makes it easier to build reports.

Maybe over-engineering for most.

@philipwalton
Copy link
Member Author

Update: I changed 'ni' to 'needs-improvement' based on the recommendation of colleagues and to be consistent with the recommendations for enumeration values section of the TAG's Design Principles guide.

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

Successfully merging this pull request may close these issues.

None yet

3 participants