fix: custom analytics graph display issue (#2637)

* chore: fixed custom analytics

* chore: typo changes
This commit is contained in:
Bavisetti Narayan 2023-11-03 19:23:35 +05:30 committed by GitHub
parent 91878fb3dd
commit db2a1b8033
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 5 deletions

View File

@ -408,7 +408,6 @@ def analytic_export_task(email, data, slug):
distribution, distribution,
x_axis, x_axis,
y_axis, y_axis,
segment,
key, key,
assignee_details, assignee_details,
label_details, label_details,

View File

@ -12,19 +12,19 @@ from django.db.models.functions import Coalesce, ExtractMonth, ExtractYear, Conc
from plane.db.models import Issue from plane.db.models import Issue
def annotate_with_monthly_dimension(queryset, field_name): def annotate_with_monthly_dimension(queryset, field_name, attribute):
# Get the year and the months # Get the year and the months
year = ExtractYear(field_name) year = ExtractYear(field_name)
month = ExtractMonth(field_name) month = ExtractMonth(field_name)
# Concat the year and month # Concat the year and month
dimension = Concat(year, Value("-"), month, output_field=CharField()) dimension = Concat(year, Value("-"), month, output_field=CharField())
# Annotate the dimension # Annotate the dimension
return queryset.annotate(dimension=dimension) return queryset.annotate(**{attribute: dimension})
def extract_axis(queryset, x_axis): def extract_axis(queryset, x_axis):
# Format the dimension when the axis is in date # Format the dimension when the axis is in date
if x_axis in ["created_at", "start_date", "target_date", "completed_at"]: if x_axis in ["created_at", "start_date", "target_date", "completed_at"]:
queryset = annotate_with_monthly_dimension(queryset, x_axis) queryset = annotate_with_monthly_dimension(queryset, x_axis, "dimension")
return queryset, "dimension" return queryset, "dimension"
else: else:
return queryset.annotate(dimension=F(x_axis)), "dimension" return queryset.annotate(dimension=F(x_axis)), "dimension"
@ -47,7 +47,7 @@ def build_graph_plot(queryset, x_axis, y_axis, segment=None):
# #
if segment in ["created_at", "start_date", "target_date", "completed_at"]: if segment in ["created_at", "start_date", "target_date", "completed_at"]:
queryset = annotate_with_monthly_dimension(queryset, segment) queryset = annotate_with_monthly_dimension(queryset, segment, "segmented")
segment = "segmented" segment = "segmented"
queryset = queryset.values(x_axis) queryset = queryset.values(x_axis)