parent
e59acd16c6
commit
97fc3b9046
1 changed files with 9 additions and 2 deletions
|
@ -214,7 +214,10 @@ func (acc *Account) averageLoop() {
|
||||||
acc.values.mu.Lock()
|
acc.values.mu.Lock()
|
||||||
// Add average of last second.
|
// Add average of last second.
|
||||||
elapsed := now.Sub(acc.values.lpTime).Seconds()
|
elapsed := now.Sub(acc.values.lpTime).Seconds()
|
||||||
avg := float64(acc.values.lpBytes) / elapsed
|
avg := 0.0
|
||||||
|
if elapsed > 0 {
|
||||||
|
avg = float64(acc.values.lpBytes) / elapsed
|
||||||
|
}
|
||||||
// Soft start the moving average
|
// Soft start the moving average
|
||||||
if period < averagePeriod {
|
if period < averagePeriod {
|
||||||
period++
|
period++
|
||||||
|
@ -442,7 +445,11 @@ func (acc *Account) speed() (bps, current float64) {
|
||||||
}
|
}
|
||||||
// Calculate speed from first read.
|
// Calculate speed from first read.
|
||||||
total := float64(time.Now().Sub(acc.values.start)) / float64(time.Second)
|
total := float64(time.Now().Sub(acc.values.start)) / float64(time.Second)
|
||||||
|
if total > 0 {
|
||||||
bps = float64(acc.values.bytes) / total
|
bps = float64(acc.values.bytes) / total
|
||||||
|
} else {
|
||||||
|
bps = 0.0
|
||||||
|
}
|
||||||
current = acc.values.avg
|
current = acc.values.avg
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue