'Return a dictionary keyed with \'deleted\', \'hidden\', and \'active\' with values
for each representing the count of contents in each state.
Note: counts for deleted and hidden overlap; In other words, a dataset that\'s
both deleted and hidden will be added to both totals.'

def active_counts(self, history):

    returned = dict(deleted=0, hidden=0, active=0)
    contents_subquery = self._union_of_contents_query(history).subquery()
    columns = [sql.column('deleted'), sql.column('visible'), func.count('*')]
    statement = sql.select(columns).select_from(contents_subquery).group_by(sql.column('deleted'), sql.column('visible'))
    groups = self.app.model.context.execute(statement).fetchall()
    for (deleted, visible, count) in groups:
        if deleted:
            returned['deleted'] += count
        if (not visible):
            returned['hidden'] += count
        if ((not deleted) and visible):
            returned['active'] += count
    return returned
