Skip to content

Commit b2e6fe0

Browse files
feat: enhanced the top repo calculation matric based on new formula for without PAT
1 parent a19424d commit b2e6fe0

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

src/context/AppContext.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createContext, useContext, useState, useCallback } from 'react'
22
import { fetchOrg, fetchRepos, fetchContributors, fetchIssues, fetchRateLimit } from '../services/github'
3-
import { buildAnalyticalModel } from '../services/analytics'
3+
import { buildAnalyticalModel, getTopRepositories } from '../services/analytics'
44

55
const Ctx = createContext(null)
66

@@ -39,9 +39,7 @@ export function AppProvider({ children }) {
3939
setLoadMsg('Fetching contributor data for top repositories...')
4040
const contribsPerRepo = {}
4141
for (const org of validOrgs) {
42-
const top = (reposPerOrg[org.login] || [])
43-
.sort((a, b) => b.stargazers_count - a.stargazers_count)
44-
.slice(0, 10)
42+
const top = getTopRepositories(reposPerOrg[org.login] || [], 10);
4543
await Promise.allSettled(top.map(async repo => {
4644
contribsPerRepo[`${org.login}/${repo.name}`] = await fetchContributors(org.login, repo.name, pat)
4745
}))

src/services/analytics.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,28 @@ export function exportTrendsCSV(series) {
168168
const rows = series.map(s => [s.date, s.prs_created, s.prs_merged, s.prs_closed, s.issues_created, s.issues_closed])
169169
download([header, ...rows].map(r => r.join(',')).join('\n'), 'orgexplorer-trends.csv')
170170
}
171+
172+
export function getTopRepositories(repos, limit = 10) {
173+
const MS_PER_DAY = 1000 * 60 * 60 * 24;
174+
175+
return [...repos]
176+
.map(repo => {
177+
const daysSinceLastPush =
178+
(Date.now() - new Date(repo.pushed_at).getTime()) / MS_PER_DAY;
179+
180+
const activityBonus = 0.5 * Math.max(0, 365 - daysSinceLastPush);
181+
182+
const score =
183+
repo.stargazers_count +
184+
repo.forks_count * 2 +
185+
repo.watchers_count * 1.5 +
186+
activityBonus;
187+
188+
return {
189+
...repo,
190+
score,
191+
};
192+
})
193+
.sort((a, b) => b.score - a.score)
194+
.slice(0, limit);
195+
}

0 commit comments

Comments
 (0)