diff options
| author | Nick White <git@njw.name> | 2019-01-23 21:54:09 +0000 | 
|---|---|---|
| committer | Nick White <git@njw.name> | 2019-01-23 21:54:15 +0000 | 
| commit | fb77852acbdbbcedcdb9771770cb6771da002851 (patch) | |
| tree | 233b6cedea313702c994919906d156d829ed378e /parse/prob | |
| parent | d256f967a26ceeb7c3987a1fc447b126a35054f9 (diff) | |
Update line-conf-buckets to mostly use package functions too.
Working now, but needs more consolidation to be worth it.
Diffstat (limited to 'parse/prob')
| -rw-r--r-- | parse/prob/prob.go | 72 | 
1 files changed, 72 insertions, 0 deletions
| diff --git a/parse/prob/prob.go b/parse/prob/prob.go new file mode 100644 index 0000000..5a84567 --- /dev/null +++ b/parse/prob/prob.go @@ -0,0 +1,72 @@ +package prob + +import ( +	"bufio" +	"io/ioutil" +	"path/filepath" +	"strconv" +	"strings" + +	"git.rescribe.xyz/testingtools/parse" +) + +// TODO: probably switch to just relying on io.Reader +func getLineAvg(r *bufio.Reader) (float64, error) { +	var err error + +	totalconf := float64(0) +	num := 0 + +	err = nil +	for err == nil { +		var line string +		line, err = r.ReadString('\n') +		fields := strings.Fields(line) + +		if len(fields) == 2 { +			conf, converr := strconv.ParseFloat(fields[1], 64) +			if converr != nil { +				continue +			} +			totalconf += conf +			num += 1 +		} +	} +	if num <= 0 { +		return 0, nil +	} +	avg := totalconf / float64(num) +	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) { +	var line parse.LineDetail +	lines := make(parse.LineDetails, 0) + +	avg, err := getLineAvg(r) +	if err != nil { +		return lines, err +	} + +	filebase := strings.Replace(name, ".prob", "", 1) + +	txt, err := ioutil.ReadFile(filebase + ".txt") +	if err != nil { +		return lines, err +	} + +	line.Name = name +	line.Avgconf = avg +	line.Text = string(txt) +	line.OcrName = filepath.Dir(filebase) + +	var imgfn parse.ImgPath +	imgfn.Path = filebase + ".bin.png" +	line.Img = imgfn + +	lines = append(lines, line) + +	return lines, nil +} | 
