-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathreport.go
74 lines (63 loc) · 1.42 KB
/
report.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"fmt"
"io"
"log/slog"
"os"
"github.com/grokify/mogo/encoding/csvutil"
"github.com/grokify/gocharts/v2/charts/rickshaw"
)
func main() {
inputfile := "data.csv"
outputfile := "report.html"
csv, fi, err := csvutil.NewReaderFile(inputfile, rune(','))
if err != nil {
slog.Error(err.Error())
os.Exit(1)
}
rickshawData := rickshaw.NewRickshawData()
idx := -1
for {
idx += 1
record, err := csv.Read()
if err == io.EOF {
break
}
if idx == 0 {
continue
}
monthData := rickshaw.MonthData{
SeriesName: record[0],
MonthS: record[1],
YearS: record[2],
ValueS: record[3]}
if err := monthData.Inflate(); err != nil {
slog.Error(err.Error())
os.Exit(2)
}
if item, err := monthData.RickshawItem(); err != nil {
slog.Error(err.Error(), "msg", "ERR_BAD_RICKSHAW_ITEM")
os.Exit(3)
} else {
rickshawData.AddItem(item)
}
}
fi.Close()
rickshawDataFormatted, err := rickshawData.Formatted()
if err != nil {
slog.Error(err.Error())
os.Exit(4)
}
tmplData := rickshaw.TemplateData{
ReportName: "Fruit Report",
RickshawURL: "https://grokify.github.io/rickshaw",
RickshawDataFormatted: rickshawDataFormatted,
IncludeDataTable: true}
if err := os.WriteFile(outputfile,
[]byte(rickshaw.RickshawExtensionsReport(tmplData)), 0600); err != nil {
slog.Error(err.Error())
os.Exit(5)
}
fmt.Println("DONE")
os.Exit(0)
}