2016-12-23 14:49:23 +00:00
|
|
|
package count
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/dannyvankooten/ana/db"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Screens returns a point slice containing screen data per size
|
2016-12-24 13:11:15 +00:00
|
|
|
func Screens(before int64, after int64, limit int) []Point {
|
2016-12-23 14:49:23 +00:00
|
|
|
// TODO: Calculate total instead of requiring it as a parameter.
|
|
|
|
stmt, err := db.Conn.Prepare(`
|
|
|
|
SELECT
|
2016-12-24 11:07:33 +00:00
|
|
|
t.value,
|
|
|
|
SUM(t.count_unique) AS count
|
|
|
|
FROM total_screens t
|
|
|
|
WHERE UNIX_TIMESTAMP(t.date) <= ? AND UNIX_TIMESTAMP(t.date) >= ?
|
|
|
|
GROUP BY t.value
|
2016-12-23 14:49:23 +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:57:37 +00:00
|
|
|
return newPointSlice(rows)
|
2016-12-23 14:49:23 +00:00
|
|
|
}
|
|
|
|
|
2016-12-24 13:14:25 +00:00
|
|
|
// CreateScreenTotals aggregates screen data into daily totals
|
|
|
|
func CreateScreenTotals(since int64) {
|
2016-12-24 11:07:33 +00:00
|
|
|
rows := queryTotalRows(`
|
2016-12-23 14:49:23 +00:00
|
|
|
SELECT
|
|
|
|
v.screen_resolution,
|
2016-12-24 11:07:33 +00:00
|
|
|
COUNT(*) AS count,
|
|
|
|
COUNT(DISTINCT(pv.visitor_id)) AS count_unique,
|
2016-12-23 14:49:23 +00:00
|
|
|
DATE_FORMAT(pv.timestamp, "%Y-%m-%d") AS date_group
|
|
|
|
FROM pageviews pv
|
|
|
|
LEFT JOIN visitors v ON v.id = pv.visitor_id
|
2016-12-24 13:14:25 +00:00
|
|
|
WHERE UNIX_TIMESTAMP(pv.timestamp) > ?
|
|
|
|
GROUP BY date_group, v.screen_resolution`, since)
|
2016-12-23 14:49:23 +00:00
|
|
|
|
2016-12-24 11:07:33 +00:00
|
|
|
processTotalRows(rows, "total_screens")
|
2016-12-23 14:49:23 +00:00
|
|
|
}
|