From: root Date: Wed, 11 Dec 2013 08:33:49 +0000 Subject: fix by org stats X-Git-Url: https://maxious.lambdacomplex.org/git/?p=ckanext-dga-stats.git&a=commitdiff&h=b644f2e1bcf44b362de1ed3a83ed966b2bf06827 --- fix by org stats --- --- a/ckanext/dga_stats/stats.py +++ b/ckanext/dga_stats/stats.py @@ -56,7 +56,9 @@ member = table('member') s = select([member.c.group_id, func.count(member.c.table_id)]).\ group_by(member.c.group_id).\ - where(and_(member.c.group_id!=None, member.c.table_name=='package')).\ + where(member.c.group_id!=None).\ + where(member.c.table_name=='package').\ + where(member.c.capacity=='public').\ order_by(func.count(member.c.table_id).desc()) #limit(limit) @@ -66,16 +68,13 @@ @classmethod def by_org(cls, limit=10): - group = table('group') - package = table('package') - s = select([group.c.id, package.c.private, func.count('*')], group_by=[group.c.id, package.c.private]).\ - where(group.c.is_organization == True).\ - group_by(group.c.id, package.c.private).\ - order_by(group.c.name) - #limit(limit) - - res_ids = model.Session.execute(s).fetchall() - res_groups = [(model.Session.query(model.Group).get(unicode(group_id)), private, val) for group_id, private, val in res_ids] + connection = model.Session.connection() + res = connection.execute("select package.owner_org, package.private, count(*) from package \ + inner join \"group\" on package.owner_org = \"group\".id \ + where package.state='active'\ + group by package.owner_org,\"group\".name, package.private \ + order by \"group\".name, package.private;").fetchall(); + res_groups = [(model.Session.query(model.Group).get(unicode(group_id)), private, val) for group_id, private, val in res] return res_groups @classmethod @@ -124,8 +123,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 --- a/ckanext/dga_stats/templates/ckanext/stats/index.html +++ b/ckanext/dga_stats/templates/ckanext/stats/index.html @@ -227,7 +227,7 @@

{{ _('No groups') }}

{% endif %} -

{{ _('Users Owning Most Datasets') }}

@@ -267,7 +266,8 @@
- + {% endif %} + {% endfor %} + + + {% else %} +

{{ _('No groups') }}

+ {% endif %} + {% endblock %} @@ -315,9 +316,9 @@ - - - + +