From cd8e3c3d9adffcdbe0ac483a867d1b9256cd3505 Mon Sep 17 00:00:00 2001 From: Danny van Kooten Date: Sat, 24 Dec 2016 15:11:15 +0200 Subject: [PATCH] Get total # of visitors in each individual metric count func. --- api/browsers.go | 7 +------ api/languages.go | 7 +------ api/referrers.go | 8 +------- api/screens.go | 8 +------- count/browsers.go | 4 ++-- count/languages.go | 4 +++- count/referrers.go | 2 ++ count/screens.go | 4 +++- 8 files changed, 14 insertions(+), 30 deletions(-) diff --git a/api/browsers.go b/api/browsers.go index 631d1c5..7a399b9 100644 --- a/api/browsers.go +++ b/api/browsers.go @@ -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) diff --git a/api/languages.go b/api/languages.go index 19b1a0c..1810d99 100644 --- a/api/languages.go +++ b/api/languages.go @@ -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) }) diff --git a/api/referrers.go b/api/referrers.go index 46ee3cf..e647eea 100644 --- a/api/referrers.go +++ b/api/referrers.go @@ -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) }) diff --git a/api/screens.go b/api/screens.go index a307516..81e8f75 100644 --- a/api/screens.go +++ b/api/screens.go @@ -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) }) diff --git a/count/browsers.go b/count/browsers.go index 9ef742b..1c7f23c 100644 --- a/count/browsers.go +++ b/count/browsers.go @@ -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) } diff --git a/count/languages.go b/count/languages.go index fbf2d52..04dd6f1 100644 --- a/count/languages.go +++ b/count/languages.go @@ -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) } diff --git a/count/referrers.go b/count/referrers.go index d22e732..99668ce 100644 --- a/count/referrers.go +++ b/count/referrers.go @@ -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) } diff --git a/count/screens.go b/count/screens.go index 7cadcba..8cae8ab 100644 --- a/count/screens.go +++ b/count/screens.go @@ -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) }