Skip to content

Commit

Permalink
Guard avg monthly and yearly messages
Browse files Browse the repository at this point in the history
  • Loading branch information
f-ewald committed May 28, 2022
1 parent 7208064 commit 43cfcbd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,14 @@ func (db *Database) Statistics(ctx context.Context) (stats *Statistics, err erro
stats.AvgDailyMessages = float64(stats.TotalMessages) / totalDays

totalMonths := monthsSince(stats.FirstMessage, stats.LastMessage)
stats.AvgMonthlyMessages = float64(stats.TotalMessages) / float64(totalMonths)
if totalMonths > 0 {
stats.AvgMonthlyMessages = float64(stats.TotalMessages) / float64(totalMonths)
}

totalYears := yearsSince(stats.FirstMessage, stats.LastMessage)
stats.AvgYearlyMessages = float64(stats.TotalMessages) / float64(totalYears)
if totalYears > 0 {
stats.AvgYearlyMessages = float64(stats.TotalMessages) / float64(totalYears)
}

return stats, nil
}
Expand Down

0 comments on commit 43cfcbd

Please sign in to comment.