From c5e9dcd2c684421417e1f6f5fefca6700521c0f5 Mon Sep 17 00:00:00 2001 From: stephen mcquay Date: Thu, 25 Feb 2016 22:54:18 -0800 Subject: [PATCH] removed sparkline --- bps.go | 54 -------------------------------------------- bps_test.go | 65 ----------------------------------------------------- 2 files changed, 119 deletions(-) diff --git a/bps.go b/bps.go index 02b6e96..f3a7694 100644 --- a/bps.go +++ b/bps.go @@ -45,15 +45,6 @@ func New(interval time.Duration) (*BPS, error) { return NewPrecise(interval, 100) } -// MustNew behaves like New, but panics on error. -func MustNew(interval time.Duration) *BPS { - b, err := New(interval) - if err != nil { - panic(err) - } - return b -} - // NewPrecise behaves like New, but allows the user to specify the temporal // resolution. // @@ -131,51 +122,6 @@ func (b *BPS) HumanRate() string { return human(uint64(b.Rate())) + "/s" } -// Sparkline returns a human-friendly sprakline of history -func (b *BPS) Sparkline(count int) string { - if count <= 0 || count > len(b.buckets) { - return "bucket count inappropriate" - } - sparks := []string{"▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"} - line := "" - bucketsPer := len(b.buckets) / count - b.Lock() - defer b.Unlock() - - var max int64 - var cur int64 - - // find max - for i := 0; i < len(b.buckets); i++ { - cur += b.buckets[i] - if i%bucketsPer == 0 { - if cur > max { - max = cur - } - cur = 0 - } - } - - if max == 0 { - for i := 0; i < count; i++ { - line += sparks[0] - } - return line - } - - cur = 0 - for i := 0; i < len(b.buckets); i++ { - val := b.buckets[(b.timeI+i)%len(b.buckets)] - cur += val - if i%bucketsPer == 0 { - approx := int((float64(cur) / float64(max)) * float64(len(sparks)-1)) - line += sparks[approx] - cur = 0 - } - } - return line -} - // Close cleans up and shuts down a BPS. func (b *BPS) Close() { close(b.quit) diff --git a/bps_test.go b/bps_test.go index 45af758..9245227 100644 --- a/bps_test.go +++ b/bps_test.go @@ -93,68 +93,3 @@ func TestHumanBytes(t *testing.T) { t.Fatalf("did not get right human rate; got %v, want %v", got, want) } } - -// TestSparkBadBucketCounts just makes sure that bad inputs are reported -func TestSparkBadBucketCounts(t *testing.T) { - bw := BPS{ - buckets: make([]int64, 10), - } - sizes := []int{-10, -1, 0, 11, 12, 100, 1000} - for _, size := range sizes { - got := bw.Sparkline(size) - want := "bucket count inappropriate" - if got != want { - t.Fatalf("got: %v, want: %v", got, want) - } - } -} - -// TestSparkline just creates a simple BPS and traverses all reasonable count -// sizes. It's primarily a test for panics which plagued us early on. -func TestSparkline(t *testing.T) { - buckets := 20 - bw := BPS{ - buckets: make([]int64, buckets), - } - - t.Logf("all 0") - for i := 0; i < buckets; i++ { - bw.buckets[i] = 0 - } - for i := 1; i < buckets; i++ { - line := bw.Sparkline(i) - t.Logf("count: %d, len %d: %+v", i, len([]rune(line)), line) - } - - t.Logf("increasing") - for i := 0; i < buckets; i++ { - bw.buckets[i] = int64(i * buckets) - } - for i := 1; i < buckets; i++ { - line := bw.Sparkline(i) - t.Logf("count: %d, len %d: %+v", i, len([]rune(line)), line) - } - - t.Logf("decreasing") - for i := 0; i < buckets; i++ { - bw.buckets[i] = int64((buckets - i) * buckets) - } - for i := 1; i < buckets; i++ { - line := bw.Sparkline(i) - t.Logf("count: %d, len %d: %+v", i, len([]rune(line)), line) - } -} - -func TestSparkRandom(t *testing.T) { - buckets := 20 - bw := BPS{ - buckets: make([]int64, buckets), - } - bw.buckets[3] = 100 - t.Logf("%+v", bw.Sparkline(10)) - bw.buckets[7] = 300 - for i := 1; i < buckets; i++ { - line := bw.Sparkline(i) - t.Logf("count: %d, len: %d: %+v", i, len([]rune(line)), line) - } -}