Skip to content

Commit

Permalink
Merge branch '1649-stats-extension-tag-counts-are-incorrect' of https…
Browse files Browse the repository at this point in the history
…://github.com/serkostyx/ckan into serkostyx-1649-stats-extension-tag-counts-are-incorrect
  • Loading branch information
amercader committed Feb 12, 2015
2 parents 12cf690 + 3626712 commit c072fc1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 6 additions & 2 deletions ckanext/stats/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,19 @@ def top_tags(cls, limit=10, returned_tag_info='object'): # by package
assert returned_tag_info in ('name', 'id', 'object')
tag = table('tag')
package_tag = table('package_tag')
#TODO filter out tags with state=deleted
package = table('package')
if returned_tag_info == 'name':
from_obj = [package_tag.join(tag)]
tag_column = tag.c.name
else:
from_obj = None
tag_column = package_tag.c.tag_id
j = join(package_tag, package,
package_tag.c.package_id == package.c.id)
s = select([tag_column, func.count(package_tag.c.package_id)],
from_obj=from_obj)
from_obj=from_obj).\
select_from(j).\
where(and_(package_tag.c.state=='active', package.c.private == False, package.c.state == 'active' ))
s = s.group_by(tag_column).\
order_by(func.count(package_tag.c.package_id).desc()).\
limit(limit)
Expand Down
3 changes: 1 addition & 2 deletions ckanext/stats/tests/test_stats_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ def test_largest_groups(self):
def test_top_tags(self):
tags = Stats.top_tags()
tags = [(tag.name, count) for tag, count in tags]
assert_equal(tags, [('tag1', 3),
('tag2', 1)])
assert_equal(tags, [('tag1', 1L)])

def test_top_package_owners(self):
owners = Stats.top_package_owners()
Expand Down

0 comments on commit c072fc1

Please sign in to comment.