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)
|
totalVisitorsLabels, totalVisitorsDps, sessionsDps, bouncesDps := tracking.GetTotalVisitors(startDate, endDate)
|
||||||
hourlyVisitorsTodayLabels, hourlyVisitorsTodayDps := tracking.GetHourlyVisitorsToday()
|
hourlyVisitorsTodayLabels, hourlyVisitorsTodayDps := tracking.GetHourlyVisitorsToday()
|
||||||
pageVisitors, pageRank := tracking.GetPageVisits(startDate, endDate)
|
pageVisitors, pageRank := tracking.GetPageVisits(startDate, endDate)
|
||||||
|
timeOfDay, timeOfDayMax := tracking.GetVisitorTimeOfDay(startDate, endDate)
|
||||||
tplCache.RenderWithoutCache(w, "tracking.html", struct {
|
tplCache.RenderWithoutCache(w, "tracking.html", struct {
|
||||||
Start int
|
Start int
|
||||||
StartDate time.Time
|
StartDate time.Time
|
||||||
@@ -143,6 +144,7 @@ func serveTracking() http.HandlerFunc {
|
|||||||
Countries []pirsch.CountryStats
|
Countries []pirsch.CountryStats
|
||||||
Platform *pirsch.VisitorStats
|
Platform *pirsch.VisitorStats
|
||||||
TimeOfDay []pirsch.TimeOfDayVisitors
|
TimeOfDay []pirsch.TimeOfDayVisitors
|
||||||
|
TimeOfDayMax float64
|
||||||
HourlyVisitorsTodayLabels template.JS
|
HourlyVisitorsTodayLabels template.JS
|
||||||
HourlyVisitorsTodayDps template.JS
|
HourlyVisitorsTodayDps template.JS
|
||||||
ActiveVisitors int
|
ActiveVisitors int
|
||||||
@@ -163,7 +165,8 @@ 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),
|
timeOfDay,
|
||||||
|
float64(timeOfDayMax),
|
||||||
hourlyVisitorsTodayLabels,
|
hourlyVisitorsTodayLabels,
|
||||||
hourlyVisitorsTodayDps,
|
hourlyVisitorsTodayDps,
|
||||||
activeVisitors,
|
activeVisitors,
|
||||||
|
|||||||
@@ -242,7 +242,10 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>{{$i}}</td>
|
<td>{{$i}}</td>
|
||||||
{{range $j, $day := $global.TimeOfDay}}
|
{{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}}
|
{{end}}
|
||||||
</tr>
|
</tr>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|||||||
@@ -38,9 +38,11 @@ func (cache *Cache) load() {
|
|||||||
funcMap := template.FuncMap{
|
funcMap := template.FuncMap{
|
||||||
"slug": slug.Make,
|
"slug": slug.Make,
|
||||||
"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(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) },
|
"round": func(f float64) string { return fmt.Sprintf("%.2f", f) },
|
||||||
"intRange": intRange,
|
"intRange": intRange,
|
||||||
|
"float64": func(i int) float64 { return float64(i) },
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
cache.tpl, err = template.New("").Funcs(funcMap).ParseGlob(templateDir)
|
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})
|
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)
|
min := endDate.Add(-time.Hour * 24 * 7)
|
||||||
|
|
||||||
if startDate.Before(min) {
|
if startDate.Before(min) {
|
||||||
@@ -172,10 +172,20 @@ func GetVisitorTimeOfDay(startDate, endDate time.Time) []pirsch.TimeOfDayVisitor
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logbuch.Error("Error reading visitor time of day statistics", logbuch.Fields{"err": err})
|
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 {
|
func sumVisitors(stats []pirsch.Stats) int {
|
||||||
|
|||||||
Reference in New Issue
Block a user