From 610060c88f47aa61950d6301ebc6691d5ea35a85 Mon Sep 17 00:00:00 2001 From: surtur Date: Sat, 16 Jul 2022 21:40:53 +0200 Subject: [PATCH] go(report): process pic lists in batches --- algo/algo.go | 12 +++++++-- report/pic.go | 73 +++++++++++++++++++++++++++------------------------ 2 files changed, 48 insertions(+), 37 deletions(-) diff --git a/algo/algo.go b/algo/algo.go index cbeb8a4..02f02d7 100644 --- a/algo/algo.go +++ b/algo/algo.go @@ -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) } diff --git a/report/pic.go b/report/pic.go index ccffaee..0d2bd28 100644 --- a/report/pic.go +++ b/report/pic.go @@ -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) + } } }