diff options
author | Nick White <git@njw.name> | 2019-01-24 17:02:56 +0000 |
---|---|---|
committer | Nick White <git@njw.name> | 2019-01-24 17:02:56 +0000 |
commit | 20a479c5a9dbdb24e3fe08aeb94440ade6a88de9 (patch) | |
tree | 653253ee8f20b3c566e97d063933a52fa141fa46 | |
parent | 55a93a583ad41693166d176abd908d0aa2e85784 (diff) |
Simplify .prob processing
-rw-r--r-- | line-conf-buckets/line-conf-buckets.go | 17 | ||||
-rw-r--r-- | parse/prob/prob.go | 27 |
2 files changed, 13 insertions, 31 deletions
diff --git a/line-conf-buckets/line-conf-buckets.go b/line-conf-buckets/line-conf-buckets.go index 915b2b4..689b779 100644 --- a/line-conf-buckets/line-conf-buckets.go +++ b/line-conf-buckets/line-conf-buckets.go @@ -4,7 +4,6 @@ package main // TODO: set bucket dirname from cmdline import ( - "bufio" "flag" "fmt" "log" @@ -14,20 +13,6 @@ import ( "git.rescribe.xyz/testingtools/parse/prob" ) -func detailsFromFile(f string) (parse.LineDetails, error) { - var newlines parse.LineDetails - - file, err := os.Open(f) - if err != nil { - return newlines, err - } - defer file.Close() - - reader := bufio.NewReader(file) - - return prob.GetLineDetails(f, reader) -} - func main() { flag.Usage = func() { fmt.Fprintf(os.Stderr, "Usage: line-conf-buckets prob1 [prob2] [...]\n") @@ -44,7 +29,7 @@ func main() { lines := make(parse.LineDetails, 0) for _, f := range flag.Args() { - newlines, err := detailsFromFile(f) + newlines, err := prob.GetLineDetails(f) if err != nil { log.Fatal(err) } diff --git a/parse/prob/prob.go b/parse/prob/prob.go index 6781a1a..8d01cab 100644 --- a/parse/prob/prob.go +++ b/parse/prob/prob.go @@ -1,7 +1,6 @@ package prob import ( - "bufio" "io/ioutil" "path/filepath" "strconv" @@ -10,22 +9,21 @@ import ( "git.rescribe.xyz/testingtools/parse" ) -// TODO: probably switch to just relying on io.Reader -func getLineAvg(r *bufio.Reader) (float64, error) { - var err error - +func getLineAvg(f string) (float64, error) { totalconf := float64(0) num := 0 - err = nil - for err == nil { - var line string - line, err = r.ReadString('\n') + prob, err := ioutil.ReadFile(f) + if err != nil { + return 0, err + } + + for _, line := range strings.Split(string(prob), "\n") { fields := strings.Fields(line) if len(fields) == 2 { - conf, converr := strconv.ParseFloat(fields[1], 64) - if converr != nil { + conf, err := strconv.ParseFloat(fields[1], 64) + if err != nil { continue } totalconf += conf @@ -39,18 +37,17 @@ func getLineAvg(r *bufio.Reader) (float64, error) { return avg, nil } -// TODO: probably switch to just relying on io.Reader // Note this only processes one line at a time -func GetLineDetails(name string, r *bufio.Reader) (parse.LineDetails, error) { +func GetLineDetails(probfn string) (parse.LineDetails, error) { var line parse.LineDetail lines := make(parse.LineDetails, 0) - avg, err := getLineAvg(r) + avg, err := getLineAvg(probfn) if err != nil { return lines, err } - filebase := strings.Replace(name, ".prob", "", 1) + filebase := strings.Replace(probfn, ".prob", "", 1) txt, err := ioutil.ReadFile(filebase + ".txt") if err != nil { |