diff --git a/stats/stats_test.go b/stats/stats_test.go index 4b2a8750..f540e7cb 100644 --- a/stats/stats_test.go +++ b/stats/stats_test.go @@ -124,3 +124,31 @@ func TestLargeNumbers(t *testing.T) { s.Close() os.Remove(conf.Filename) } + +// this code is a chunk copied from getData() that generates aggregate data per day +func aggregateDataPerDay(firstID uint32) int { + firstDayID := (firstID + 24 - 1) / 24 * 24 // align_ceil(24) + a := []uint64{} + var sum uint64 + id := firstDayID + nextDayID := firstDayID + 24 + for i := firstDayID - firstID; int(i) != 720; i++ { + sum++ + if id == nextDayID { + a = append(a, sum) + sum = 0 + nextDayID += 24 + } + id++ + } + if id <= nextDayID { + a = append(a, sum) + } + return len(a) +} +func TestAggregateDataPerTimeUnit(t *testing.T) { + for i := 0; i != 25; i++ { + alen := aggregateDataPerDay(uint32(i)) + assert.True(t, alen == 30, "i=%d", i) + } +} diff --git a/stats/stats_unit.go b/stats/stats_unit.go index 0bedb334..1d524bcc 100644 --- a/stats/stats_unit.go +++ b/stats/stats_unit.go @@ -551,7 +551,7 @@ func (s *statsCtx) getData(timeUnit TimeUnit) map[string]interface{} { } id++ } - if id < nextDayID { + if id <= nextDayID { a = append(a, sum) } if len(a) != int(s.limit/24) { @@ -578,7 +578,7 @@ func (s *statsCtx) getData(timeUnit TimeUnit) map[string]interface{} { } id++ } - if id < nextDayID { + if id <= nextDayID { a = append(a, sum) } } @@ -602,7 +602,7 @@ func (s *statsCtx) getData(timeUnit TimeUnit) map[string]interface{} { } id++ } - if id < nextDayID { + if id <= nextDayID { a = append(a, sum) } } @@ -626,7 +626,7 @@ func (s *statsCtx) getData(timeUnit TimeUnit) map[string]interface{} { } id++ } - if id < nextDayID { + if id <= nextDayID { a = append(a, sum) } }