From 02c07aa96f6d5e3d646911ed431474edcf52c245 Mon Sep 17 00:00:00 2001 From: Bill Keenan Date: Tue, 26 Jun 2018 14:40:44 -0400 Subject: [PATCH 1/6] udpated config --- _sample_configs/bargraph_config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/_sample_configs/bargraph_config.yml b/_sample_configs/bargraph_config.yml index ffdf9fe5..c42a4dd5 100644 --- a/_sample_configs/bargraph_config.yml +++ b/_sample_configs/bargraph_config.yml @@ -11,7 +11,8 @@ wtf: mods: bargraph: enabled: true - graphIcon: "🍎" + starChar: "🍎" + stars: 20 position: top: 2 left: 0 From ae5ed9ee86e73203a8ea7e5f1cf191b144da1b9f Mon Sep 17 00:00:00 2001 From: Bill Keenan Date: Wed, 27 Jun 2018 14:15:16 -0400 Subject: [PATCH 2/6] added bargraph unit test --- wtf/bargraph.go | 25 ++++++++++++++-------- wtf_tests/bargraph/bargraph_test.go | 33 +++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 wtf_tests/bargraph/bargraph_test.go diff --git a/wtf/bargraph.go b/wtf/bargraph.go index 977f526f..7a1a5e9e 100644 --- a/wtf/bargraph.go +++ b/wtf/bargraph.go @@ -11,9 +11,10 @@ import ( //BarGraph lets make graphs type BarGraph struct { - enabled bool - focusable bool - + enabled bool + focusable bool + starChar string + maxStars int Name string RefreshedAt time.Time RefreshInt int @@ -27,9 +28,10 @@ type BarGraph struct { // NewBarGraph initialize your fancy new graph func NewBarGraph(name string, configKey string, focusable bool) BarGraph { widget := BarGraph{ - enabled: Config.UBool(fmt.Sprintf("wtf.mods.%s.enabled", configKey), false), - focusable: focusable, - + enabled: Config.UBool(fmt.Sprintf("wtf.mods.%s.enabled", configKey), false), + focusable: focusable, + starChar: Config.UString(fmt.Sprintf("wtf.mods.%s.graphIcon", configKey), name), + maxStars: Config.UInt(fmt.Sprintf("wtf.mods.%s.graphStars", configKey), 20), Name: Config.UString(fmt.Sprintf("wtf.mods.%s.title", configKey), name), RefreshInt: Config.UInt(fmt.Sprintf("wtf.mods.%s.refreshInterval", configKey)), } @@ -99,8 +101,14 @@ func (widget *BarGraph) addView() { // BuildBars will build a string of * to represent your data of [time][value] // time should be passed as a int64 -func (widget *BarGraph) BuildBars(maxStars int, starChar string, data [][2]int64) { +func (widget *BarGraph) BuildBars(data [][2]int64) { + widget.View.SetText(BuildStars(data, widget.maxStars, widget.starChar)) + +} + +//BuildStars build the string to display +func BuildStars(data [][2]int64, maxStars int, starChar string) string { var buffer bytes.Buffer //counter to inintialize min value @@ -158,8 +166,7 @@ func (widget *BarGraph) BuildBars(maxStars int, starChar string, data [][2]int64 buffer.WriteString(fmt.Sprintf("%s -\t [red]%s[white] - (%d)\n", t.Format("Jan 02, 2006"), stars, val)) } - widget.View.SetText(buffer.String()) - + return buffer.String() } /* -------------------- Exported Functions -------------------- */ diff --git a/wtf_tests/bargraph/bargraph_test.go b/wtf_tests/bargraph/bargraph_test.go new file mode 100644 index 00000000..3135c925 --- /dev/null +++ b/wtf_tests/bargraph/bargraph_test.go @@ -0,0 +1,33 @@ +package bargraphtests + +import ( + "testing" + + . "github.com/senorprogrammer/wtf/wtf" + . "github.com/stretchr/testify/assert" +) + +// MakeData - Create sample data +func makeData() [][2]int64 { + + //this could come from config + const lineCount = 2 + var stats [lineCount][2]int64 + + stats[0][1] = 1530122942 + stats[0][0] = 100 + + stats[1][1] = 1530132942 + stats[1][0] = 210 + + return stats[:] + +} + +//TestOutput of the bargraph make string (BuildStars) function +func TestOutput(t *testing.T) { + + result := BuildStars(makeData(), 20, "*") + + Equal(t, result, "Jan 18, 1970 -\t [red]*[white] - (100)\nJan 18, 1970 -\t [red]********************[white] - (210)\n") +} From 6c09935e56a581a41d21c5620ecfe9f9712d363a Mon Sep 17 00:00:00 2001 From: Bill Keenan Date: Wed, 27 Jun 2018 14:33:22 -0400 Subject: [PATCH 3/6] fixing bad merge --- bargraph/widget.go | 3 +-- wtf/bargraph.go | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/bargraph/widget.go b/bargraph/widget.go index b5b9d9ff..7863f81d 100644 --- a/bargraph/widget.go +++ b/bargraph/widget.go @@ -50,8 +50,7 @@ func MakeGraph(widget *Widget) { } - icon := wtf.Config.UString("wtf.mods.bargraph.graphIcon", "✭ ") - widget.BarGraph.BuildBars(20, icon, stats[:]) + widget.BarGraph.BuildBars(stats[:]) } diff --git a/wtf/bargraph.go b/wtf/bargraph.go index 7a1a5e9e..5ec057d7 100644 --- a/wtf/bargraph.go +++ b/wtf/bargraph.go @@ -144,7 +144,7 @@ func BuildStars(data [][2]int64, maxStars int, starChar string) string { } // each number = how many stars? - var starRatio = float64(maxStars) / float64((maxValue - minValue)) + var starRatio = float64(widget.maxStars) / float64((maxValue - minValue)) //build the stars for i := range data { @@ -157,7 +157,7 @@ func BuildStars(data [][2]int64, maxStars int, starChar string) string { starCount = 1 } //build the actual string - var stars = strings.Repeat(starChar, starCount) + var stars = strings.Repeat(widget.starChar, starCount) //parse the time var t = time.Unix(int64(data[i][1]/1000), 0) From ac9c44d322ea5d656a04a8311e302c50827ef6d3 Mon Sep 17 00:00:00 2001 From: Bill Keenan Date: Wed, 27 Jun 2018 14:35:13 -0400 Subject: [PATCH 4/6] ugh this config --- _sample_configs/bargraph_config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_sample_configs/bargraph_config.yml b/_sample_configs/bargraph_config.yml index c42a4dd5..9b321a42 100644 --- a/_sample_configs/bargraph_config.yml +++ b/_sample_configs/bargraph_config.yml @@ -11,8 +11,8 @@ wtf: mods: bargraph: enabled: true - starChar: "🍎" - stars: 20 + starChar: "👿" + stars: 25 position: top: 2 left: 0 From 85dd41bf452aa80308ece4649c75b7cc151132ba Mon Sep 17 00:00:00 2001 From: Bill Keenan Date: Wed, 27 Jun 2018 14:44:51 -0400 Subject: [PATCH 5/6] fix bad merge --- wtf/bargraph.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wtf/bargraph.go b/wtf/bargraph.go index 5ec057d7..7a1a5e9e 100644 --- a/wtf/bargraph.go +++ b/wtf/bargraph.go @@ -144,7 +144,7 @@ func BuildStars(data [][2]int64, maxStars int, starChar string) string { } // each number = how many stars? - var starRatio = float64(widget.maxStars) / float64((maxValue - minValue)) + var starRatio = float64(maxStars) / float64((maxValue - minValue)) //build the stars for i := range data { @@ -157,7 +157,7 @@ func BuildStars(data [][2]int64, maxStars int, starChar string) string { starCount = 1 } //build the actual string - var stars = strings.Repeat(widget.starChar, starCount) + var stars = strings.Repeat(starChar, starCount) //parse the time var t = time.Unix(int64(data[i][1]/1000), 0) From 578470c348354e3937052a064f06e9464db045bf Mon Sep 17 00:00:00 2001 From: Bill Keenan Date: Wed, 27 Jun 2018 14:48:52 -0400 Subject: [PATCH 6/6] add subdirectory testing --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b20b9c4a..05f6591d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,4 +9,4 @@ before_install: - export TRAVIS_BUILD_DIR=$HOME/gopath/src/github.com/senorprogrammer/wtf - cd $HOME/gopath/src/github.com/senorprogrammer/wtf -script: go get ./... && go get github.com/go-test/deep && go test -v github.com/senorprogrammer/wtf/wtf_tests +script: go get ./... && go get github.com/go-test/deep && go test -v github.com/senorprogrammer/wtf/wtf_tests/...