diff --git a/report/comparisonOfMeans.go b/report/comparisonOfMeans.go new file mode 100644 index 0000000..eadc9f6 --- /dev/null +++ b/report/comparisonOfMeans.go @@ -0,0 +1,75 @@ +// Copyright 2022 wanderer +// SPDX-License-Identifier: GPL-3.0-or-later + +package report + +import ( + _ "embed" + "fmt" + "log" + "os" + "text/template" + "time" + + "git.dotya.ml/wanderer/math-optim/util" +) + +//go:embed comparisonOfMeans.tmpl +var tmplComparisonOfMeansFile []byte + +// SaveComparisonOfMeans saves each pic in the list to file, takes note of the +// saved file names. +func SaveComparisonOfMeans(p PicList, benchCount int) { + // algos contains a title of sorts in the form "Algo vs Algo vs Algo...", + // i.e. p.Algo has been repurposed in this instance to contain the names + // of all pertaining algos. + algos := p.Algo + texfiles := picTexFiles{Algo: "Comparison of Algo Means: " + algos} + safeName := util.SanitiseFName(algos) + texPicsFile := fmt.Sprintf("%spics-%s.tex", GetTexDir(), safeName) + tmplComparisonOfMeans := template.New("comparisonofmeans") + tmplComparisonOfMeans = template.Must( + tmplComparisonOfMeans.Parse(string(tmplComparisonOfMeansFile)), + ) + benchPicLists := make([]PicList, 0, benchCount) + + // split the slice to smaller, per-bench slices. + for i := 0; i < len(p.Pics); i += benchCount { + pL := &PicList{} + pL.Pics = p.Pics[i : i+benchCount] + pL.Bench = p.Pics[i].Bench + benchPicLists = append(benchPicLists, *pL) + } + + // 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() + + err = tmplComparisonOfMeans.Execute(f, struct { + Title string + Bench string + BenchCount int + PicLists []PicList + Timestamp time.Time + }{ + Title: p.Algo, + Bench: p.Bench, + BenchCount: benchCount, + PicLists: benchPicLists, + Timestamp: time.Now(), + }) + + if err != nil { + log.Println(err) + } + + texfiles.FilePaths = []string{texPicsFile} + allPics.TexFiles = append(allPics.TexFiles, texfiles) +} diff --git a/report/comparisonOfMeans.tmpl b/report/comparisonOfMeans.tmpl new file mode 100644 index 0000000..f35a8b9 --- /dev/null +++ b/report/comparisonOfMeans.tmpl @@ -0,0 +1,25 @@ +% Code generated by math-optim; DO NOT EDIT. +% +% This file was generated by robots at +% {{ .Timestamp }} +% source: git.dotya.ml/wanderer/math-optim/report/comparisonOfMeans.tmpl + +% This file is a part of the math-optim project. +% project homepage: https://git.dotya.ml/wanderer/math-optim/ + +%\subsection{ {{- printf "Comparison of algo means: %s" .Title -}} } +{{ range $i, $v := .PicLists }} +\subsection{ {{- (index $v.Pics 0).Bench -}} } +\begin{figure}[h!] + \centering +{{- range $j, $u := $v.Pics }} + \begin{subfigure}{0.30\textwidth} + {\includesvg[scale=0.45]{ {{- printf "%s" $u.FilePath -}} }} + \caption{ {{- printf "\\scriptsize{%s}" $u.Caption -}} } + \end{subfigure} + \hfill +{{- end }} +\caption{ {{- printf "{Bench: %s}" $v.Bench }} } +\end{figure} +\newpage +{{ end }} diff --git a/run.go b/run.go index 6684d14..fb54f7d 100644 --- a/run.go +++ b/run.go @@ -36,6 +36,9 @@ func run() { wg.Wait() + pL, benchCount := algo.PrepComparisonOfMeans(&wg) + + report.SaveComparisonOfMeans(*pL, benchCount) report.SaveTexAllPics() report.SaveTexAllTables() }