add siteanalytics, exclude empty datasets from some stats
--- a/ckanext/dga_stats/stats.py
+++ b/ckanext/dga_stats/stats.py
@@ -72,6 +72,7 @@
def by_org(cls, limit=10):
connection = model.Session.connection()
res = connection.execute("select package.owner_org, package.private, count(*) from package \
+ inner join (select distinct package_id from resource_group inner join resource on resource.resource_group_id = resource_group.id) as r on package.id = r.package_id \
inner join \"group\" on package.owner_org = \"group\".id \
where package.state='active'\
group by package.owner_org,\"group\".name, package.private \
@@ -107,6 +108,7 @@
def top_active_orgs(cls, limit=10):
connection = model.Session.connection()
res = connection.execute("select package.owner_org, count(*) from package \
+ inner join (select distinct package_id from resource_group inner join resource on resource.resource_group_id = resource_group.id) as r on package.id = r.package_id \
inner join \"group\" on package.owner_org = \"group\".id \
inner join (select distinct object_id from activity where activity.timestamp > (now() - interval '60 day')) \
latestactivities on latestactivities.object_id = package.id \
@@ -138,10 +140,10 @@
connection = model.Session.connection()
res = connection.execute("SELECT 'Total Organisations', count(*) from \"group\" where type = 'organization' and state = 'active' union \
- select 'Total Datasets', count(*) from package where (state='active' or state='draft' or state='draft-complete') and private = 'f' union \
+ select 'Total Datasets', count(*) from package inner join (select distinct package_id from resource_group inner join resource on resource.resource_group_id = resource_group.id) as r on package.id = r.package_id where (package.state='active' or package.state='draft' or package.state='draft-complete') and private = 'f' union \
select 'Total Archived Datasets', count(*) from package where (state='active' or state='draft' or state='draft-complete') and private = 't' union \
select 'Total Data Files/Resources', count(*) from resource where state='active' union \
- select 'Total Machine Readable/Data API Resources', count(*) from resource where state='active' and webstore_url = 'active'\
+ select 'Total Machine Readable/Data API Resources', count(*) from resource where state='active' and (webstore_url = 'active' or format="wms")\
").fetchall();
return res
--- a/ckanext/dga_stats/templates/ckanext/stats/index.html
+++ b/ckanext/dga_stats/templates/ckanext/stats/index.html
@@ -305,6 +305,7 @@
<li class="nav-item"><a href="#stats-by-org" data-toggle="tab">{{ _('Datasets by Organization') }}</a></li>
<li class="nav-item"><a href="#stats-res-by-org" data-toggle="tab">{{ _('Resources by Organization') }}</a></li>
<li class="nav-item"><a href="#stats-activity-org" data-toggle="tab">{{ _('Most Active Organisations') }}</a></li>
+ <li class="nav-item active"><a href="//data.gov.au/site-usage" data-toggle="tab">Site Analytics</a></li>
<li class="nav-item active"><a href="#stats-summary" data-toggle="tab">{{ _('Summary') }}</a></li>
</ul>
</nav>