mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-17 02:48:28 -07:00
Merge: - stats: fix crash
Close #1051 * commit '9ff39a362f83b94b685982efd62329bdd264eb21': - stats: fix crash
This commit is contained in:
commit
3862fa7659
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user