summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.name>2021-12-06 11:48:30 +0000
committerNick White <git@njw.name>2021-12-06 11:48:30 +0000
commit31a610fd23cc4f41d677a70353460085dbf20572 (patch)
treee90fca9861b43366c0ca9f6249a2a66bd19881ec
parent059ec57f8d99033f0570d89e0848f3ac02cf3dc4 (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.go21
1 files changed, 16 insertions, 5 deletions
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