Skip to content

Commit

Permalink
Add is_validates filter
Browse files Browse the repository at this point in the history
  • Loading branch information
sudip-khanal committed Dec 12, 2024
1 parent 4d61d3d commit ad5e19a
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions per/drf_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from django.conf import settings
from django.db import transaction
from django.db.models import Count, F, Prefetch, Q
from django.db.models.functions import ExtractYear
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.utils.translation import get_language as django_get_language
Expand Down Expand Up @@ -932,33 +931,39 @@ def stats(self, request):
"""
Get the Ops Learning stats based on the filters
"""
ops_data = OpsLearning.objects.aggregate(
operations_included=Count("appeal_code", distinct=True),
learning_extracts=Count("id", filter=Q(is_validated=True), distinct=True),
sector_covered=Count("sector_validated", distinct=True),
source_used=Count("appeal_code__appealdocument", distinct=True),
ops_data = (
super()
.get_queryset()
.aggregate(
operations_included=Count("appeal_code", distinct=True),
learning_extracts=Count("id", filter=Q(is_validated=True), distinct=True),
sector_covered=Count("sector_validated", distinct=True),
source_used=Count("appeal_code__appealdocument", distinct=True),
)
)

learning_by_sector = (
SectorTag.objects.filter(title__isnull=False)
.annotate(count=Count("validated_sectors", distinct=True))
.values("id", "title", "count")
.values("title", "count")
)
learning_by_region = (
Region.objects.annotate(count=Count("appeal__opslearning", distinct=True))
Region.objects.filter(appeal__opslearning__is_validated=True)
.annotate(count=Count("appeal__opslearning", distinct=True))
.values("id", "label", "count")
.order_by("label")
)

learning_by_country = (
Country.objects.annotate(operation_count=Count("appeal__opslearning", distinct=True))
Country.objects.filter(appeal__opslearning__is_validated=True)
.annotate(operation_count=Count("appeal__opslearning", distinct=True))
.values("id", "name", "operation_count")
.order_by("name")
)

sources_overtime = {
str(appeal_type_label): OpsLearning.objects.filter(appeal_code__atype=appeal_type)
.annotate(year=ExtractYear(F("appeal_code__start_date")))
str(appeal_type_label): OpsLearning.objects.filter(appeal_code__atype=appeal_type, is_validated=True)
.annotate(year=F(("appeal_code__start_date")))
.values("year")
.annotate(count=Count("appeal_code__appealdocument", distinct=True))
.order_by("year")
Expand Down

0 comments on commit ad5e19a

Please sign in to comment.