MCPcopy
hub / github.com/npmx-dev/npmx.dev / buildContributorCounts

Function buildContributorCounts

app/composables/useCharts.ts:188–216  ·  view source on GitHub ↗
(stats: GitHubContributorStats[])

Source from the content-addressed store, hash-verified

186}
187
188function buildContributorCounts(stats: GitHubContributorStats[]) {
189 const weeklyCounts = new Map<number, number>()
190 const monthlyCounts = new Map<string, number>()
191 const yearlyCounts = new Map<string, number>()
192
193 for (const contributor of stats ?? []) {
194 const monthSet = new Set<string>()
195 const yearSet = new Set<string>()
196
197 for (const week of contributor?.weeks ?? []) {
198 if (!week || week.c <= 0) continue
199
200 weeklyCounts.set(week.w, (weeklyCounts.get(week.w) ?? 0) + 1)
201
202 const weekStartDate = new Date(week.w * 1000)
203 monthSet.add(toIsoMonthKey(weekStartDate))
204 yearSet.add(String(weekStartDate.getUTCFullYear()))
205 }
206
207 for (const key of monthSet) {
208 monthlyCounts.set(key, (monthlyCounts.get(key) ?? 0) + 1)
209 }
210 for (const key of yearSet) {
211 yearlyCounts.set(key, (yearlyCounts.get(key) ?? 0) + 1)
212 }
213 }
214
215 return { weeklyCounts, monthlyCounts, yearlyCounts }
216}
217
218async function fetchDailyRangeCached(packageName: string, startIso: string, endIso: string) {
219 const cache = npmDailyRangeCache

Callers 1

Calls 3

toIsoMonthKeyFunction · 0.85
setMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected