File size: 753 Bytes
1624b73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from rest_framework.views import APIView
from rest_framework.response import Response
from .models import Detection
from django.db.models import Count
from collections import Counter

class StatsView(APIView):
    def get(self, request):
        detections = Detection.objects.all()
        total_detections = detections.count()
        
        # Count labels across all detections
        label_counts = Counter()
        for det in detections:
            for item in det.results:
                label_counts[item['label']] += 1
        
        return Response({
            "total_images_analyzed": total_detections,
            "total_objects_detected": sum(label_counts.values()),
            "label_distribution": dict(label_counts)
        })