when getting stats for a given period; date should larger than start date, but not equal

This commit is contained in:
Danny 2018-05-09 08:36:29 +02:00
parent 8ed076dd02
commit 3e22efc5f7
3 changed files with 7 additions and 7 deletions

View File

@ -30,7 +30,7 @@ func UpdatePageStats(s *models.PageStats) error {
func GetAggregatedPageStats(startDate time.Time, endDate time.Time, limit int) ([]*models.PageStats, error) {
var result []*models.PageStats
query := dbx.Rebind(`SELECT hostname, pathname, SUM(pageviews) AS pageviews, SUM(visitors) AS visitors, SUM(entries) AS entries, ROUND(AVG(bounce_rate), 0) AS bounce_rate FROM daily_page_stats WHERE date >= ? AND date <= ? GROUP BY hostname, pathname ORDER BY pageviews DESC LIMIT ?`)
query := dbx.Rebind(`SELECT hostname, pathname, SUM(pageviews) AS pageviews, SUM(visitors) AS visitors, SUM(entries) AS entries, ROUND(AVG(bounce_rate), 0) AS bounce_rate FROM daily_page_stats WHERE date > ? AND date <= ? GROUP BY hostname, pathname ORDER BY pageviews DESC LIMIT ?`)
err := dbx.Select(&result, query, startDate.Format("2006-01-02"), endDate.Format("2006-01-02"), limit)
return result, err
}

View File

@ -31,7 +31,7 @@ func UpdateReferrerStats(s *models.ReferrerStats) error {
func GetAggregatedReferrerStats(startDate time.Time, endDate time.Time, limit int) ([]*models.ReferrerStats, error) {
var result []*models.ReferrerStats
query := dbx.Rebind(`SELECT url, SUM(visitors) AS visitors, SUM(pageviews) AS pageviews FROM daily_referrer_stats WHERE date >= ? AND date <= ? GROUP BY url ORDER BY pageviews DESC LIMIT ?`)
query := dbx.Rebind(`SELECT url, SUM(visitors) AS visitors, SUM(pageviews) AS pageviews FROM daily_referrer_stats WHERE date > ? AND date <= ? GROUP BY url ORDER BY pageviews DESC LIMIT ?`)
err := dbx.Select(&result, query, startDate.Format("2006-01-02"), endDate.Format("2006-01-02"), limit)
return result, err
}

View File

@ -29,7 +29,7 @@ func UpdateSiteStats(s *models.SiteStats) error {
}
func GetTotalSiteViews(startDate time.Time, endDate time.Time) (int, error) {
sql := `SELECT COALESCE(SUM(pageviews), 0) FROM daily_site_stats WHERE date >= ? AND date <= ?`
sql := `SELECT COALESCE(SUM(pageviews), 0) FROM daily_site_stats WHERE date > ? AND date <= ?`
query := dbx.Rebind(sql)
var total int
err := dbx.Get(&total, query, startDate.Format("2006-01-02"), endDate.Format("2006-01-02"))
@ -37,7 +37,7 @@ func GetTotalSiteViews(startDate time.Time, endDate time.Time) (int, error) {
}
func GetTotalSiteVisitors(startDate time.Time, endDate time.Time) (int, error) {
sql := `SELECT COALESCE(SUM(visitors), 0) FROM daily_site_stats WHERE date >= ? AND date <= ?`
sql := `SELECT COALESCE(SUM(visitors), 0) FROM daily_site_stats WHERE date > ? AND date <= ?`
query := dbx.Rebind(sql)
var total int
err := dbx.Get(&total, query, startDate.Format("2006-01-02"), endDate.Format("2006-01-02"))
@ -45,7 +45,7 @@ func GetTotalSiteVisitors(startDate time.Time, endDate time.Time) (int, error) {
}
func GetTotalSiteSessions(startDate time.Time, endDate time.Time) (int, error) {
sql := `SELECT COALESCE(SUM(sessions), 0) FROM daily_site_stats WHERE date >= ? AND date <= ?`
sql := `SELECT COALESCE(SUM(sessions), 0) FROM daily_site_stats WHERE date > ? AND date <= ?`
query := dbx.Rebind(sql)
var total int
err := dbx.Get(&total, query, startDate.Format("2006-01-02"), endDate.Format("2006-01-02"))
@ -53,7 +53,7 @@ func GetTotalSiteSessions(startDate time.Time, endDate time.Time) (int, error) {
}
func GetAverageSiteDuration(startDate time.Time, endDate time.Time) (int, error) {
sql := `SELECT COALESCE(ROUND(AVG(avg_duration), 0), 0) FROM daily_site_stats WHERE date >= ? AND date <= ?`
sql := `SELECT COALESCE(ROUND(AVG(avg_duration), 0), 0) FROM daily_site_stats WHERE date > ? AND date <= ?`
query := dbx.Rebind(sql)
var total int
err := dbx.Get(&total, query, startDate.Format("2006-01-02"), endDate.Format("2006-01-02"))
@ -61,7 +61,7 @@ func GetAverageSiteDuration(startDate time.Time, endDate time.Time) (int, error)
}
func GetAverageSiteBounceRate(startDate time.Time, endDate time.Time) (float64, error) {
sql := `SELECT COALESCE(AVG(bounce_rate), 0.00) FROM daily_site_stats WHERE date >= ? AND date <= ?`
sql := `SELECT COALESCE(AVG(bounce_rate), 0.00) FROM daily_site_stats WHERE date > ? AND date <= ?`
query := dbx.Rebind(sql)
var total float64
err := dbx.Get(&total, query, startDate.Format("2006-01-02"), endDate.Format("2006-01-02"))