go(report): add pic.go, pics.tmpl
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-07-12 22:31:29 +02:00
parent a2bc1eec6f
commit 2d88ab9afc
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
2 changed files with 94 additions and 0 deletions

71
report/pic.go Normal file
View File

@ -0,0 +1,71 @@
// Copyright 2022 wanderer <a_mirre at utb dot cz>
// SPDX-License-Identifier: GPL-3.0-or-later
package report
import (
"log"
"os"
"text/template"
"time"
"git.dotya.ml/wanderer/math-optim/util"
)
// Pic holds path to pic along with its caption.
type Pic struct {
Caption string
FilePath string
}
// PicList is a structure holding a slice of pics and {bench,algo} metadata.
type PicList struct {
Algo string
Bench string
Pics []Pic
}
// NewPic returns a new copy of Pic.
func NewPic() *Pic {
return &Pic{}
}
// NewPicList returns a new copy of PicList.
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"
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)
}
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(),
})
if err != nil {
log.Println(err)
}
}

23
report/pics.tmpl Normal file
View File

@ -0,0 +1,23 @@
% Code generated by math-optim; DO NOT EDIT.
%
% This file was generated by robots at
% {{ .Timestamp }}
% source: git.dotya.ml/wanderer/math-optim/report/pics.tmpl
% This file is a part of the math-optim project.
% project homepage: https://git.dotya.ml/wanderer/math-optim/
\subsection{ {{- printf "%s - %s" .Algo .Bench -}} }
{{- range $i, $v := .Pics }}
\subsubsection{ {{- $v.Caption -}} }
\begin{figure}[!hbt]
\centering
\includesvg[width=0.65\textwidth]{ {{- $v.FilePath -}} }
\caption{ {{- $v.Caption -}} }
\end{figure}
{{- end }}
% vim: ft=gotexttmpl.tex ts=2 sts=2 sw=2 bs=2 expandtab