Take the cable zero from the shortest delay seen rather than a flag

This commit is contained in:
flamingcow
2026-07-26 09:43:03 -07:00
parent e77574712d
commit 4d102f377e
2 changed files with 18 additions and 16 deletions
+13 -9
View File
@@ -34,18 +34,20 @@ type cableStats struct {
mu sync.Mutex
min int64
samples uint64
floor int64
txPend map[uint64]int64
rxPend map[uint64]int64
}
type cableView struct {
min int64
samples uint64
min int64
floor int64
ok bool
}
func (v cableView) minText() string {
if v.samples == 0 {
if !v.ok {
return "-"
}
return commasInt(v.min)
@@ -57,15 +59,14 @@ func (c config) cableMetres(views []view) (float64, bool) {
if len(views) == 0 {
return 0, false
}
var sum float64
var excess float64
for _, v := range views {
if v.cable.samples == 0 {
if !v.cable.ok {
return 0, false
}
sum += float64(v.cable.min)
excess += float64(v.cable.min - v.cable.floor)
}
mean := sum / float64(len(views))
return (mean - c.zeroNS) / c.nsPerM, true
return excess / float64(len(views)) / c.nsPerM, true
}
func (c config) cableText(views []view) string {
@@ -114,13 +115,16 @@ func (c *cableStats) put(seq uint64, ts int64, tx bool) {
if c.samples == 0 || delta < c.min {
c.min = delta
}
if c.floor == 0 || delta < c.floor {
c.floor = delta
}
c.samples++
}
func (c *cableStats) view() cableView {
c.mu.Lock()
defer c.mu.Unlock()
return cableView{c.min, c.samples}
return cableView{c.min, c.floor, c.samples > 0}
}
func (c *cableStats) reset() {