From 2bbe1b0813b38e592d1a9557c51d82d677f2f543 Mon Sep 17 00:00:00 2001 From: vivek Date: Thu, 4 Jan 2024 05:41:02 +0530 Subject: [PATCH 1/3] fix review count using set --- lib/api.ts | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/lib/api.ts b/lib/api.ts index cfce5f14..13246de6 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -100,9 +100,14 @@ export function getContributorBySlug(file: string, detail = false) { ...activityData, activity: [...activityData.activity, ...getSlackMessages(data.slack)], }; + let AllUnqPrReviews = new Set(); - const weightedActivity = activityData.activity.reduce( + let weightedActivity = activityData.activity.reduce( (acc, activity) => { + if (activity.type == "pr_reviewed") { + AllUnqPrReviews.add(activity.title); + } + return { activity: [ ...acc.activity, @@ -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: @@ -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, @@ -191,10 +197,27 @@ export function getCalendarData(activity: Activity[]) { }; } acc[date].count += 1; + + const uniquePrReviews = new Set(); + if (acc[date][activity.type]) { - acc[date][activity.type] += 1; + if ( + activity.type != "pr_reviewed" || + (activity.type == "pr_reviewed" && + uniquePrReviews.has(activity.title)) + ) { + 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); From b45124a35706357020ba74bd2ccffd9ec6e77eae Mon Sep 17 00:00:00 2001 From: vivek Date: Wed, 31 Jan 2024 17:53:54 +0530 Subject: [PATCH 2/3] test dp --- lib/api.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/api.ts b/lib/api.ts index 88e22d9f..205001f6 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -106,6 +106,7 @@ export function getContributorBySlug(file: string, detail = false) { let weightedActivity = activityData.activity.reduce( (acc, activity) => { if (activity.type == "pr_reviewed") { + AllUnqPrReviews.add(activity.title); } From 7b6149434a0f98065ccfdfb68789f2fe95ab2bd6 Mon Sep 17 00:00:00 2001 From: vivek Date: Wed, 31 Jan 2024 18:08:06 +0530 Subject: [PATCH 3/3] fix formatting --- lib/api.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/api.ts b/lib/api.ts index 205001f6..ea4a9a40 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -101,13 +101,12 @@ export function getContributorBySlug(file: string, detail = false) { ...activityData, activity: [...activityData.activity, ...getSlackMessages(data.slack)], }; - let AllUnqPrReviews = new Set(); + let allUnqPrReviews = new Set(); let weightedActivity = activityData.activity.reduce( (acc, activity) => { if (activity.type == "pr_reviewed") { - - AllUnqPrReviews.add(activity.title); + allUnqPrReviews.add(activity.title); } return { @@ -144,7 +143,7 @@ export function getContributorBySlug(file: string, detail = false) { } as Highlights & { activity: Activity[] }, ); - weightedActivity.pr_reviewed = AllUnqPrReviews.size; + weightedActivity.pr_reviewed = allUnqPrReviews.size; const calendarData = getCalendarData(weightedActivity.activity); @@ -222,7 +221,6 @@ export function getCalendarData(activity: Activity[]) { uniquePrReviews.has(activity.title)) ) { acc[date][activity.type] += 1; - } } else { if (