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
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"log"
|
||||
"os"
|
||||
"text/template"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed report_base.tex
|
||||
reportBase []byte
|
||||
|
||||
//go:embed report.tmpl
|
||||
tmplReportFile []byte
|
||||
)
|
||||
|
||||
func main() {
|
||||
// colAlign sets the alignment of latex table columns.
|
||||
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",
|
||||
}
|
||||
fName := "../out/tex/report.tex"
|
||||
f, err := os.Create(fName)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
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 {
|
||||
ReportBase string
|
||||
Timestamp time.Time
|
||||
ColNames []string
|
||||
Results []float64
|
||||
ColAlign []string
|
||||
}{
|
||||
ReportBase: string(reportBase),
|
||||
Timestamp: time.Now(),
|
||||
ColNames: colNames,
|
||||
Results: results,
|
||||
ColAlign: colAlign,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
@ -6,11 +6,6 @@
|
||||
% This file is a part of the math-optim project.
|
||||
% project homepage: https://git.dotya.ml/wanderer/math-optim/
|
||||
|
||||
\begin{tabular}{ ||{{- range $i, $v := .ColAlign }}{{$v}}| {{- end}}| }
|
||||
{{ range $i, $v := .ColNames }}{{$v }} & {{ end}}\\
|
||||
{{- range .Results }}
|
||||
{{ printf "%f &" . }} \\
|
||||
{{- end }}
|
||||
\end{tabular}
|
||||
{{- .ReportBase -}}
|
||||
|
||||
% vim: ft=gotexttmpl.tex ts=2 bs=2
|
||||
% vim: ft=gotexttmpl ts=2 bs=2 expandtab
|
||||
|
Loading…
Reference in New Issue
Block a user