Skip to content

Commit

Permalink
Tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
irees committed Jan 17, 2025
1 parent e71f644 commit 70c7ac3
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions stats/fvsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,32 @@ import (
)

func ServiceLevelDaysMaxWindow(fvsls []dmfr.FeedVersionServiceLevel, startDate time.Time, endDate time.Time, windowSize int) (time.Time, time.Time, int) {
// Requires window size > 0
if windowSize < 1 {
windowSize = 1
}
i := 0
window := make([]int, windowSize)
windowSeconds := 0
windowStart := startDate
windowEnd := startDate
for d, slevel := range ServiceLevelDays(fvsls, startDate, endDate) {
// fmt.Println("d:", d, "slevel:", slevel)
window[i%windowSize] = slevel

i := 0
window := make([]int, windowSize)
for serviceDate, serviceLevel := range ServiceLevelDays(fvsls, startDate, endDate) {
// Overwrite window position
window[i%windowSize] = serviceLevel
i++

// Calculate window total
tot := 0
for _, v := range window {
tot += v
}
// fmt.Println("\twindow:", window, "tot:", tot)

// Update max window
if tot >= windowSeconds {
windowSeconds = tot
windowEnd = d
windowStart = d.AddDate(0, 0, -windowSize+1)
windowEnd = serviceDate
windowStart = serviceDate.AddDate(0, 0, -windowSize+1)
}
}
return windowStart, windowEnd, windowSeconds
Expand Down

0 comments on commit 70c7ac3

Please sign in to comment.