|
|
|
@ -3,7 +3,7 @@ from rest_framework.response import Response |
|
|
|
from rest_framework.permissions import IsAuthenticated, IsAdminUser |
|
|
|
from django.utils import timezone |
|
|
|
from datetime import timedelta |
|
|
|
from django.db.models import Count, Sum |
|
|
|
from django.db.models import Count, Sum, Q |
|
|
|
from django.db.models.functions import TruncDate |
|
|
|
|
|
|
|
from apps.account.models import User, LoginHistory |
|
|
|
@ -26,15 +26,22 @@ class AdminDashboardStatsView(APIView): |
|
|
|
# --------------------------------------------------------- |
|
|
|
# 1. CARDS & BASIC STATS |
|
|
|
# --------------------------------------------------------- |
|
|
|
active_students = User.objects.filter(groups__name="Student Group", is_active=True).count() |
|
|
|
professors = User.objects.filter(groups__name="Professor Group", is_active=True).count() |
|
|
|
active_students = User.objects.filter( |
|
|
|
Q(user_type=User.UserType.STUDENT) | Q(user_type=User.UserType.CLIENT), |
|
|
|
is_active=True |
|
|
|
).count() |
|
|
|
professors = User.objects.filter(user_type=User.UserType.PROFESSOR, is_active=True).count() |
|
|
|
active_courses = Course.objects.filter(status=Course.StatusChoices.ONGOING).count() |
|
|
|
total_blogs = Blog.objects.count() |
|
|
|
pending_certificates = Certificate.objects.filter(status='pending').count() |
|
|
|
active_live_sessions = CourseLiveSession.objects.filter(ended_at__isnull=True).count() |
|
|
|
|
|
|
|
# Revenue (Mocked for 30d sum) |
|
|
|
revenue_30d = 12500.00 # Dummy data |
|
|
|
# Revenue (30d sum of successful transactions) |
|
|
|
revenue_result = TransactionParticipant.objects.filter( |
|
|
|
status=TransactionParticipant.TransactionStatus.SUCCESS, |
|
|
|
created_at__gte=thirty_days_ago |
|
|
|
).aggregate(total=Sum('price')) |
|
|
|
revenue_30d = float(revenue_result['total'] or 0.0) |
|
|
|
|
|
|
|
# Private vs Group Chat Usage |
|
|
|
chat_types = RoomMessage.objects.values('room_type').annotate(count=Count('id')) |
|
|
|
|