Updated pirsch, need to implement the new interface.

This commit is contained in:
Marvin Blum
2020-09-10 17:51:15 +02:00
committed by Marvin Blum
parent 837b833c07
commit 5b800991c8
6 changed files with 34 additions and 45 deletions

View File

@@ -1,11 +1,7 @@
package tracking
import (
"fmt"
"github.com/emvi/logbuch"
"github.com/emvi/pirsch"
"html/template"
"strings"
"time"
)
@@ -19,7 +15,7 @@ type PageVisits struct {
Data template.JS
}
func GetTotalVisitors(startDate, endDate time.Time) (template.JS, template.JS) {
/*func GetTotalVisitors(startDate, endDate time.Time) (template.JS, template.JS) {
visitors, err := analyzer.Visitors(&pirsch.Filter{From: startDate, To: endDate})
if err != nil {
@@ -31,7 +27,7 @@ func GetTotalVisitors(startDate, endDate time.Time) (template.JS, template.JS) {
}
func GetPageVisits(startDate, endDate time.Time) []PageVisits {
visits, err := analyzer.PageVisits(&pirsch.Filter{From: startDate, To: endDate})
visits, err := analyzer.PageVisitors(&pirsch.Filter{From: startDate, To: endDate})
if err != nil {
logbuch.Error("Error reading page statistics", logbuch.Fields{"err": err})
@@ -126,17 +122,6 @@ func GetPlatform(startDate, endDate time.Time) *pirsch.Stats {
return platform
}
func GetHourlyVisitors(startDate, endDate time.Time) (template.JS, template.JS) {
visitors, err := analyzer.HourlyVisitors(&pirsch.Filter{From: startDate, To: endDate})
if err != nil {
logbuch.Error("Error reading hourly visitors", logbuch.Fields{"err": err})
return "", ""
}
return getLabelsAndDataHourly(visitors)
}
func GetHourlyVisitorsToday() (template.JS, template.JS) {
visitors, err := analyzer.HourlyVisitors(&pirsch.Filter{From: today(), To: today()})
@@ -196,7 +181,7 @@ func getLabelsAndDataHourly(visitors []pirsch.Stats) (template.JS, template.JS)
labelsStr := labels.String()
dataStr := dp.String()
return template.JS(labelsStr[:len(labelsStr)-1]), template.JS(dataStr[:len(dataStr)-1])
}
}*/
func today() time.Time {
now := time.Now()

View File

@@ -55,7 +55,7 @@ func NewTracker() (*pirsch.Tracker, context.CancelFunc) {
ReferrerDomainBlacklistIncludesSubdomains: true,
})
analyzer = pirsch.NewAnalyzer(store)
processor := pirsch.NewProcessor(store, nil)
processor := pirsch.NewProcessor(store)
cancel := pirsch.RunAtMidnight(func() {
processTrackingData(processor)
})