From: root Date: Mon, 16 Dec 2013 03:34:38 +0000 Subject: additional overview stats X-Git-Url: https://maxious.lambdacomplex.org/git/?p=ckanext-dga-stats.git&a=commitdiff&h=b7b3043b725e370ecb8a8c4e6cc569811fb42280 --- additional overview 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 @@ -125,8 +124,11 @@ 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' union \ - select 'Total Data Files/Resources', count(*) from resource where state='active'").fetchall(); + select 'Total Datasets', count(*) from package where (state='active' or state='draft' or 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'\ + ").fetchall(); return res --- a/ckanext/dga_stats/templates/ckanext/stats/index.html +++ b/ckanext/dga_stats/templates/ckanext/stats/index.html @@ -6,31 +6,8 @@ {% block primary_content %}
-
-

{{ _('Summary') }}

- {% if c.summary_stats %} - - - - - - - - - {% for measure,value in c.summary_stats %} - - - - - {% endfor %} - -
{{ _('Measure') }}{{ _('Value') }}
{{measure}}{{ value }}
- {% else %} -

{{ _('No groups') }}

- {% endif %} -
{% if h.check_access('sysadmin') %} -
+

{{ _('Site Activity Log') }}

{% if c.activity_counts %} @@ -55,7 +32,7 @@

{{ _('No groups') }}

{% endif %} -
+

{{ _('Recent Datasets') }}

{% if c.recent_datasets %}
@@ -80,7 +57,7 @@

{{ _('No groups') }}

{% endif %} -
+

{{ _('User Access List') }}

{% if c.user_access_list %}
@@ -154,31 +131,6 @@
-
-

{{ _('Top Rated Datasets') }}

- {% if c.top_rated_packages %} - - - - - - - - - - {% for package, rating, num_ratings in c.top_rated_packages %} - - - - - - {% endfor %} - -
Dataset{{ _('Average rating') }}{{ _('Number of ratings') }}
{{ h.link_to(package.title or package.name, h.url_for(controller='package', action='read', id=package.name)) }}{{ rating }}{{ num_ratings }}
- {% else %} -

{{ _('No ratings') }}

- {% endif %} -

{{ _('Most Edited Datasets') }}

@@ -227,47 +179,7 @@

{{ _('No groups') }}

{% endif %}
- -
-

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

- - - - - - - - - {% for user, num_packages in c.top_package_owners %} - - - - - {% endfor %} - -
{{ _('User') }}{{ _('Number of Datasets') }}
{{ h.linked_user(user) }}{{ num_packages }}
-
- + {% endif %} + {% endfor %} + + + {% else %} +

{{ _('No groups') }}

+ {% endif %} +
+
+

{{ _('Summary') }}

+ {% if c.summary_stats %} + + + + + + + + + {% for measure,value in c.summary_stats %} + {% if 'Archived' not in measure or h.check_access('sysadmin') %} + + + + + {% endif %} + {% endfor %} + +
{{ _('Measure') }}{{ _('Value') }}
{{measure}}{{ value }}
+ {% else %} +

{{ _('No groups') }}

+ {% endif %} +
{% endblock %} @@ -305,19 +243,15 @@

{{ _('Statistics Menu') }}