go(report): process pic lists in batches
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-07-16 21:40:53 +02:00
parent c47951f3ea
commit 610060c88f
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
2 changed files with 48 additions and 37 deletions

@ -46,12 +46,16 @@ func DoRandomSearch(wg *sync.WaitGroup) {
go plotAllDims(algoStats[i], "plot", ".svg", pCh)
}
pLs := []report.PicList{}
for range algoStats {
pL := <-pCh
report.SavePicsToFile(pL, "Random Search")
pLs = append(pLs, pL)
}
report.SavePicsToFile(pLs, "Random Search")
stats.SaveTable("Random Search", algoStats)
}
@ -86,12 +90,16 @@ func DoStochasticHillClimbing(wg *sync.WaitGroup) {
go plotAllDims(algoStat, "plot", ".svg", pCh)
}
pLs := []report.PicList{}
for range algoStats {
pL := <-pCh
report.SavePicsToFile(pL, "Stochastic Hill Climbing")
pLs = append(pLs, pL)
}
report.SavePicsToFile(pLs, "Stochastic Hill Climbing")
stats.SaveTable("Stochastic Hill CLimbing", algoStats)
}

@ -35,47 +35,50 @@ func NewPicList() *PicList {
return &PicList{}
}
// SavePicsToFile saves to file a pic list of a specified algo.
func SavePicsToFile(p PicList, algoName string) {
safeName := util.SanitiseFName(p.Algo + "-" + p.Bench)
texPicsFile := GetTexDir() + "pics-" + safeName + ".tex"
tmplPicsFile := "report/pics.tmpl"
// SavePicsToFile saves each pic list for all bench funcs of a specified algo
// to a file.
func SavePicsToFile(pls []PicList, algoName string) {
for _, p := range pls {
safeName := util.SanitiseFName(p.Algo + "-" + p.Bench)
texPicsFile := GetTexDir() + "pics-" + safeName + ".tex"
tmplPicsFile := "report/pics.tmpl"
if _, err := os.Stat(tmplPicsFile); err != nil {
// TODO(me): fix this, same as in table.go.
// this block is relevant for the unit test path, somehow the file is
// not found as defined above.
log.Println(err, `, weird test behaviour , prepending "../"`)
if _, err := os.Stat(tmplPicsFile); err != nil {
// TODO(me): fix this, same as in table.go.
// this block is relevant for the unit test path, somehow the file is
// not found as defined above.
log.Println(err, `, weird test behaviour , prepending "../"`)
tmplPicsFile = "../" + tmplPicsFile
}
tmplPicsFile = "../" + tmplPicsFile
}
tmplPics := template.Must(template.ParseFiles(tmplPicsFile))
tmplPics := template.Must(template.ParseFiles(tmplPicsFile))
// make sure the output dir exists, else die early.
if err := util.CreatePath(GetTexDir()); err != nil {
log.Fatalln(err)
}
// make sure the output dir exists, else die early.
if err := util.CreatePath(GetTexDir()); err != nil {
log.Fatalln(err)
}
f, err := os.Create(texPicsFile)
if err != nil {
log.Println(err)
}
defer f.Close()
f, err := os.Create(texPicsFile)
if err != nil {
log.Println(err)
}
defer f.Close()
err = tmplPics.Execute(f, struct {
Algo string
Bench string
Pics []Pic
Timestamp time.Time
}{
Algo: p.Algo,
Bench: p.Bench,
Pics: p.Pics,
Timestamp: time.Now(),
})
err = tmplPics.Execute(f, struct {
Algo string
Bench string
Pics []Pic
Timestamp time.Time
}{
Algo: p.Algo,
Bench: p.Bench,
Pics: p.Pics,
Timestamp: time.Now(),
})
if err != nil {
log.Println(err)
if err != nil {
log.Println(err)
}
}
}