Add command for company stats
This commit is contained in:
parent
a024a2f244
commit
9603b37196
|
|
@ -0,0 +1,30 @@
|
|||
import djclick as click
|
||||
import structlog
|
||||
from django.db.models import Count
|
||||
|
||||
from vbv_lernwelt.course.models import CourseSessionUser
|
||||
|
||||
logger = structlog.get_logger(__name__)
|
||||
|
||||
|
||||
@click.command()
|
||||
def command():
|
||||
VV_COURSE_SESSIONS = [1, 2, 3] # DE, FR, IT
|
||||
|
||||
# Aggregation of users per organisation for a specific course session
|
||||
user_counts = (
|
||||
CourseSessionUser.objects.filter(course_session__id__in=VV_COURSE_SESSIONS)
|
||||
.values("user__organisation__organisation_id", "user__organisation__name_de")
|
||||
.annotate(user_count=Count("id"))
|
||||
.order_by("user__organisation__organisation_id")
|
||||
)
|
||||
|
||||
for entry in user_counts:
|
||||
print(
|
||||
f"Organisation Name: {entry['user__organisation__name_de']}, "
|
||||
f"User Count: {entry['user_count']}"
|
||||
)
|
||||
|
||||
print(
|
||||
f"Total number of users: {sum([entry['user_count'] for entry in user_counts])}"
|
||||
)
|
||||
Loading…
Reference in New Issue