Skip to content

fix: dynamically calculate Avg Review Time instead of hardcoded value#263

Merged
Soumya-codr merged 2 commits into
Coder-s-OG-s:mainfrom
yush-1018:fix/avg-review-time-hardcoded-261
Jun 6, 2026
Merged

fix: dynamically calculate Avg Review Time instead of hardcoded value#263
Soumya-codr merged 2 commits into
Coder-s-OG-s:mainfrom
yush-1018:fix/avg-review-time-hardcoded-261

Conversation

@yush-1018

Copy link
Copy Markdown
Contributor

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

const avgReviewDays = 2.3; 

@vercel

vercel Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

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

@codersogs-code

Copy link
Copy Markdown
Collaborator

@yush-1018
Thanks for tackling this issue! Moving away from the hardcoded 2.3 value is a great catch. However, I have a couple of callouts regarding the calculation logic before we move out:

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 ${avgReviewDays} days can be a bit fragile for layout consistency. Let's strip the extra spaces and rely on Tailwind/CSS if we need padding.

Comment thread src/app/(app)/my-prs/page.tsx Outdated
</div>
<div className="font-sans text-[24px] font-black leading-none text-white">
{avgReviewDays} days
{avgReviewDays !== null ? `${avgReviewDays} days` : 'N/A'}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@vercel

vercel Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
mergeship Ready Ready Preview, Comment Jun 6, 2026 12:21pm

@Soumya-codr Soumya-codr merged commit 644fa4a into Coder-s-OG-s:main Jun 6, 2026
4 checks passed
@Soumya-codr

Copy link
Copy Markdown
Collaborator

LGTM Thanks

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.

"Avg Review Time" on My PRs page is hardcoded to 2.3 days

3 participants