mirror of
https://github.com/Kugelschieber/marvinblum.git
synced 2026-01-18 06:40:27 +00:00
Added colors to time of day view.
This commit is contained in:
5
main.go
5
main.go
@@ -126,6 +126,7 @@ func serveTracking() http.HandlerFunc {
|
||||
totalVisitorsLabels, totalVisitorsDps, sessionsDps, bouncesDps := tracking.GetTotalVisitors(startDate, endDate)
|
||||
hourlyVisitorsTodayLabels, hourlyVisitorsTodayDps := tracking.GetHourlyVisitorsToday()
|
||||
pageVisitors, pageRank := tracking.GetPageVisits(startDate, endDate)
|
||||
timeOfDay, timeOfDayMax := tracking.GetVisitorTimeOfDay(startDate, endDate)
|
||||
tplCache.RenderWithoutCache(w, "tracking.html", struct {
|
||||
Start int
|
||||
StartDate time.Time
|
||||
@@ -143,6 +144,7 @@ func serveTracking() http.HandlerFunc {
|
||||
Countries []pirsch.CountryStats
|
||||
Platform *pirsch.VisitorStats
|
||||
TimeOfDay []pirsch.TimeOfDayVisitors
|
||||
TimeOfDayMax float64
|
||||
HourlyVisitorsTodayLabels template.JS
|
||||
HourlyVisitorsTodayDps template.JS
|
||||
ActiveVisitors int
|
||||
@@ -163,7 +165,8 @@ func serveTracking() http.HandlerFunc {
|
||||
tracking.GetOS(startDate, endDate),
|
||||
tracking.GetCountry(startDate, endDate),
|
||||
tracking.GetPlatform(startDate, endDate),
|
||||
tracking.GetVisitorTimeOfDay(startDate, endDate),
|
||||
timeOfDay,
|
||||
float64(timeOfDayMax),
|
||||
hourlyVisitorsTodayLabels,
|
||||
hourlyVisitorsTodayDps,
|
||||
activeVisitors,
|
||||
|
||||
@@ -242,7 +242,10 @@
|
||||
<tr>
|
||||
<td>{{$i}}</td>
|
||||
{{range $j, $day := $global.TimeOfDay}}
|
||||
<td>{{(index (index $global.TimeOfDay $j).Stats $i).Visitors}}</td>
|
||||
{{$visitors := float64 (index (index $global.TimeOfDay $j).Stats $i).Visitors}}
|
||||
<td style="background: rgba(81, 81, 81, {{divide $visitors $global.TimeOfDayMax}});color: #fff;text-align: center;">
|
||||
{{$visitors}}
|
||||
</td>
|
||||
{{end}}
|
||||
</tr>
|
||||
{{end}}
|
||||
|
||||
@@ -38,9 +38,11 @@ func (cache *Cache) load() {
|
||||
funcMap := template.FuncMap{
|
||||
"slug": slug.Make,
|
||||
"format": func(t time.Time, layout string) string { return t.Format(layout) },
|
||||
"multiply": func(f, x float64) float64 { return f * x },
|
||||
"multiply": func(a, b float64) float64 { return a * b },
|
||||
"divide": func(a, b float64) float64 { return a / b },
|
||||
"round": func(f float64) string { return fmt.Sprintf("%.2f", f) },
|
||||
"intRange": intRange,
|
||||
"float64": func(i int) float64 { return float64(i) },
|
||||
}
|
||||
var err error
|
||||
cache.tpl, err = template.New("").Funcs(funcMap).ParseGlob(templateDir)
|
||||
|
||||
@@ -161,7 +161,7 @@ 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 {
|
||||
func GetVisitorTimeOfDay(startDate, endDate time.Time) ([]pirsch.TimeOfDayVisitors, int) {
|
||||
min := endDate.Add(-time.Hour * 24 * 7)
|
||||
|
||||
if startDate.Before(min) {
|
||||
@@ -172,10 +172,20 @@ func GetVisitorTimeOfDay(startDate, endDate time.Time) []pirsch.TimeOfDayVisitor
|
||||
|
||||
if err != nil {
|
||||
logbuch.Error("Error reading visitor time of day statistics", logbuch.Fields{"err": err})
|
||||
return nil
|
||||
return nil, 0
|
||||
}
|
||||
|
||||
return visitors
|
||||
maxVisitors := 0
|
||||
|
||||
for _, v := range visitors {
|
||||
for _, s := range v.Stats {
|
||||
if maxVisitors < s.Visitors {
|
||||
maxVisitors = s.Visitors
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return visitors, maxVisitors
|
||||
}
|
||||
|
||||
func sumVisitors(stats []pirsch.Stats) int {
|
||||
|
||||
Reference in New Issue
Block a user