1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

fix: empty projects (resolve #197)

fix: potential division by zero (see #199)
This commit is contained in:
Ferdinand Mütsch 2021-05-03 21:32:26 +02:00
parent cf3d293688
commit f3b738b250
2 changed files with 5 additions and 4 deletions

View File

@ -31,9 +31,6 @@ type StatsData struct {
func NewStatsFrom(summary *models.Summary, filters *models.Filters) *StatsViewModel { func NewStatsFrom(summary *models.Summary, filters *models.Filters) *StatsViewModel {
totalTime := summary.TotalTime() totalTime := summary.TotalTime()
numDays := int(summary.ToTime.T().Sub(summary.FromTime.T()).Hours() / 24) numDays := int(summary.ToTime.T().Sub(summary.FromTime.T()).Hours() / 24)
if math.IsInf(float64(numDays), 0) {
numDays = 0
}
data := &StatsData{ data := &StatsData{
Username: summary.UserID, Username: summary.UserID,
@ -45,6 +42,10 @@ func NewStatsFrom(summary *models.Summary, filters *models.Filters) *StatsViewMo
DaysIncludingHolidays: numDays, DaysIncludingHolidays: numDays,
} }
if math.IsInf(data.DailyAverage, 0) || math.IsNaN(data.DailyAverage) {
data.DailyAverage = 0
}
editors := make([]*SummariesEntry, len(summary.Editors)) editors := make([]*SummariesEntry, len(summary.Editors))
for i, e := range summary.Editors { for i, e := range summary.Editors {
editors[i] = convertEntry(e, summary.TotalTimeBy(models.SummaryEditor)) editors[i] = convertEntry(e, summary.TotalTimeBy(models.SummaryEditor))

View File

@ -9,7 +9,7 @@ func StringsToSet(slice []string) map[string]bool {
} }
func SetToStrings(set map[string]bool) []string { func SetToStrings(set map[string]bool) []string {
slice := make([]string, len(set)) slice := make([]string, 0, len(set))
for k := range set { for k := range set {
slice = append(slice, k) slice = append(slice, k)
} }