fix: dynamically calculate Avg Review Time instead of hardcoded value#263
Conversation
|
@yush-1018 is attempting to deploy a commit to the codersogs-3057's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@yush-1018 Metric Accuracy: merged_at - github_created_at calculates the total lifespan of a PR, not the Review Time. A PR could sit drafts or wait on a broken CI pipeline for days after being fully reviewed. Should we adjust this to track the time between the first review/approval and creation, or should we rename the UI label to Avg PR Lifespan? Floating Point Quirks: Using Math.round(val * 10) / 10 can sometimes introduce floating-point precision issues in JS. It might be safer to handle this using avgReviewDays.toFixed(1) directly in the JSX presentation layer. String Spacing: The hardcoded spaces inside |
| </div> | ||
| <div className="font-sans text-[24px] font-black leading-none text-white"> | ||
| {avgReviewDays} days | ||
| {avgReviewDays !== null ? `${avgReviewDays} days` : 'N/A'} |
There was a problem hiding this comment.
Could you please explain the purpose behind this change and break down how the whole code works? I'd love to understand the logic better, especially the math used for the calculation and the conditional rendering at the end. Thanks!
There was a problem hiding this comment.
So basically the old code had avgReviewDays = 2.3 just sitting there hardcoded lol. Every user was seeing the same number regardless of their actual PRs.
What I did is pretty straightforward — I grab all the merged PRs that have both a github_created_at and merged_at timestamp, then for each one I calculate how many days it took from creation to merge:
(merged_at - github_created_at) gives us milliseconds, and dividing by 1000 * 60 * 60 * 24 converts that to days. Then I just average them all out.
For the rendering part — if the user has merged PRs, we show the calculated value with .toFixed(1) so it looks clean (like "2.3 days"). If they don't have any merged PRs at all, avgMergeDays ends up being null and we just show "N/A" instead of some random number.
Hope that clears it up, let me know if anything else looks off.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
… and string spacing
|
LGTM Thanks |
Fixes #261
What's the problem?
The "Avg Review Time" stat on the My Pull Requests page was always showing 2.3 days for every user — because it was literally hardcoded