go(stats): add functions for manipulating Stats
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
e178ee3237
commit
ed76cf865b
@ -3,6 +3,14 @@
|
|||||||
|
|
||||||
package stats
|
package stats
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
type FuncStats struct {
|
type FuncStats struct {
|
||||||
BenchName string
|
BenchName string
|
||||||
Results []float64
|
Results []float64
|
||||||
@ -15,3 +23,38 @@ type Stats struct {
|
|||||||
Iterations int
|
Iterations int
|
||||||
Generations int
|
Generations int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetFuncStats(funcName string, results []float64) FuncStats {
|
||||||
|
f := FuncStats{
|
||||||
|
BenchName: funcName,
|
||||||
|
Results: results,
|
||||||
|
}
|
||||||
|
|
||||||
|
return f
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetStats(algo string, dimens int, benchFuncStats []FuncStats, iterations, generations int) Stats {
|
||||||
|
s := Stats{
|
||||||
|
Algo: algo,
|
||||||
|
Dimens: dimens,
|
||||||
|
BenchFuncStats: benchFuncStats,
|
||||||
|
Iterations: iterations,
|
||||||
|
Generations: generations,
|
||||||
|
}
|
||||||
|
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func SaveStats(stats Stats) {
|
||||||
|
if j, err := json.MarshalIndent(stats, "", " "); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
} else {
|
||||||
|
fmt.Fprintln(os.Stderr, j)
|
||||||
|
|
||||||
|
log.Println("saving json stats to: test.json")
|
||||||
|
|
||||||
|
if err = ioutil.WriteFile("test.json", j, 0o600); err != nil {
|
||||||
|
log.Println("error saving stats to file:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user