Fix total datasets
--- a/ckanext/dga_stats/stats.py
+++ b/ckanext/dga_stats/stats.py
@@ -124,8 +124,9 @@
def summary_stats(cls):
connection = model.Session.connection()
+# select 'Total Archived Datasets', count(*) from package where (state='active' or state='draft' or state='draft-complete') and private = 't' union \
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' union \
+ select 'Total Datasets', count(*) from package where (state='active' or state='draft' or state='draft-complete') and private = 'f' union \
select 'Total Data Files/Resources', count(*) from resource where state='active'").fetchall();
return res
@@ -250,8 +251,10 @@
# be 'for all time' else you get first revision in the time period.
package_revision = table('package_revision')
revision = table('revision')
- s = select([package_revision.c.id, func.min(revision.c.timestamp)], from_obj=[package_revision.join(revision)]).\
+ package = table('package')
+ s = select([package_revision.c.id, func.min(revision.c.timestamp)], from_obj=[package_revision.join(revision).join(package)]).\
where(package_revision.c.state==model.State.DELETED).\
+ where(package.c.private == 'f').\
group_by(package_revision.c.id).\
order_by(func.min(revision.c.timestamp))
res = model.Session.execute(s).fetchall() # [(id, datetime), ...]