Get total # of visitors in each individual metric count func.

This commit is contained in:
Danny van Kooten 2016-12-24 15:11:15 +02:00
parent 86efee462a
commit cd8e3c3d9a
8 changed files with 14 additions and 30 deletions

View File

@ -10,12 +10,7 @@ import (
// URL: /api/browsers
var GetBrowsersHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
before, after := getRequestedPeriods(r)
// get total
total := count.Visitors(before, after)
// get rows
results := count.Browsers(before, after, getRequestedLimit(r), total)
results := count.Browsers(before, after, getRequestedLimit(r))
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(results)

View File

@ -10,12 +10,7 @@ import (
// URL: /api/languages
var GetLanguagesHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
before, after := getRequestedPeriods(r)
// get total
total := count.Visitors(before, after)
results := count.Languages(before, after, getRequestedLimit(r), total)
results := count.Languages(before, after, getRequestedLimit(r))
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(results)
})

View File

@ -10,13 +10,7 @@ import (
// URL: /api/referrers
var GetReferrersHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
before, after := getRequestedPeriods(r)
// get total
total := count.Visitors(before, after)
// get rows
results := count.Referrers(before, after, getRequestedLimit(r), total)
results := count.Referrers(before, after, getRequestedLimit(r))
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(results)
})

View File

@ -10,13 +10,7 @@ import (
// URL: /api/screen-resolutions
var GetScreenResolutionsHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
before, after := getRequestedPeriods(r)
// get total
total := count.Visitors(before, after)
// get rows
results := count.Screens(before, after, getRequestedLimit(r), total)
results := count.Screens(before, after, getRequestedLimit(r))
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(results)
})

View File

@ -5,8 +5,7 @@ import (
)
// Browsers returns a point slice containing browser data per browser name
func Browsers(before int64, after int64, limit int, total float64) []Point {
// TODO: Calculate total instead of requiring it as a parameter.
func Browsers(before int64, after int64, limit int) []Point {
stmt, err := db.Conn.Prepare(`
SELECT
t.value,
@ -22,6 +21,7 @@ func Browsers(before int64, after int64, limit int, total float64) []Point {
rows, err := stmt.Query(before, after, limit)
checkError(err)
total := Visitors(before, after)
return newPointSlice(rows, total)
}

View File

@ -5,7 +5,7 @@ import (
)
// Languages returns a point slice containing language data per language
func Languages(before int64, after int64, limit int, total float64) []Point {
func Languages(before int64, after int64, limit int) []Point {
// TODO: Calculate total instead of requiring it as a parameter.
stmt, err := db.Conn.Prepare(`
SELECT
@ -22,6 +22,8 @@ func Languages(before int64, after int64, limit int, total float64) []Point {
rows, err := stmt.Query(before, after, limit)
checkError(err)
total := Visitors(before, after)
return newPointSlice(rows, total)
}

View File

@ -22,6 +22,8 @@ func Referrers(before int64, after int64, limit int, total float64) []Point {
rows, err := stmt.Query(before, after, limit)
checkError(err)
total := Visitors(before, after)
return newPointSlice(rows, total)
}

View File

@ -5,7 +5,7 @@ import (
)
// Screens returns a point slice containing screen data per size
func Screens(before int64, after int64, limit int, total float64) []Point {
func Screens(before int64, after int64, limit int) []Point {
// TODO: Calculate total instead of requiring it as a parameter.
stmt, err := db.Conn.Prepare(`
SELECT
@ -22,6 +22,8 @@ func Screens(before int64, after int64, limit int, total float64) []Point {
rows, err := stmt.Query(before, after, limit)
checkError(err)
total := Visitors(before, after)
return newPointSlice(rows, total)
}