From: Maxious Date: Thu, 17 Oct 2013 12:39:06 +0000 Subject: Fix missing package definition X-Git-Url: http://maxious.lambdacomplex.org/git/?p=ckanext-dga-stats.git&a=commitdiff&h=1bbc0f8615582adc6ff179807355039adad7ca75 --- Fix missing package definition --- --- /dev/null +++ b/.gitignore @@ -1,1 +1,2 @@ +*.pyc --- a/README.md +++ b/README.md @@ -5,4 +5,5 @@ * Remove private datasets from all statistics (except top users) * Add summary page * Add activity summary page +* Add organisation public/private dataset count page --- a/ckanext/dga_stats/controller.py +++ b/ckanext/dga_stats/controller.py @@ -16,6 +16,7 @@ c.top_package_owners = stats.top_package_owners() c.summary_stats = stats.summary_stats() c.activity_counts = stats.activity_counts() + c.by_org = stats.by_org() c.new_packages_by_week = rev_stats.get_by_week('new_packages') c.deleted_packages_by_week = rev_stats.get_by_week('deleted_packages') c.num_packages_by_week = rev_stats.get_num_packages_by_week() --- a/ckanext/dga_stats/stats.py +++ b/ckanext/dga_stats/stats.py @@ -42,7 +42,7 @@ package_revision = table('package_revision') package = table('package') s = select([package_revision.c.id, func.count(package_revision.c.revision_id)], from_obj=[package_revision.join(package)]).\ - where(package.c.private == 'f').\ + where(package.c.private == 'f').\ group_by(package_revision.c.id).\ order_by(func.count(package_revision.c.revision_id).desc()).\ limit(limit) @@ -52,16 +52,28 @@ @classmethod def largest_groups(cls, limit=10): - member = table('member') - package = table('package') - s = select([member.c.group_id, func.count(member.c.table_id)]).\ + 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', package.c.private == 'f')).\ + where(and_(member.c.group_id!=None, member.c.table_name=='package')).\ order_by(func.count(member.c.table_id).desc()).\ limit(limit) + res_ids = model.Session.execute(s).fetchall() + res_groups = [(model.Session.query(model.Group).get(unicode(group_id)), val) for group_id, val in res_ids] + return res_groups + + @classmethod + def by_org(cls, limit=10): + group = table('group') + package = table('package') + s = select([group.c.id, package.c.private, func.count(package.c.private)]).\ + group_by(group.c.id, package.c.private).\ + order_by(group.c.id).\ + limit(limit) + res_ids = model.Session.execute(s).fetchall() - res_groups = [(model.Session.query(model.Group).get(unicode(group_id)), val) for group_id, val in res_ids] + res_groups = [(model.Session.query(model.Group).get(unicode(group_id)), private, val) for group_id, private, val in res_ids] return res_groups @classmethod @@ -193,6 +205,7 @@ # be 'for all time' else you get first revision in the time period. package_revision = table('package_revision') revision = table('revision') + package = table('package') s = select([package_revision.c.id, func.min(revision.c.timestamp)], from_obj=[package_revision.join(revision)]).\ where(package.c.private == 'f').\ group_by(package_revision.c.id).order_by(func.min(revision.c.timestamp)) --- a/ckanext/dga_stats/templates/ckanext/stats/index.html +++ b/ckanext/dga_stats/templates/ckanext/stats/index.html @@ -163,7 +163,7 @@ {{ _('Number of datasets') }} - + {% for group, num_packages in c.largest_groups %} {{ h.link_to(group.title or group.name, h.url_for(controller='group', action='read', id=group.name)) }} @@ -173,30 +173,7 @@ {% else %} -

{{ _('No groups') }}

- {% endif %} - -
-

{{ _('Largest Groups') }}

- {% if c.largest_groups %} - - - - - - - - - {% for group, num_packages in c.largest_groups %} - - - - - {% endfor %} - -
{{ _('Group') }}{{ _('Number of datasets') }}
{{ h.link_to(group.title or group.name, h.url_for(controller='group', action='read', id=group.name)) }}{{ num_packages }}
- {% else %} -

{{ _('No groups') }}

+

{{ _('No groups') }}

{% endif %}
@@ -239,6 +216,36 @@ +
+

{{ _('Datasets by Organization') }}

+ {% if c.by_org %} + + + + + + + + + + {% for group,private, num_packages in c.by_org %} + + + {% if private == True %} + + {% else %} + + {% endif %} + + + {% endfor %} + +
{{ _('Group') }}{{ _('Public/Archived') }}{{ _('Number of datasets') }}
{{ h.link_to(group.title or group.name, h.url_for(controller='organization', action='read', id=group.name)) }}ArchivedPublic{{ num_packages }}
+ {% else %} +

{{ _('No groups') }}

+ {% endif %} +
+ {% endblock %} @@ -251,11 +258,11 @@ - + - +