/
display.go
84 lines (66 loc) · 1.91 KB
/
display.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
75
76
77
78
79
80
81
82
83
84
package googleanalytics
import (
"fmt"
"strings"
"time"
)
func (widget *Widget) createTable(websiteReports []websiteReport) string {
content := ""
if len(websiteReports) == 0 {
return content
}
if websiteReports[0].RealtimeReport != nil {
content += "Realtime Visitor Counts\n"
for _, websiteReport := range websiteReports {
websiteRow := fmt.Sprintf(" %-20s", websiteReport.Name)
if websiteReport.RealtimeReport == nil {
websiteRow += "No data found for given ViewId"
} else {
if len(websiteReport.RealtimeReport.Rows) == 0 {
websiteRow += "-"
} else {
websiteRow += fmt.Sprintf("%-10s", websiteReport.RealtimeReport.Rows[0][0])
}
}
content += websiteRow + "\n"
}
content += "\n"
content += "Historical Visitor Counts\n"
}
content += widget.createHeader()
for _, websiteReport := range websiteReports {
websiteRow := ""
for _, report := range websiteReport.Report.Reports {
websiteRow += fmt.Sprintf(" %-20s", websiteReport.Name)
reportRows := report.Data.Rows
noDataMonth := widget.settings.months - len(reportRows)
// Fill in requested months with no data from query
if noDataMonth > 0 {
websiteRow += strings.Repeat("- ", noDataMonth)
}
if reportRows == nil {
websiteRow += "No data found for given ViewId"
} else {
for _, row := range reportRows {
metrics := row.Metrics
for _, metric := range metrics {
websiteRow += fmt.Sprintf("%-10s", metric.Values[0])
}
}
}
content += websiteRow + "\n"
}
}
return content
}
func (widget *Widget) createHeader() string {
// Creates the table header of consisting of Months
currentMonth := int(time.Now().Month())
widgetStartMonth := currentMonth - widget.settings.months + 1
header := " "
for i := widgetStartMonth; i < currentMonth+1; i++ {
header += fmt.Sprintf("%-10s", time.Month(i))
}
header += "\n"
return header
}