From bd557cbeb752c6296f3a74cc2c7aea5c13bb55fa Mon Sep 17 00:00:00 2001 From: Nick White Date: Wed, 28 Aug 2019 22:40:02 +0100 Subject: Add medium and bad lines to graphs --- bookpipeline/graph.go | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/bookpipeline/graph.go b/bookpipeline/graph.go index 4386218..67deb33 100644 --- a/bookpipeline/graph.go +++ b/bookpipeline/graph.go @@ -9,10 +9,13 @@ import ( "strings" "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/drawing" ) const maxticks = 20 -const cutoff = 70 +const goodCutoff = 70 +const mediumCutoff = 65 +const badCutoff = 60 type Conf struct { Path, Code string @@ -23,6 +26,22 @@ type GraphConf struct { Pgnum, Conf float64 } +func createLine(xvalues []float64, y float64, c drawing.Color) chart.ContinuousSeries { + var yvalues []float64 + for _ = range xvalues { + yvalues = append(yvalues, y) + } + return chart.ContinuousSeries{ + XValues: xvalues, + YValues: yvalues, + Style: chart.Style{ + Show: true, + StrokeColor: c, + StrokeDashArray: []float64{10.0, 5.0}, + }, + } +} + func Graph(confs map[string]*Conf, bookname string, w io.Writer) error { // Organise confs to sort them by page var graphconf []GraphConf @@ -54,7 +73,7 @@ func Graph(confs map[string]*Conf, bookname string, w io.Writer) error { i = i + 1 xvalues = append(xvalues, c.Pgnum) yvalues = append(yvalues, c.Conf) - if c.Conf < cutoff { + if c.Conf < goodCutoff { annotations = append(annotations, chart.Value2{Label: fmt.Sprintf("%.0f", c.Pgnum), XValue: c.Pgnum, YValue: c.Conf}) } if tickevery % i == 0 { @@ -66,20 +85,10 @@ func Graph(confs map[string]*Conf, bookname string, w io.Writer) error { YValues: yvalues, } - // Create 70% line - yvalues = []float64{} - for _ = range xvalues { - yvalues = append(yvalues, cutoff) - } - cutoffSeries := chart.ContinuousSeries{ - XValues: xvalues, - YValues: yvalues, - Style: chart.Style{ - Show: true, - StrokeColor: chart.ColorAlternateGreen, - StrokeDashArray: []float64{10.0, 5.0}, - }, - } + // Create lines + goodCutoffSeries := createLine(xvalues, goodCutoff, chart.ColorAlternateGreen) + mediumCutoffSeries := createLine(xvalues, mediumCutoff, chart.ColorOrange) + badCutoffSeries := createLine(xvalues, badCutoff, chart.ColorRed) // Create lines marking top and bottom 10% confidence sort.Slice(graphconf, func(i, j int) bool { return graphconf[i].Conf < graphconf[j].Conf }) @@ -139,7 +148,9 @@ func Graph(confs map[string]*Conf, bookname string, w io.Writer) error { mainSeries, minSeries, maxSeries, - cutoffSeries, + goodCutoffSeries, + mediumCutoffSeries, + badCutoffSeries, chart.AnnotationSeries{ Annotations: annotations, }, -- cgit v1.2.1-24-ge1ad