mirror of
https://github.com/Kugelschieber/marvinblum.git
synced 2026-01-18 06:40:27 +00:00
Added time of day to tracking page.
This commit is contained in:
2
main.go
2
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,
|
||||
|
||||
@@ -225,6 +225,30 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
<section>
|
||||
<h2>Time of Day</h2>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Time</th>
|
||||
{{range $day := .TimeOfDay}}
|
||||
<th>{{format $day.Day "Mon 01/02"}}</th>
|
||||
{{end}}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{$global := .}}
|
||||
{{range $i := (intRange 0 24)}}
|
||||
<tr>
|
||||
<td>{{$i}}</td>
|
||||
{{range $j, $day := $global.TimeOfDay}}
|
||||
<td>{{(index (index $global.TimeOfDay $j).Stats $i).Visitors}}</td>
|
||||
{{end}}
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
<section>
|
||||
<h2>Page Visits</h2>
|
||||
</section>
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user