diff --git a/algo/plot.go b/algo/plot.go index 5a2e87a..dc88555 100644 --- a/algo/plot.go +++ b/algo/plot.go @@ -10,6 +10,7 @@ import ( "time" "git.dotya.ml/wanderer/math-optim/stats" + "git.dotya.ml/wanderer/math-optim/util" "gonum.org/v1/gonum/floats" "gonum.org/v1/plot" "gonum.org/v1/plot/plotter" @@ -88,14 +89,14 @@ func plotAllDims(algoStats []stats.Stats, fPrefix, fExt string, wg *sync.WaitGro log.Panic(err) } - if err := createPath(picPath); err != nil { + if err := util.CreatePath(picPath); err != nil { log.Println(err) } filename := picPath + fPrefix + "-" + - sanitiseFName(s.Algo) + "-" + - sanitiseFName(dim.BenchName) + "-" + + util.SanitiseFName(s.Algo) + "-" + + util.SanitiseFName(dim.BenchName) + "-" + fmt.Sprint(s.Dimens) + "D-" + fmt.Sprint(s.Generations) + "G-" + fmt.Sprint(len(dim.Solution)) + "I" + diff --git a/algo/util.go b/util/util.go similarity index 63% rename from algo/util.go rename to util/util.go index 6541710..2a9a7c7 100644 --- a/algo/util.go +++ b/util/util.go @@ -1,7 +1,7 @@ // Copyright 2022 wanderer // SPDX-License-Identifier: GPL-3.0-or-later -package algo +package util import ( "errors" @@ -10,13 +10,15 @@ import ( "strings" ) -func sanitiseFName(s string) string { +// SanitiseFName clears spaces from the string that is supposed to be a file +// name. +func SanitiseFName(s string) string { return strings.ReplaceAll(s, " ", "_") } -// createFolder creates a folder at the specified path, if it doesn't already +// CreateFolder creates a folder at the specified path, if it doesn't already // exist. -func createFolder(path string) error { +func CreateFolder(path string) error { var err error if _, err = os.Stat(path); errors.Is(err, os.ErrNotExist) { @@ -29,9 +31,9 @@ func createFolder(path string) error { return err } -// createPath creates all folders in the provided path, if they don't already +// CreatePath creates all folders in the provided path, if they don't already // exist. -func createPath(path string) error { +func CreatePath(path string) error { var err error if _, err = os.Stat(path); errors.Is(err, os.ErrNotExist) { diff --git a/algo/util_test.go b/util/util_test.go similarity index 92% rename from algo/util_test.go rename to util/util_test.go index f30e813..4501cc8 100644 --- a/algo/util_test.go +++ b/util/util_test.go @@ -1,7 +1,7 @@ // Copyright 2022 wanderer // SPDX-License-Identifier: GPL-3.0-or-later -package algo +package util import ( "os" @@ -12,7 +12,7 @@ import ( func TestCreateFolder(t *testing.T) { // let's assume this will never exist in a clean project... testPath := "whatever-path" - got := createFolder(testPath) + got := CreateFolder(testPath) var want error @@ -28,7 +28,7 @@ func TestCreatePath(t *testing.T) { // let's assume this, too, will never exist in a clean project... testPathRoot := "whatever-path" testPath := testPathRoot + "/whatever-subpath/subsubpath" - got := createPath(testPath) + got := CreatePath(testPath) var want error