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
Conversation
src/lib/bindReporter.ts
Outdated
const getRating = (value: number, thresholds: number[]) => { | ||
if (value > thresholds[1]) { | ||
return 'poor'; | ||
} | ||
if (value > thresholds[0]) { | ||
return 'ni'; | ||
} | ||
return 'good'; | ||
}; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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”.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
For my solution, I calculated the rating and returned an object like this: return { 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. |
Update: I changed |
This PR address #2 by adding a new
rating
property to theMetric
object.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.