mirror of
https://github.com/umap-project/umap.git
synced 2025-04-28 19:42:36 +02:00
feat: add more users counts in /stats/ (#2555)
This commit is contained in:
commit
3b195e562a
2 changed files with 19 additions and 0 deletions
|
@ -185,6 +185,10 @@ def test_stats_empty(client):
|
|||
"users_count": 0,
|
||||
"active_sessions": 0,
|
||||
"version": VERSION,
|
||||
"editors_count": 0,
|
||||
"members_count": 0,
|
||||
"orphans_count": 0,
|
||||
"owners_count": 0,
|
||||
}
|
||||
|
||||
|
||||
|
@ -202,6 +206,10 @@ def test_stats_basic(client, map, datalayer, user2):
|
|||
"users_count": 2,
|
||||
"active_sessions": 0,
|
||||
"version": VERSION,
|
||||
"editors_count": 0,
|
||||
"members_count": 0,
|
||||
"orphans_count": 1,
|
||||
"owners_count": 1,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1372,6 +1372,13 @@ class PictogramJSONList(ListView):
|
|||
|
||||
def stats(request):
|
||||
last_week = make_aware(datetime.now()) - timedelta(days=7)
|
||||
users = User.objects.values_list("pk", flat=True)
|
||||
owners = set(
|
||||
Map.objects.filter(owner__isnull=False).values_list("owner", flat=True)
|
||||
)
|
||||
editors = set(Map.editors.through.objects.values_list("user_id", flat=True))
|
||||
members = set(Team.users.through.objects.values_list("user_id", flat=True))
|
||||
orphans = set(users) - owners - editors - members
|
||||
return simple_json_response(
|
||||
**{
|
||||
"version": VERSION,
|
||||
|
@ -1386,6 +1393,10 @@ def stats(request):
|
|||
"active_sessions": Session.objects.filter(
|
||||
expire_date__gt=datetime.utcnow()
|
||||
).count(),
|
||||
"owners_count": len(owners),
|
||||
"editors_count": len(editors),
|
||||
"members_count": len(members),
|
||||
"orphans_count": len(orphans),
|
||||
}
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue