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

fix review count #198

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,14 @@ export function getContributorBySlug(file: string, detail = false) {
...activityData,
activity: [...activityData.activity, ...getSlackMessages(data.slack)],
};
let AllUnqPrReviews = new Set();
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved

const weightedActivity = activityData.activity.reduce(
let weightedActivity = activityData.activity.reduce(
(acc, activity) => {
if (activity.type == "pr_reviewed") {
AllUnqPrReviews.add(activity.title);
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved
}

return {
activity: [
...acc.activity,
Expand All @@ -116,8 +121,7 @@ export function getContributorBySlug(file: string, detail = false) {
pr_merged: acc.pr_merged + (activity.type === "pr_merged" ? 1 : 0),
pr_collaborated:
acc.pr_collaborated + (activity.type === "pr_collaborated" ? 1 : 0),
pr_reviewed:
acc.pr_reviewed + (activity.type === "pr_reviewed" ? 1 : 0),
pr_reviewed: 0,
issue_assigned:
acc.issue_assigned + (activity.type === "issue_assigned" ? 1 : 0),
issue_opened:
Expand All @@ -138,6 +142,8 @@ export function getContributorBySlug(file: string, detail = false) {
} as Highlights & { activity: Activity[] },
);

weightedActivity.pr_reviewed = AllUnqPrReviews.size;

const calendarData = getCalendarData(weightedActivity.activity);
return {
file: file,
Expand Down Expand Up @@ -191,10 +197,27 @@ export function getCalendarData(activity: Activity[]) {
};
}
acc[date].count += 1;

const uniquePrReviews = new Set();
Copy link
Member

Choose a reason for hiding this comment

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

Could you explain why there are Two sets? All Unique and Unique? Could you explain the algorithm for how you are solving the problem?

Choose a reason for hiding this comment

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

The AllUnq set is used to count the total unique pull requests (PRs) reviewed.

and the 2nd set is For PRs reviewed in the last 7 days, we calculate and count the reviews for each date (day) and sum them up over this period.

In this process, if a PR has multiple reviews on the same day or on subsequent days, it is only counted once for its first review. Any subsequent reviews of the same PR are not counted again.

Copy link
Member

Choose a reason for hiding this comment

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

@konavivekramakrishna multiple distinct reviews on the same PR must be counted. But we shouldn't count the individual review comment on the PR. We should only count one review event.

Choose a reason for hiding this comment

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

@rithviknishad
For example, in the following pr: ohcnetwork/care_fe#6479

what should be the count of pr_reviewed

The count of 'pr_reviewed' for this pull request in the current staging leaderboard is 13

Choose a reason for hiding this comment

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

@konavivekramakrishna multiple distinct reviews on the same PR must be counted. But we shouldn't count the individual review comment on the PR. We should only count one review event.

@rithviknishad are you referring to multiple individuals reviewing the same pull request, or do you mean counting multiple distinct reviews by a single person?"

Copy link
Member

Choose a reason for hiding this comment

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

No. For example, the recent review I've made on your PR in care (ohcnetwork/care_fe#7152 (review)), I've only requested changes ONCE (and you might have also got a mail notification once for the same). However, leaderboard shows 2 review events even though I've made only 1 review event.

image image

Copy link
Member

Choose a reason for hiding this comment

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

The review event seems to be having an ID. Could you update the types? Or if we are not scrapping the ID, can we adjust the scraper to report only one review event for an ID?


if (acc[date][activity.type]) {
acc[date][activity.type] += 1;
if (
activity.type != "pr_reviewed" ||
(activity.type == "pr_reviewed" &&
uniquePrReviews.has(activity.title))
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved
) {
acc[date][activity.type] += 1;

}
} else {
acc[date][activity.type] = 1;
if (
activity.type != "pr_reviewed" ||
(activity.type == "pr_reviewed" &&
!uniquePrReviews.has(activity.title))
) {
acc[date][activity.type] = 1;
uniquePrReviews.add(activity.title);
}
}
if (!acc[date].types.includes(activity.type)) {
acc[date].types.push(activity.type);
Expand Down