go(report): rework gen.go,report.tmpl
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
make report include `report_base.tex` file verbatim and save it in `out/tex/report.tex` as a base file of the report. currently, this is done when running `go generate ./report` but there are plans to switch from that to emitting the file during runtime, as is done with all other templates.
This commit is contained in:
parent
6db4b60875
commit
052b51f0df
|
@ -7,64 +7,41 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
_ "embed"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
//go:embed report_base.tex
|
||||||
|
reportBase []byte
|
||||||
|
|
||||||
|
//go:embed report.tmpl
|
||||||
|
tmplReportFile []byte
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// colAlign sets the alignment of latex table columns.
|
fName := "../out/tex/report.tex"
|
||||||
colAlign := []string{
|
|
||||||
"l",
|
|
||||||
"c",
|
|
||||||
"c",
|
|
||||||
"c",
|
|
||||||
"c",
|
|
||||||
"c",
|
|
||||||
}
|
|
||||||
results := []float64{
|
|
||||||
161.032187,
|
|
||||||
125.03484,
|
|
||||||
80321,
|
|
||||||
85.0362432,
|
|
||||||
-4.466,
|
|
||||||
66.0008,
|
|
||||||
}
|
|
||||||
colNames := []string{
|
|
||||||
"func name",
|
|
||||||
"min",
|
|
||||||
"max",
|
|
||||||
"mean",
|
|
||||||
"median",
|
|
||||||
"stdDev",
|
|
||||||
}
|
|
||||||
|
|
||||||
fName := "report.tex"
|
|
||||||
paths := []string{
|
|
||||||
"report.tmpl",
|
|
||||||
}
|
|
||||||
f, err := os.Create(fName)
|
f, err := os.Create(fName)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
reportTemplate := template.Must(template.ParseFiles(paths...))
|
tmplReport := template.New("report")
|
||||||
|
tmplReport = template.Must(tmplReport.Parse(string(tmplReportFile)))
|
||||||
|
|
||||||
err = reportTemplate.Execute(f, struct {
|
err = tmplReport.Execute(f, struct {
|
||||||
Timestamp time.Time
|
ReportBase string
|
||||||
ColNames []string
|
Timestamp time.Time
|
||||||
Results []float64
|
|
||||||
ColAlign []string
|
|
||||||
}{
|
}{
|
||||||
Timestamp: time.Now(),
|
ReportBase: string(reportBase),
|
||||||
ColNames: colNames,
|
Timestamp: time.Now(),
|
||||||
Results: results,
|
|
||||||
ColAlign: colAlign,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,6 @@
|
||||||
% This file is a part of the math-optim project.
|
% This file is a part of the math-optim project.
|
||||||
% project homepage: https://git.dotya.ml/wanderer/math-optim/
|
% project homepage: https://git.dotya.ml/wanderer/math-optim/
|
||||||
|
|
||||||
\begin{tabular}{ ||{{- range $i, $v := .ColAlign }}{{$v}}| {{- end}}| }
|
{{- .ReportBase -}}
|
||||||
{{ range $i, $v := .ColNames }}{{$v }} & {{ end}}\\
|
|
||||||
{{- range .Results }}
|
|
||||||
{{ printf "%f &" . }} \\
|
|
||||||
{{- end }}
|
|
||||||
\end{tabular}
|
|
||||||
|
|
||||||
% vim: ft=gotexttmpl.tex ts=2 bs=2
|
% vim: ft=gotexttmpl ts=2 bs=2 expandtab
|
||||||
|
|
Loading…
Reference in New Issue