SATCAP-OCEANS_DOCKER / api /stats_views.py
rinogeek's picture
Initial Docker configuration for Hugging Face
1624b73
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)
})