Skip to content
Snippets Groups Projects
Commit ae072c25 authored by Joe Schneider's avatar Joe Schneider
Browse files

Merge pull request #48 from scitran/session-counts

Add session counts to projects and collections
parents eb630f44 dafd5ce0
No related branches found
No related tags found
No related merge requests found
......@@ -212,6 +212,16 @@ class Collections(containers.ContainerList):
query = {'curator': self.request.GET.get('curator')} if self.request.GET.get('curator') else {}
projection = ['curator', 'name']
collections = self._get(query, projection, self.request.GET.get('admin', '').lower() in ('1', 'true'))
session_counts = self.app.db.acquisitions.aggregate([
{'$match': {'collections': {'$in': [collection['_id'] for collection in collections]}}},
{'$unwind': "$collections"},
{'$group': {'_id': "$collections", 'sessions': {'$addToSet': "$session"}}}
])
# Convert to dict for easy lookup
session_counts = {coll['_id']: len(coll['sessions']) for coll in session_counts}
for coll in collections:
coll['session_count'] = session_counts.get(coll['_id'], 0)
if self.debug:
for coll in collections:
cid = str(coll['_id'])
......
......@@ -121,6 +121,14 @@ class Projects(containers.ContainerList):
query = {'group': gid} if gid else {}
projection = ['group', 'name']
projects = self._get(query, projection, self.request.GET.get('admin', '').lower() in ('1', 'true'), uid)
session_counts = self.app.db.sessions.aggregate([
{'$match': {'project': {'$in': [proj['_id'] for proj in projects]}}},
{'$group': {'_id': '$project', 'count': {"$sum": 1}}}
])
# Convert to dict for easy lookup
session_counts = {proj['_id']: proj['count'] for proj in session_counts}
for proj in projects:
proj['session_count'] = session_counts.get(proj['_id'], 0)
if self.debug:
for proj in projects:
pid = str(proj['_id'])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment