From e696a3741c6a1e2569d52748372483da2a155e24 Mon Sep 17 00:00:00 2001 From: pablohashescobar <118773738+pablohashescobar@users.noreply.github.com> Date: Wed, 17 May 2023 00:45:59 +0530 Subject: [PATCH] chore: analytics data ordering (#1059) --- apiserver/plane/utils/analytics_plot.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/apiserver/plane/utils/analytics_plot.py b/apiserver/plane/utils/analytics_plot.py index 7106769a6..10b0a799d 100644 --- a/apiserver/plane/utils/analytics_plot.py +++ b/apiserver/plane/utils/analytics_plot.py @@ -8,6 +8,9 @@ from django.db.models.functions import Coalesce, ExtractMonth, ExtractYear, Conc def build_graph_plot(queryset, x_axis, y_axis, segment=None): + + temp_axis = x_axis + if x_axis in ["created_at", "start_date", "target_date", "completed_at"]: year = ExtractYear(x_axis) month = ExtractMonth(x_axis) @@ -61,7 +64,13 @@ def build_graph_plot(queryset, x_axis, y_axis, segment=None): result_values = list(queryset) grouped_data = {} - for date, items in groupby(result_values, key=lambda x: x[str("dimension")]): - grouped_data[str(date)] = list(items) + for key, items in groupby(result_values, key=lambda x: x[str("dimension")]): + grouped_data[str(key)] = list(items) - return grouped_data + sorted_data = grouped_data + if temp_axis == "priority": + order = ["low", "medium", "high", "urgent", "None"] + sorted_data = {key: grouped_data[key] for key in order if key in grouped_data} + else: + sorted_data = dict(sorted(grouped_data.items(), key=lambda x: (x[0] is "None", x[0]))) + return sorted_data