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
|
OS []pirsch.OSStats
|
||||||
Countries []pirsch.CountryStats
|
Countries []pirsch.CountryStats
|
||||||
Platform *pirsch.VisitorStats
|
Platform *pirsch.VisitorStats
|
||||||
|
TimeOfDay []pirsch.TimeOfDayVisitors
|
||||||
HourlyVisitorsTodayLabels template.JS
|
HourlyVisitorsTodayLabels template.JS
|
||||||
HourlyVisitorsTodayDps template.JS
|
HourlyVisitorsTodayDps template.JS
|
||||||
ActiveVisitors int
|
ActiveVisitors int
|
||||||
@@ -162,6 +163,7 @@ func serveTracking() http.HandlerFunc {
|
|||||||
tracking.GetOS(startDate, endDate),
|
tracking.GetOS(startDate, endDate),
|
||||||
tracking.GetCountry(startDate, endDate),
|
tracking.GetCountry(startDate, endDate),
|
||||||
tracking.GetPlatform(startDate, endDate),
|
tracking.GetPlatform(startDate, endDate),
|
||||||
|
tracking.GetVisitorTimeOfDay(startDate, endDate),
|
||||||
hourlyVisitorsTodayLabels,
|
hourlyVisitorsTodayLabels,
|
||||||
hourlyVisitorsTodayDps,
|
hourlyVisitorsTodayDps,
|
||||||
activeVisitors,
|
activeVisitors,
|
||||||
|
|||||||
@@ -134,20 +134,20 @@
|
|||||||
<h2>Browser</h2>
|
<h2>Browser</h2>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Browser</th>
|
<th>Browser</th>
|
||||||
<th>Absolute</th>
|
<th>Absolute</th>
|
||||||
<th>Relative</th>
|
<th>Relative</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{{range $data := .Browser}}
|
{{range $data := .Browser}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{if $data.Browser.String}}{{$data.Browser.String}}{{else}}(unknown){{end}}</td>
|
<td>{{if $data.Browser.String}}{{$data.Browser.String}}{{else}}(unknown){{end}}</td>
|
||||||
<td>{{$data.Visitors}}</td>
|
<td>{{$data.Visitors}}</td>
|
||||||
<td>{{round (multiply $data.RelativeVisitors 100)}} %</td>
|
<td>{{round (multiply $data.RelativeVisitors 100)}} %</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{end}}
|
{{end}}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</section>
|
</section>
|
||||||
@@ -155,20 +155,20 @@
|
|||||||
<h2>Operating System</h2>
|
<h2>Operating System</h2>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>OS</th>
|
<th>OS</th>
|
||||||
<th>Absolute</th>
|
<th>Absolute</th>
|
||||||
<th>Relative</th>
|
<th>Relative</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{{range $data := .OS}}
|
{{range $data := .OS}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{if $data.OS.String}}{{$data.OS.String}}{{else}}(unknown){{end}}</td>
|
<td>{{if $data.OS.String}}{{$data.OS.String}}{{else}}(unknown){{end}}</td>
|
||||||
<td>{{$data.Visitors}}</td>
|
<td>{{$data.Visitors}}</td>
|
||||||
<td>{{round (multiply $data.RelativeVisitors 100)}} %</td>
|
<td>{{round (multiply $data.RelativeVisitors 100)}} %</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{end}}
|
{{end}}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</section>
|
</section>
|
||||||
@@ -176,20 +176,20 @@
|
|||||||
<h2>Countries</h2>
|
<h2>Countries</h2>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Country</th>
|
<th>Country</th>
|
||||||
<th>Absolute</th>
|
<th>Absolute</th>
|
||||||
<th>Relative</th>
|
<th>Relative</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{{range $data := .Countries}}
|
{{range $data := .Countries}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{if $data.CountryCode.String}}{{$data.CountryCode.String}}{{else}}(unknown){{end}}</td>
|
<td>{{if $data.CountryCode.String}}{{$data.CountryCode.String}}{{else}}(unknown){{end}}</td>
|
||||||
<td>{{$data.Visitors}}</td>
|
<td>{{$data.Visitors}}</td>
|
||||||
<td>{{round (multiply $data.RelativeVisitors 100)}} %</td>
|
<td>{{round (multiply $data.RelativeVisitors 100)}} %</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{end}}
|
{{end}}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</section>
|
</section>
|
||||||
@@ -200,11 +200,11 @@
|
|||||||
<section>
|
<section>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Platform</th>
|
<th>Platform</th>
|
||||||
<th>Absolute</th>
|
<th>Absolute</th>
|
||||||
<th>Relative</th>
|
<th>Relative</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -225,6 +225,30 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</section>
|
</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>
|
<section>
|
||||||
<h2>Page Visits</h2>
|
<h2>Page Visits</h2>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ func (cache *Cache) load() {
|
|||||||
"format": func(t time.Time, layout string) string { return t.Format(layout) },
|
"format": func(t time.Time, layout string) string { return t.Format(layout) },
|
||||||
"multiply": func(f, x float64) float64 { return f * x },
|
"multiply": func(f, x float64) float64 { return f * x },
|
||||||
"round": func(f float64) string { return fmt.Sprintf("%.2f", f) },
|
"round": func(f float64) string { return fmt.Sprintf("%.2f", f) },
|
||||||
|
"intRange": intRange,
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
cache.tpl, err = template.New("").Funcs(funcMap).ParseGlob(templateDir)
|
cache.tpl, err = template.New("").Funcs(funcMap).ParseGlob(templateDir)
|
||||||
@@ -100,3 +101,17 @@ func (cache *Cache) Clear() {
|
|||||||
defer cache.m.Unlock()
|
defer cache.m.Unlock()
|
||||||
cache.cache = make(map[string][]byte)
|
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})
|
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 {
|
func sumVisitors(stats []pirsch.Stats) int {
|
||||||
sum := 0
|
sum := 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user