2016-12-24 08:00:45 +00:00
|
|
|
package count
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/dannyvankooten/ana/db"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Referrers returns a point slice containing browser data per browser name
|
2016-12-24 13:14:25 +00:00
|
|
|
func Referrers(before int64, after int64, limit int) []Point {
|
2016-12-24 08:00:45 +00:00
|
|
|
stmt, err := db.Conn.Prepare(`
|
|
|
|
SELECT
|
2016-12-24 11:07:33 +00:00
|
|
|
t.value,
|
|
|
|
SUM(t.count_unique) AS count
|
|
|
|
FROM total_referrers t
|
|
|
|
WHERE UNIX_TIMESTAMP(t.date) <= ? AND UNIX_TIMESTAMP(t.date) >= ?
|
|
|
|
GROUP BY t.value
|
2016-12-24 08:00:45 +00:00
|
|
|
ORDER BY count DESC
|
|
|
|
LIMIT ?`)
|
|
|
|
checkError(err)
|
|
|
|
defer stmt.Close()
|
|
|
|
|
|
|
|
rows, err := stmt.Query(before, after, limit)
|
|
|
|
checkError(err)
|
|
|
|
|
2016-12-24 13:11:15 +00:00
|
|
|
total := Visitors(before, after)
|
|
|
|
|
2016-12-24 08:00:45 +00:00
|
|
|
return newPointSlice(rows, total)
|
|
|
|
}
|
|
|
|
|
2016-12-24 13:14:25 +00:00
|
|
|
// CreateReferrerTotals aggregates screen data into daily totals
|
|
|
|
func CreateReferrerTotals(since int64) {
|
2016-12-24 11:07:33 +00:00
|
|
|
rows := queryTotalRows(`
|
2016-12-24 08:00:45 +00:00
|
|
|
SELECT
|
|
|
|
pv.referrer_url,
|
2016-12-24 11:07:33 +00:00
|
|
|
COUNT(*) AS count,
|
|
|
|
COUNT(DISTINCT(pv.visitor_id)) AS count_unique,
|
2016-12-24 08:00:45 +00:00
|
|
|
DATE_FORMAT(pv.timestamp, "%Y-%m-%d") AS date_group
|
|
|
|
FROM pageviews pv
|
|
|
|
WHERE pv.referrer_url IS NOT NULL
|
2016-12-24 11:07:33 +00:00
|
|
|
AND pv.referrer_url != ''
|
2016-12-24 13:14:25 +00:00
|
|
|
AND UNIX_TIMESTAMP(pv.timestamp) > ?
|
|
|
|
GROUP BY date_group, pv.referrer_url`, since)
|
2016-12-24 08:00:45 +00:00
|
|
|
|
2016-12-24 11:07:33 +00:00
|
|
|
processTotalRows(rows, "total_referrers")
|
2016-12-24 08:00:45 +00:00
|
|
|
}
|