Skip to content

Commit

Permalink
ENH: Add a direct tag count
Browse files Browse the repository at this point in the history
  • Loading branch information
jnmclarty committed Aug 6, 2015
1 parent 2858068 commit a26f862
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion trump/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
from sqlalchemy.orm.session import object_session
from sqlalchemy.exc import ProgrammingError, NoSuchTableError
from sqlalchemy.sql import and_, or_
from sqlalchemy import create_engine
from sqlalchemy import create_engine, distinct

from indexing import indexingtypes
from validity import validitychecks
Expand Down Expand Up @@ -521,6 +521,19 @@ def search_meta_specific(self, **avargs):

qry = qry.order_by(Symbol.name)
return qry.all()
def tag_counts(self):
""" Get a list of tags and the number of each.
Returns
-------
List of tuples, in order (tag, # of Symbols w/Tag)
"""
qry = self.ses.query(SymbolTag.tag, func.count(SymbolTag.tag))
qry = qry.group_by(SymbolTag.tag)
qry = qry.order_by(SymbolTag.tag)
tags = list(qry.all())
return tags

def bulk_cache_of_tag(self, tag):
""" Caches all the symbols by a certain tag.
Expand Down

0 comments on commit a26f862

Please sign in to comment.