go,tex: add logic for go-generating tex reports
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-06-15 23:36:47 +02:00
parent 8b1e496c10
commit 826347f7a7
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
5 changed files with 138 additions and 0 deletions

@ -8,6 +8,7 @@ import (
"sync"
"git.dotya.ml/wanderer/math-optim/algo"
"git.dotya.ml/wanderer/math-optim/report"
)
var version = "development"
@ -27,5 +28,7 @@ func main() {
wg.Wait()
report.Print()
log.Println("looks like we're done")
}

70
report/gen.go Normal file

@ -0,0 +1,70 @@
// Copyright 2022 wanderer <a_mirre at utb dot cz>
// SPDX-License-Identifier: GPL-3.0-or-later
//go:build ignore
// +build ignore
package main
import (
"log"
"os"
"text/template"
"time"
)
func main() {
columns := []string{
"l",
"c",
"c",
"c",
"c",
"c",
}
results := []float64{
161.032187,
125.03484,
80321,
85.0362432,
-4.466,
66.0008,
}
topics := []string{
"func name",
"minS",
"maxS",
"meanS",
"medianS",
"stdDevS",
}
fName := "report.tex"
paths := []string{
"report.tmpl",
}
f, err := os.Create(fName)
if err != nil {
log.Fatal(err)
}
defer f.Close()
reportTemplate := template.Must(template.ParseFiles(paths...))
err = reportTemplate.Execute(f, struct {
Timestamp time.Time
Topics []string
Results []float64
Columns []string
}{
Timestamp: time.Now(),
Topics: topics,
Results: results,
Columns: columns,
})
if err != nil {
log.Println(err)
}
}

30
report/report.go Normal file

@ -0,0 +1,30 @@
// Copyright 2022 wanderer <a_mirre at utb dot cz>
// SPDX-License-Identifier: GPL-3.0-or-later
package report
//go:generate go run gen.go
import (
"fmt"
"io"
"log"
"os"
)
// Print prints stats in a report format.
func Print() {
fmt.Fprint(os.Stderr, " printing report...")
fname := "report.tex"
fh, err := os.Open(fname)
if err != nil {
log.Fatal(err)
}
_, err = io.Copy(os.Stdout, fh)
if err != nil {
log.Fatal(err)
}
}

19
report/report.tex Normal file

@ -0,0 +1,19 @@
% Code generated by go generate; DO NOT EDIT.
% This file was generated by robots at
% 2022-06-15 23:30:32.080901953 +0200 CEST m=+0.000320625
% source: git.dotya.ml/wanderer/math-optim/report/report.tmpl
% This file is a part of the math-optim project.
% project homepage: https://git.dotya.ml/wanderer/math-optim/
\begin{tabular}{ ||l|c|c|c|c|c|| }
func name & minS & maxS & meanS & medianS & stdDevS & \\
161.032187 & \\
125.034840 & \\
80321.000000 & \\
85.036243 & \\
-4.466000 & \\
66.000800 & \\
\end{tabular}
% vim: ft=gotexttmpl.tex ts=2 bs=2

16
report/report.tmpl Normal file

@ -0,0 +1,16 @@
% Code generated by go generate; DO NOT EDIT.
% This file was generated by robots at
% {{ .Timestamp }}
% source: git.dotya.ml/wanderer/math-optim/report/report.tmpl
% This file is a part of the math-optim project.
% project homepage: https://git.dotya.ml/wanderer/math-optim/
\begin{tabular}{ ||{{- range $i, $v := .Columns }}{{$v}}| {{- end}}| }
{{ range $i, $v := .Topics }}{{$v }} & {{ end}}\\
{{- range .Results }}
{{ printf "%f &" . }} \\
{{- end }}
\end{tabular}
% vim: ft=gotexttmpl.tex ts=2 bs=2