From: Tom Rees Date: Thu, 17 Jan 2013 00:20:53 +0000 Subject: Done integrating graphs onto site_usage/publishers and site_usage/datasets. Including some interesting queries. X-Git-Url: http://maxious.lambdacomplex.org/git/?p=ckanext-ga-report.git&a=commitdiff&h=5277d6bac60f0eb0cf88a550b77b15e3110dfba9 --- Done integrating graphs onto site_usage/publishers and site_usage/datasets. Including some interesting queries. --- --- a/ckanext/ga_report/controller.py +++ b/ckanext/ga_report/controller.py @@ -253,7 +253,9 @@ writer = csv.writer(response) writer.writerow(["Publisher Title", "Publisher Name", "Views", "Visits", "Period Name"]) - for publisher,view,visit in _get_top_publishers(None): + top_publishers, top_publishers_graph = _get_top_publishers(None) + + for publisher,view,visit in top_publishers: writer.writerow([publisher.title.encode('utf-8'), publisher.name.encode('utf-8'), view, @@ -302,7 +304,9 @@ if c.month: c.month_desc = ''.join([m[1] for m in c.months if m[0]==c.month]) - c.top_publishers = _get_top_publishers() + c.top_publishers, graph_data = _get_top_publishers() + c.top_publishers_graph = json.dumps( _to_rickshaw(graph_data.values()) ) + return render('ga_report/publisher/index.html') def _get_packages(self, publisher=None, count=-1): @@ -405,9 +409,22 @@ 'x':_get_unix_epoch(entry.period_name), 'y':int(entry.pageviews), }) - c.graph_data = json.dumps(graph_data.values()) + + c.graph_data = json.dumps( _to_rickshaw(graph_data.values()) ) return render('ga_report/publisher/read.html') + +def _to_rickshaw(data): + num_points = [] + for package in data: + package['data'] = sorted( package['data'], key=lambda x:x['x'] ) + num_points.append( len(package['data']) ) + if len(set(num_points))>1: + example = num_points[ num_points.index(max(num_points)) ] + for package in data: + while len(package['data'])