mirror of https://github.com/curusarn/resh
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.6 KiB
72 lines
1.6 KiB
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"log"
|
|
"math"
|
|
"strconv"
|
|
)
|
|
|
|
type statistics struct {
|
|
writer *bufio.Writer
|
|
size int
|
|
matches []int
|
|
matchesTotal int
|
|
charactersRecalled []int
|
|
charactersRecalledTotal int
|
|
dataPointCount int
|
|
}
|
|
|
|
func (s *statistics) init() {
|
|
s.matches = make([]int, s.size)
|
|
s.charactersRecalled = make([]int, s.size)
|
|
}
|
|
|
|
func (s *statistics) addMatch(distance int, cmdLength int) {
|
|
if distance >= s.size {
|
|
// --calculate-total
|
|
// log.Fatal("Match distance is greater than size of statistics")
|
|
s.matchesTotal++
|
|
s.charactersRecalledTotal += cmdLength
|
|
return
|
|
}
|
|
s.matches[distance]++
|
|
s.matchesTotal++
|
|
s.charactersRecalled[distance] += cmdLength
|
|
s.charactersRecalledTotal += cmdLength
|
|
s.dataPointCount++
|
|
}
|
|
|
|
func (s *statistics) addMiss() {
|
|
s.dataPointCount++
|
|
}
|
|
|
|
func (s *statistics) printCumulative() {
|
|
matchesPercent := 0.0
|
|
out := "### Matches ###\n"
|
|
for i := 0; i < s.size; i++ {
|
|
matchesPercent += 100 * float64(s.matches[i]) / float64(s.dataPointCount)
|
|
out += strconv.Itoa(i) + " ->"
|
|
out += fmt.Sprintf(" (%.1f %%)\n", matchesPercent)
|
|
for j := 0; j < int(math.Round(matchesPercent)); j++ {
|
|
out += "#"
|
|
}
|
|
out += "\n"
|
|
}
|
|
matchesPercent = 100 * float64(s.matchesTotal) / float64(s.dataPointCount)
|
|
out += "TOTAL ->"
|
|
out += fmt.Sprintf(" (%.1f %%)\n", matchesPercent)
|
|
for j := 0; j < int(math.Round(matchesPercent)); j++ {
|
|
out += "#"
|
|
}
|
|
out += "\n"
|
|
|
|
n, err := s.writer.WriteString(string(out) + "\n\n")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
if n == 0 {
|
|
log.Fatal("Nothing was written", n)
|
|
}
|
|
}
|
|
|