Force len in avg calc to be a float too
--- a/ckanext/ga_report/controller.py
+++ b/ckanext/ga_report/controller.py
@@ -114,7 +114,7 @@
if k in ['Total page views', 'Total visits']:
v = sum(v)
else:
- v = float(sum(v))/len(v)
+ v = float(sum(v))/float(len(v))
key, val = clean_key(k,v)
c.global_totals.append((key, val))
--- a/ckanext/ga_report/download_analytics.py
+++ b/ckanext/ga_report/download_analytics.py
@@ -250,7 +250,7 @@
ids='ga:' + self.profile_id,
filters='ga:pagePath==%s' % (path,),
start_date=start_date,
- metrics='ga:bounces,ga:pageviews',
+ metrics='ga:visitBounceRate',
dimensions='ga:pagePath',
max_results=10000,
end_date=end_date).execute()
@@ -260,10 +260,10 @@
path, result_data)
return
results = result_data[0]
- bounces, total = [float(x) for x in result_data[0][1:]]
- pct = 100 * bounces/total
- log.info('%d bounces from %d total == %s', bounces, total, pct)
- ga_model.update_sitewide_stats(period_name, "Totals", {'Bounce rate (home page)': pct},
+ bounces = float(results[1])
+ # visitBounceRate is already a %
+ log.info('Google reports visitBounceRate as %s', bounces)
+ ga_model.update_sitewide_stats(period_name, "Totals", {'Bounce rate (home page)': float(bounces)},
period_complete_day)
--- a/ckanext/ga_report/ga_model.py
+++ b/ckanext/ga_report/ga_model.py
@@ -168,10 +168,9 @@
count = model.Session.query(GA_Url).\
filter(GA_Url.period_name == 'All').count()
log.debug("Deleting %d 'All' records" % count)
- model.Session.query(GA_Url).\
+ count = model.Session.query(GA_Url).\
filter(GA_Url.period_name == 'All').delete()
- log.debug("Query: %s" % model.Session.query(GA_Url).
- filter(GA_Url.period_name == 'All'))
+ log.debug("Deleted %d 'All' records" % count)
model.Session.flush()
model.Session.commit()