math-optim/stats/stats.go
surtur 49f5d93200
All checks were successful
continuous-integration/drone/push Build is passing
go(stats): update FuncStats definition
2022-06-18 00:51:51 +02:00

66 lines
1.2 KiB
Go

// Copyright 2022 wanderer <a_mirre at utb dot cz>
// SPDX-License-Identifier: GPL-3.0-or-later
package stats
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
)
type BenchRound struct {
Iteration int
Results []float64
}
type FuncStats struct {
BenchName string
Solution []BenchRound
}
type Stats struct {
Algo string
Dimens int
BenchFuncStats []FuncStats
Iterations int
Generations int
}
func GetFuncStats(funcName string, solution []BenchRound) FuncStats {
f := FuncStats{
BenchName: funcName,
Solution: solution,
}
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)
}
}
}