From 31a610fd23cc4f41d677a70353460085dbf20572 Mon Sep 17 00:00:00 2001 From: Nick White Date: Mon, 6 Dec 2021 11:48:30 +0000 Subject: graph: make number page parsing much more robust, and ensure fake numbers are used to create a coherant graph if any page numbers cannot be found from file names --- graph.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'graph.go') diff --git a/graph.go b/graph.go index 5d6068a..02ad8a8 100644 --- a/graph.go +++ b/graph.go @@ -63,14 +63,24 @@ func GraphOpts(confs map[string]*Conf, bookname string, xaxis string, guidelines var graphconf []GraphConf for _, conf := range confs { name := filepath.Base(conf.Path) - var numend int - numend = strings.Index(name, "_") + numend := strings.Index(name, "_bin") if numend == -1 { numend = strings.Index(name, ".") } - pgnum, err := strconv.ParseFloat(name[0:numend], 64) + // cancel this process if and rely on fake number version + // below if there can't be a 4 digit number before _bin + if numend < 4 { + graphconf = []GraphConf{} + break + } + numstart := numend - 4 + + pgnum, err := strconv.ParseFloat(name[numstart:numend], 64) + // if any page numbers can't be parsed, cancel this + // and rely on the fake number version below if err != nil { - continue + graphconf = []GraphConf{} + break } var c GraphConf c.Pgnum = pgnum @@ -79,7 +89,8 @@ func GraphOpts(confs map[string]*Conf, bookname string, xaxis string, guidelines } // If we failed to get any page numbers, just fake the lot - if len(graphconf) == 0 { + if len(graphconf) < 2 { + graphconf = []GraphConf{} i := float64(1) for _, conf := range confs { var c GraphConf -- cgit v1.2.1-24-ge1ad