limit packet loss

This commit is contained in:
2023-11-15 21:57:20 +01:00
parent 6ae0cd2cbe
commit e992535fc1

2
rtt.go
View File

@@ -121,7 +121,7 @@ func (cp *ContinuousPinger) Stats(dSent, dReceive int) (*PingStats, error) {
}
}
ps.AvgRtt = time.Duration(sum / int64(pkgsInArr))
ps.PacketLoss = math.Min(100, 100-(float64(dReceive)/float64(dSent)*100))
ps.PacketLoss = math.Min(100, math.Max(100-(float64(dReceive)/float64(dSent)*100), 0))
stdDev, err := stats.StandardDeviation(rttArray)
if err != nil {
return nil, err