Skip to content

Commit

Permalink
fix: analytic query params (#1035)
Browse files Browse the repository at this point in the history
* fix: query params for analytics

* fix: default analytics filters
  • Loading branch information
pablohashescobar authored May 11, 2023
1 parent f2a6887 commit 6e9235e
Showing 1 changed file with 10 additions and 27 deletions.
37 changes: 10 additions & 27 deletions apiserver/plane/api/views/analytic.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from plane.api.serializers import AnalyticViewSerializer
from plane.utils.analytics_plot import build_graph_plot
from plane.bgtasks.analytic_plot_export import analytic_export_task
from plane.utils.issue_filters import issue_filters


class AnalyticsEndpoint(BaseAPIView):
Expand All @@ -44,19 +45,10 @@ def get(self, request, slug):
status=status.HTTP_400_BAD_REQUEST,
)

project_ids = request.GET.getlist("project")
cycle_ids = request.GET.getlist("cycle")
module_ids = request.GET.getlist("module")

segment = request.GET.get("segment", False)
filters = issue_filters(request.GET, "GET")

queryset = Issue.objects.filter(workspace__slug=slug)
if project_ids:
queryset = queryset.filter(project_id__in=project_ids)
if cycle_ids:
queryset = queryset.filter(issue_cycle__cycle_id__in=cycle_ids)
if module_ids:
queryset = queryset.filter(issue_module__module_id__in=module_ids)
queryset = Issue.objects.filter(workspace__slug=slug, **filters)

total_issues = queryset.count()
distribution = build_graph_plot(
Expand All @@ -75,18 +67,18 @@ def get(self, request, slug):

colors = (
State.objects.filter(
workspace__slug=slug, project_id__in=project_ids
workspace__slug=slug, project_id__in=filters.get("project__in")
).values(key, "color")
if project_ids
if filters.get("project__in", False)
else State.objects.filter(workspace__slug=slug).values(key, "color")
)

if x_axis in ["labels__name"] or segment in ["labels__name"]:
colors = (
Label.objects.filter(
workspace__slug=slug, project_id__in=project_ids
workspace__slug=slug, project_id__in=filters.get("project__in")
).values("name", "color")
if project_ids
if filters.get("project__in", False)
else Label.objects.filter(workspace__slug=slug).values(
"name", "color"
)
Expand Down Expand Up @@ -213,18 +205,9 @@ class DefaultAnalyticsEndpoint(BaseAPIView):

def get(self, request, slug):
try:
queryset = Issue.objects.filter(workspace__slug=slug)

project_ids = request.GET.getlist("project")
cycle_ids = request.GET.getlist("cycle")
module_ids = request.GET.getlist("module")

if project_ids:
queryset = queryset.filter(project_id__in=project_ids)
if cycle_ids:
queryset = queryset.filter(issue_cycle__cycle_id__in=cycle_ids)
if module_ids:
queryset = queryset.filter(issue_module__module_id__in=module_ids)
filters = issue_filters(request.GET, "GET")

queryset = Issue.objects.filter(workspace__slug=slug, **filters)

total_issues = queryset.count()

Expand Down

0 comments on commit 6e9235e

Please sign in to comment.