From: Ross Jones Date: Thu, 08 Nov 2012 15:27:34 +0000 Subject: Actually returning the score instead of 0 X-Git-Url: http://maxious.lambdacomplex.org/git/?p=ckanext-ga-report.git&a=commitdiff&h=4a81aca56dfbca1a227d7a6f903ca1b00c81208e --- Actually returning the score instead of 0 --- --- a/ckanext/ga_report/command.py +++ b/ckanext/ga_report/command.py @@ -80,7 +80,7 @@ default=False, dest='delete_first', help='Delete data for the period first') - self.parser.add_option('-s', '--slip_url_stats', + self.parser.add_option('-s', '--skip_url_stats', action='store_true', default=False, dest='skip_url_stats', --- a/ckanext/ga_report/controller.py +++ b/ckanext/ga_report/controller.py @@ -71,13 +71,13 @@ entries = q.order_by('ga_stat.key').all() def clean_key(key, val): - if key in ['Average time on site', 'Pages per visit', 'New visits', 'Bounces']: + if key in ['Average time on site', 'Pages per visit', 'New visits', 'Bounce rate (home page)']: val = "%.2f" % round(float(val), 2) if key == 'Average time on site': mins, secs = divmod(float(val), 60) hours, mins = divmod(mins, 60) val = '%02d:%02d:%02d (%s seconds) ' % (hours, mins, secs, val) - if key in ['New visits','Bounces']: + if key in ['New visits','Bounce rate (home page)']: val = "%s%%" % val if key in ['Total page views', 'Total visits']: val = int(val) @@ -232,7 +232,7 @@ return render('ga_report/publisher/index.html') def _get_packages(self, publisher=None, count=-1): - '''Returns the datasets in order of visits''' + '''Returns the datasets in order of views''' if count == -1: count = sys.maxint @@ -244,7 +244,7 @@ if publisher: q = q.filter(GA_Url.department_id==publisher.name) q = q.filter(GA_Url.period_name==month) - q = q.order_by('ga_url.visits::int desc') + q = q.order_by('ga_url.pageviews::int desc') top_packages = [] for entry,package in q.limit(count): if package: @@ -312,7 +312,7 @@ and package_id <> '' and url like '/dataset/%%' and period_name=%s - group by department_id order by visits desc + group by department_id order by views desc """ if limit: q = q + " limit %s;" % (limit) @@ -329,7 +329,7 @@ def _get_publishers(): ''' Returns a list of all publishers. Each item is a tuple: - (names, title) + (name, title) ''' publishers = [] for pub in model.Session.query(model.Group).\ --- a/ckanext/ga_report/download_analytics.py +++ b/ckanext/ga_report/download_analytics.py @@ -253,7 +253,7 @@ max_results=10000, end_date=end_date).execute() result_data = results.get('rows') - if len(result_data) != 1: + if not result_data or len(result_data) != 1: log.error('Could not pinpoint the bounces for path: %s. Got results: %r', path, result_data) return @@ -261,7 +261,7 @@ 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': pct}) + ga_model.update_sitewide_stats(period_name, "Totals", {'Bounce rate (home page)': pct}) def _locale_stats(self, start_date, end_date, period_name): --- a/ckanext/ga_report/ga_model.py +++ b/ckanext/ga_report/ga_model.py @@ -343,3 +343,21 @@ q.delete() model.Session.commit() +def get_score_for_dataset(dataset_name): + import datetime + now = datetime.datetime.now() + period_names = ['%s-%02d' % (now.year, now.month), + '%s-%02d' % (now.year, now.month-1)] + + entry = model.Session.query(GA_Url)\ + .filter(GA_Url.period_name==period_names[0])\ + .filter(GA_Url.package_id==dataset_name).first() + score = int(entry.pageviews) if entry else 0 + + entry = model.Session.query(GA_Url)\ + .filter(GA_Url.period_name==period_names[1])\ + .filter(GA_Url.package_id==dataset_name).first() + val = int(entry.pageviews) if entry else 0 + score += val/2 if val else 0 + + return score --- a/ckanext/ga_report/templates/ga_report/notes.html +++ b/ckanext/ga_report/templates/ga_report/notes.html @@ -6,8 +6,8 @@
  • Notes

    --- a/ckanext/ga_report/templates/ga_report/publisher/index.html +++ b/ckanext/ga_report/templates/ga_report/publisher/index.html @@ -41,14 +41,14 @@ - + - + --- a/ckanext/ga_report/templates/ga_report/publisher/read.html +++ b/ckanext/ga_report/templates/ga_report/publisher/read.html @@ -47,14 +47,14 @@
    PublisherDataset Visits Dataset Views
    ${h.link_to(publisher.title, h.url_for(controller='ckanext.ga_report.controller:GaDatasetReport', action='read_publisher', id=publisher.name))} ${visits} ${views}
    - + - +
    DatasetVisits Views
    ${h.link_to(package.title or package.name, h.url_for(controller='package', action='read', id=package.name))} ${visits} ${views}