Skip to content

Commit

Permalink
mean -> median
Browse files Browse the repository at this point in the history
Summary: Make t3lurid3 happy

Reviewed By: deathowl

Differential Revision: D64596575

fbshipit-source-id: 1398d9d1dca9a94746ca46718ac96548f5ec1ed3
  • Loading branch information
leoleovich authored and facebook-github-bot committed Oct 18, 2024
1 parent 85e49df commit d007a8c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions cmd/ntpcheck/checker/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type NTPStats struct {
StatError bool `json:"ntp.stat.error"` // error reported in Leap Status
Correction float64 `json:"ntp.correction"` // current correction
PeerCount int `json:"ntp.peer.count"` // number of upstream peers
OffsetComparedToPeers float64 `json:"ntp.sys.offset_selected_vs_peers_ms"` // sys peer offset vs mean peer offset in ms
OffsetComparedToPeers float64 `json:"ntp.sys.offset_selected_vs_peers_ms"` // sys peer offset vs median peer offset in ms
}

type averages struct {
Expand Down Expand Up @@ -84,7 +84,7 @@ func peersAverages(peers []*Peer) (*averages, error) {
}, nil
}

func meanOffset(peers []*Peer) float64 {
func medianOffset(peers []*Peer) float64 {
offsets := []float64{}
for _, p := range peers {
offsets = append(offsets, p.Offset)
Expand Down Expand Up @@ -135,7 +135,7 @@ func NewNTPStats(r *NTPCheckResult) (*NTPStats, error) {
peerAvgs, err := peersAverages(okPeers)
if err == nil {
log.Debugf("Sys Offset: %v, Avg Peer Offset: %v", time.Duration(offset*float64(time.Millisecond)), time.Duration(peerAvgs.offset*float64(time.Millisecond)))
offsetComparedToPeers = math.Abs(math.Abs(offset) - math.Abs(meanOffset(okPeers)))
offsetComparedToPeers = math.Abs(math.Abs(offset) - math.Abs(medianOffset(okPeers)))
}
}
output := NTPStats{
Expand Down
6 changes: 3 additions & 3 deletions cmd/ntpcheck/checker/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func TestNTPStatsWithSysPeerAndNoSelect(t *testing.T) {
require.Equal(t, want, stats)
}

func TestMeanOffset(t *testing.T) {
func TestMedianOffset(t *testing.T) {
peers := []*Peer{
0: {Offset: 1},
1: {Offset: 2},
Expand All @@ -206,6 +206,6 @@ func TestMeanOffset(t *testing.T) {
5: {Offset: 6},
6: {Offset: 100500},
}
meanOffset := meanOffset(peers)
require.Equal(t, float64(4), meanOffset)
medianOffset := medianOffset(peers)
require.Equal(t, float64(4), medianOffset)
}

0 comments on commit d007a8c

Please sign in to comment.