diff --git a/main.go b/main.go
index bcd4802..0f210be 100644
--- a/main.go
+++ b/main.go
@@ -142,6 +142,7 @@ func serveTracking() http.HandlerFunc {
OS []pirsch.OSStats
Countries []pirsch.CountryStats
Platform *pirsch.VisitorStats
+ TimeOfDay []pirsch.TimeOfDayVisitors
HourlyVisitorsTodayLabels template.JS
HourlyVisitorsTodayDps template.JS
ActiveVisitors int
@@ -162,6 +163,7 @@ func serveTracking() http.HandlerFunc {
tracking.GetOS(startDate, endDate),
tracking.GetCountry(startDate, endDate),
tracking.GetPlatform(startDate, endDate),
+ tracking.GetVisitorTimeOfDay(startDate, endDate),
hourlyVisitorsTodayLabels,
hourlyVisitorsTodayDps,
activeVisitors,
diff --git a/template/tracking.html b/template/tracking.html
index 33ba764..f6a288e 100644
--- a/template/tracking.html
+++ b/template/tracking.html
@@ -134,20 +134,20 @@
Browser
-
- | Browser |
- Absolute |
- Relative |
-
+
+ | Browser |
+ Absolute |
+ Relative |
+
- {{range $data := .Browser}}
-
- | {{if $data.Browser.String}}{{$data.Browser.String}}{{else}}(unknown){{end}} |
- {{$data.Visitors}} |
- {{round (multiply $data.RelativeVisitors 100)}} % |
-
- {{end}}
+ {{range $data := .Browser}}
+
+ | {{if $data.Browser.String}}{{$data.Browser.String}}{{else}}(unknown){{end}} |
+ {{$data.Visitors}} |
+ {{round (multiply $data.RelativeVisitors 100)}} % |
+
+ {{end}}
@@ -155,20 +155,20 @@
Operating System
-
- | OS |
- Absolute |
- Relative |
-
+
+ | OS |
+ Absolute |
+ Relative |
+
- {{range $data := .OS}}
-
- | {{if $data.OS.String}}{{$data.OS.String}}{{else}}(unknown){{end}} |
- {{$data.Visitors}} |
- {{round (multiply $data.RelativeVisitors 100)}} % |
-
- {{end}}
+ {{range $data := .OS}}
+
+ | {{if $data.OS.String}}{{$data.OS.String}}{{else}}(unknown){{end}} |
+ {{$data.Visitors}} |
+ {{round (multiply $data.RelativeVisitors 100)}} % |
+
+ {{end}}
@@ -176,20 +176,20 @@
Countries
-
- | Country |
- Absolute |
- Relative |
-
+
+ | Country |
+ Absolute |
+ Relative |
+
- {{range $data := .Countries}}
-
- | {{if $data.CountryCode.String}}{{$data.CountryCode.String}}{{else}}(unknown){{end}} |
- {{$data.Visitors}} |
- {{round (multiply $data.RelativeVisitors 100)}} % |
-
- {{end}}
+ {{range $data := .Countries}}
+
+ | {{if $data.CountryCode.String}}{{$data.CountryCode.String}}{{else}}(unknown){{end}} |
+ {{$data.Visitors}} |
+ {{round (multiply $data.RelativeVisitors 100)}} % |
+
+ {{end}}
@@ -200,11 +200,11 @@
-
- | Platform |
- Absolute |
- Relative |
-
+
+ | Platform |
+ Absolute |
+ Relative |
+
@@ -225,6 +225,30 @@
+
+ Time of Day
+
+
+
+ | Time |
+ {{range $day := .TimeOfDay}}
+ {{format $day.Day "Mon 01/02"}} |
+ {{end}}
+
+
+
+ {{$global := .}}
+ {{range $i := (intRange 0 24)}}
+
+ | {{$i}} |
+ {{range $j, $day := $global.TimeOfDay}}
+ {{(index (index $global.TimeOfDay $j).Stats $i).Visitors}} |
+ {{end}}
+
+ {{end}}
+
+
+
diff --git a/tpl/template.go b/tpl/template.go
index 2f19393..60cd339 100644
--- a/tpl/template.go
+++ b/tpl/template.go
@@ -40,6 +40,7 @@ func (cache *Cache) load() {
"format": func(t time.Time, layout string) string { return t.Format(layout) },
"multiply": func(f, x float64) float64 { return f * x },
"round": func(f float64) string { return fmt.Sprintf("%.2f", f) },
+ "intRange": intRange,
}
var err error
cache.tpl, err = template.New("").Funcs(funcMap).ParseGlob(templateDir)
@@ -100,3 +101,17 @@ func (cache *Cache) Clear() {
defer cache.m.Unlock()
cache.cache = make(map[string][]byte)
}
+
+func intRange(start, end int) []int {
+ if end-start < 0 {
+ return []int{}
+ }
+
+ r := make([]int, end-start)
+
+ for i := 0; i < end-start; i++ {
+ r[i] = start + i
+ }
+
+ return r
+}
diff --git a/tracking/statistics.go b/tracking/statistics.go
index 7554891..84107df 100644
--- a/tracking/statistics.go
+++ b/tracking/statistics.go
@@ -157,6 +157,17 @@ func GetPlatform(startDate, endDate time.Time) *pirsch.VisitorStats {
return analyzer.Platform(&pirsch.Filter{From: startDate, To: endDate})
}
+func GetVisitorTimeOfDay(startDate, endDate time.Time) []pirsch.TimeOfDayVisitors {
+ visitors, err := analyzer.TimeOfDay(&pirsch.Filter{From: startDate, To: endDate})
+
+ if err != nil {
+ logbuch.Error("Error reading visitor time of day statistics", logbuch.Fields{"err": err})
+ return nil
+ }
+
+ return visitors
+}
+
func sumVisitors(stats []pirsch.Stats) int {
sum := 0