Skip to content

Commit ff17681

Browse files
Merge pull request #94 from rahul-vyas-dev/fix/repo-count
fix: update analytical model to include total repositories and adjust…
2 parents 5688e69 + 079eab6 commit ff17681

4 files changed

Lines changed: 29 additions & 15 deletions

File tree

src/context/AppContext.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ export function AppProvider({ children }) {
8686
);
8787

8888
setTotalRepo(total);
89+
const totalReposPerOrg = Object.fromEntries(
90+
Object.entries(reposPerOrg).map(([org, repos]) => [
91+
org,
92+
[...repos], // copy each array
93+
])
94+
);
8995

9096
setLoadMsg('Fetching contributor data for top repositories...')
9197
const contribsPerRepo = {}
@@ -100,7 +106,7 @@ export function AppProvider({ children }) {
100106
}
101107

102108
setLoadMsg('Building analytical data model...')
103-
setModel(buildAnalyticalModel(validOrgs, reposPerOrg, contribsPerRepo))
109+
setModel(buildAnalyticalModel(validOrgs, reposPerOrg, contribsPerRepo, totalReposPerOrg))
104110

105111

106112
// Save to recent searches

src/pages/OverviewPage.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ export default function OverviewPage() {
3030

3131
if (!model) return null
3232

33-
const { allRepos } = model
33+
const { totalRepos } = model
3434
const isMulti = orgs.length > 1
35-
const totalStars = allRepos.reduce((s, r) => s + r.stargazers_count, 0)
36-
const totalForks = allRepos.reduce((s, r) => s + r.forks_count, 0)
37-
const activeRepos = allRepos.filter(r => r.activityClassification === 'Thriving' || r.activityClassification === 'Active').length
35+
const totalStars = totalRepos.reduce((s, r) => s + r.stargazers_count, 0)
36+
const totalForks = totalRepos.reduce((s, r) => s + r.forks_count, 0)
37+
const activeRepos = totalRepos.filter(r => r.activityClassification === 'Thriving' || r.activityClassification === 'Active').length
3838

3939
const langMap = {}
40-
allRepos.forEach(r => { if (r.language) langMap[r.language] = (langMap[r.language] || 0) + 1 })
40+
totalRepos.forEach(r => { if (r.language) langMap[r.language] = (langMap[r.language] || 0) + 1 })
4141
const langs = Object.entries(langMap).sort((a, b) => b[1] - a[1]).slice(0, 7)
4242
const langTotal = langs.reduce((s, [, c]) => s + c, 0)
4343

44-
const topRepos = [...allRepos].sort((a, b) => b.healthScore - a.healthScore).slice(0, 5)
44+
const topRepos = [...totalRepos].sort((a, b) => b.healthScore - a.healthScore).slice(0, 5)
4545

4646
const NavCard = ({ to, label, sub }) => (
4747
<div

src/pages/RepositoriesPage.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default function RepositoriesPage() {
3636
}, [])
3737

3838
const navigate = useNavigate()
39-
const allRepos = model?.allRepos ?? []
39+
const allRepos = model?.totalRepos ?? []
4040

4141
const langs = useMemo(() =>
4242
['All Languages', ...new Set(allRepos.map(r => r.language).filter(Boolean))].slice(0, 10),

src/services/analytics.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,28 @@ export function computeBusFactor(contributors = []) {
3737
// Unified Analytical Data Model
3838
// Merges multiple orgs into one normalized graph:
3939
// Organization → Repositories → Contributors → Issues/PRs
40-
export function buildAnalyticalModel(orgs, reposPerOrg, contribsPerRepo) {
40+
export function buildAnalyticalModel(orgs, reposPerOrg, contribsPerRepo, totalReposPerOrg) {
4141
const allRepos = []
4242
const contributorMap = {}
43+
const totalRepos = [];
4344

4445
orgs.forEach(org => {
4546
const repos = reposPerOrg[org.login] || []
47+
const total = totalReposPerOrg[org.login] || [];
48+
49+
total.forEach(repo => {
50+
const key = `${org.login}/${repo.name}`
51+
const contribs = contribsPerRepo[key] || []
52+
const health = computeHealthScore(repo, contribs.length)
53+
const activityClassification = computeActivityClassification(repo)
54+
const bf = computeBusFactor(contribs)
55+
totalRepos.push({ ...repo, orgLogin: org.login, contributors: contribs, healthScore: health, activityClassification: activityClassification, busFactor: bf })
56+
})
4657

4758
repos.forEach(repo => {
48-
const key = `${org.login}/${repo.name}`
59+
const key = `${org.login}/${repo.name}`
4960
const contribs = contribsPerRepo[key] || []
50-
const health = computeHealthScore(repo, contribs.length)
51-
const activityClassification = computeActivityClassification(repo)
52-
const bf = computeBusFactor(contribs)
53-
allRepos.push({ ...repo, orgLogin: org.login, contributors: contribs, healthScore: health, activityClassification: activityClassification, busFactor: bf })
61+
allRepos.push({ ...repo, orgLogin: org.login });
5462

5563
// Build contributor map — deduplicated by login across orgs
5664
contribs.forEach(c => {
@@ -87,7 +95,7 @@ export function buildAnalyticalModel(orgs, reposPerOrg, contribsPerRepo) {
8795
})).sort((a, b) => b.totalContribs - a.totalContribs)
8896

8997
// Graph is constructed here and persisted through cache layers
90-
return { allRepos, contributors }
98+
return { allRepos, contributors, totalRepos }
9199
}
92100

93101
// Time-Series Bucketing

0 commit comments

Comments
 (0)