fix: analytics export (#1862)

* fix: analytics export

* dev: export analytics assignee indexing

* dev: total counts
This commit is contained in:
Nikhil 2023-08-15 15:48:22 +05:30 committed by GitHub
parent e1ae0d3b56
commit df46a45afc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -51,12 +51,12 @@ def analytic_export_task(email, data, slug):
segmented = segment segmented = segment
assignee_details = {} assignee_details = {}
if x_axis in ["assignees__display_name"] or segment in ["assignees__display_name"]: if x_axis in ["assignees__id"] or segment in ["assignees__id"]:
assignee_details = ( assignee_details = (
Issue.issue_objects.filter(workspace__slug=slug, **filters, assignees__avatar__isnull=False) Issue.issue_objects.filter(workspace__slug=slug, **filters, assignees__avatar__isnull=False)
.order_by("assignees__id") .order_by("assignees__id")
.distinct("assignees__id") .distinct("assignees__id")
.values("assignees__avatar", "assignees__display_name", "assignees__first_name", "assignees__last_name") .values("assignees__avatar", "assignees__display_name", "assignees__first_name", "assignees__last_name", "assignees__id")
) )
if segment: if segment:
@ -93,19 +93,19 @@ def analytic_export_task(email, data, slug):
else: else:
generated_row.append("0") generated_row.append("0")
# x-axis replacement for names # x-axis replacement for names
if x_axis in ["assignees__display_name"]: if x_axis in ["assignees__id"]:
assignee = [user for user in assignee_details if str(user.get("assignees__display_name")) == str(item)] assignee = [user for user in assignee_details if str(user.get("assignees__id")) == str(item)]
if len(assignee): if len(assignee):
generated_row[0] = str(assignee[0].get("assignees__first_name")) + " " + str(assignee[0].get("assignees__last_name")) generated_row[0] = str(assignee[0].get("assignees__first_name")) + " " + str(assignee[0].get("assignees__last_name"))
rows.append(tuple(generated_row)) rows.append(tuple(generated_row))
# If segment is ["assignees__display_name"] then replace segment_zero rows with first and last names # If segment is ["assignees__display_name"] then replace segment_zero rows with first and last names
if segmented in ["assignees__display_name"]: if segmented in ["assignees__id"]:
for index, segm in enumerate(row_zero[2:]): for index, segm in enumerate(row_zero[2:]):
# find the name of the user # find the name of the user
assignee = [user for user in assignee_details if str(user.get("assignees__display_name")) == str(segm)] assignee = [user for user in assignee_details if str(user.get("assignees__id")) == str(segm)]
if len(assignee): if len(assignee):
row_zero[index] = str(assignee[0].get("assignees__first_name")) + " " + str(assignee[0].get("assignees__last_name")) row_zero[index + 2] = str(assignee[0].get("assignees__first_name")) + " " + str(assignee[0].get("assignees__last_name"))
rows = [tuple(row_zero)] + rows rows = [tuple(row_zero)] + rows
csv_buffer = io.StringIO() csv_buffer = io.StringIO()
@ -141,8 +141,8 @@ def analytic_export_task(email, data, slug):
else distribution.get(item)[0].get("estimate "), else distribution.get(item)[0].get("estimate "),
] ]
# x-axis replacement to names # x-axis replacement to names
if x_axis in ["assignees__display_name"]: if x_axis in ["assignees__id"]:
assignee = [user for user in assignee_details if str(user.get("assignees__display_name")) == str(item)] assignee = [user for user in assignee_details if str(user.get("assignees__id")) == str(item)]
if len(assignee): if len(assignee):
row[0] = str(assignee[0].get("assignees__first_name")) + " " + str(assignee[0].get("assignees__last_name")) row[0] = str(assignee[0].get("assignees__first_name")) + " " + str(assignee[0].get("assignees__last_name"))