Skip to content

Commit

Permalink
Merge pull request #39 from withgraphite/01-23-fix_active_time_calcul…
Browse files Browse the repository at this point in the history
…ations

fix: active time calculations
  • Loading branch information
shampliu authored Jan 23, 2025
2 parents ee67587 + da8978c commit 2ee8c60
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions lib/utils/records.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ export const findMostActiveTimes = (weeks: Week[]) => {

weeks.forEach(w => {
w.contributionDays.forEach(d => {
const date = new Date(d.date)

const dayOfWeek = date.getDay()
const month = date.getMonth()
const dayOfWeek = d.weekday as number
const month = Number(d.date.split('-')[1]) - 1

dayOfWeekContributions[dayOfWeek] += d.contributionCount

Expand All @@ -62,11 +60,8 @@ export const findMostActiveTimes = (weeks: Week[]) => {
})

// Find most active day
const avgDayContributions = dayOfWeekContributions.map((count, i) =>
dayOfWeekTotals[i] ? Math.round(count / dayOfWeekTotals[i]) : 0
)
const maxDayIndex = avgDayContributions.indexOf(
Math.max(...avgDayContributions)
const maxDayIndex = dayOfWeekContributions.indexOf(
Math.max(...dayOfWeekContributions)
)

// Find most active month
Expand All @@ -86,7 +81,7 @@ export const findMostActiveTimes = (weeks: Week[]) => {
{
title: 'Most Active Day',
value: DAYS[maxDayIndex],
subtitle: `Avg. ${avgDayContributions[maxDayIndex]} contributions`,
subtitle: `${dayOfWeekContributions[maxDayIndex]} contributions`,
icon: <Clock className='w-[16px] text-violet-500' />
}
]
Expand Down

0 comments on commit 2ee8c60

Please sign in to comment.