diff options
author | Nick White <git@njw.name> | 2021-12-06 11:48:30 +0000 |
---|---|---|
committer | Nick White <git@njw.name> | 2021-12-06 11:48:30 +0000 |
commit | 31a610fd23cc4f41d677a70353460085dbf20572 (patch) | |
tree | e90fca9861b43366c0ca9f6249a2a66bd19881ec | |
parent | 059ec57f8d99033f0570d89e0848f3ac02cf3dc4 (diff) |
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
-rw-r--r-- | graph.go | 21 |
1 files changed, 16 insertions, 5 deletions
@@ -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 |