-
Notifications
You must be signed in to change notification settings - Fork 4
/
report.go
64 lines (52 loc) · 1.24 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
package main
import (
"fmt"
"io"
"io/ioutil"
"log"
"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 {
panic(fmt.Sprintf("ERROR %v\n", err))
}
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]}
monthData.Inflate()
item, err := monthData.RickshawItem()
if err != nil {
panic(fmt.Sprintf("ERR_BAD_RICKSHAW_ITEM: %v\n", err))
}
rickshawData.AddItem(item)
}
fi.Close()
rickshawDataFormatted, err := rickshawData.Formatted()
if err != nil {
log.Fatal(err)
}
tmplData := rickshaw.TemplateData{
ReportName: "Fruit Report",
RickshawURL: "https://grokify.github.io/rickshaw",
RickshawDataFormatted: rickshawDataFormatted,
IncludeDataTable: true}
ioutil.WriteFile(outputfile, []byte(rickshaw.RickshawExtensionsReport(tmplData)), 0644)
fmt.Println("DONE")
}