2023-01-12 23:35:51 +01:00
|
|
|
// Copyright 2023 wanderer <a_mirre at utb dot cz>
|
2022-07-13 00:15:40 +02:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
package report
|
|
|
|
|
|
|
|
import (
|
2022-07-17 11:36:59 +02:00
|
|
|
_ "embed"
|
2022-07-13 00:15:40 +02:00
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"text/template"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.dotya.ml/wanderer/math-optim/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Table struct {
|
|
|
|
Algo string
|
|
|
|
Header []string
|
|
|
|
ColLayout []string
|
|
|
|
Rows []Row
|
|
|
|
}
|
|
|
|
|
|
|
|
type Row struct {
|
|
|
|
// Title of the row should contain the settings used to get the Values.
|
|
|
|
Title string
|
|
|
|
Values []float64
|
|
|
|
}
|
|
|
|
|
2022-07-17 11:36:59 +02:00
|
|
|
//go:embed table.tmpl
|
|
|
|
var tmplTableFile []byte
|
|
|
|
|
2022-07-13 00:15:40 +02:00
|
|
|
func NewTable() *Table {
|
|
|
|
return &Table{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewRow() *Row {
|
|
|
|
return &Row{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func SaveTableToFile(t Table) {
|
|
|
|
safeName := util.SanitiseFName(t.Algo)
|
|
|
|
texTableFile := GetTexDir() + "table-" + safeName + ".tex"
|
2022-07-17 11:36:59 +02:00
|
|
|
tmplTable := template.New("table")
|
2022-07-13 17:35:18 +02:00
|
|
|
|
2022-07-17 11:36:59 +02:00
|
|
|
tmplTable = template.Must(tmplTable.Parse(string(tmplTableFile)))
|
2022-07-13 00:15:40 +02:00
|
|
|
|
2022-07-16 23:30:56 +02:00
|
|
|
ttf := tableTexFiles{Algo: t.Algo, FilePaths: []string{texTableFile}}
|
|
|
|
allTables.TexFiles = append(allTables.TexFiles, ttf)
|
|
|
|
|
2022-07-13 00:15:40 +02:00
|
|
|
f, err := os.Create(texTableFile)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
err = tmplTable.Execute(f, struct {
|
|
|
|
Algo string
|
|
|
|
ColLayout []string
|
|
|
|
ColNames []string
|
|
|
|
Rs []Row
|
|
|
|
Timestamp time.Time
|
|
|
|
}{
|
|
|
|
Algo: t.Algo,
|
|
|
|
ColNames: t.Header,
|
|
|
|
ColLayout: t.ColLayout,
|
|
|
|
Rs: t.Rows,
|
|
|
|
Timestamp: time.Now(),
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
}
|