chore: assignee names in analytics export (#1086)

* chore: assignee names in analytics export

* chore: update key as assignee name
This commit is contained in:
pablohashescobar 2023-05-20 16:00:02 +05:30 committed by GitHub
parent 1fed5f7846
commit 012486df11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,7 +21,7 @@ row_mapping = {
"state__name": "State", "state__name": "State",
"state__group": "State Group", "state__group": "State Group",
"labels__name": "Label", "labels__name": "Label",
"assignees__email": "Assignee Email", "assignees__email": "Assignee Name",
"start_date": "Start Date", "start_date": "Start Date",
"target_date": "Due Date", "target_date": "Due Date",
"completed_at": "Completed At", "completed_at": "Completed At",
@ -48,6 +48,17 @@ def analytic_export_task(email, data, slug):
key = "count" if y_axis == "issue_count" else "estimate" key = "count" if y_axis == "issue_count" else "estimate"
segmented = segment
assignee_details = {}
if x_axis in ["assignees__email"] or segment in ["assignees__email"]:
assignee_details = (
Issue.objects.filter(workspace__slug=slug, **filters, assignees__avatar__isnull=False)
.order_by("assignees__id")
.distinct("assignees__id")
.values("assignees__avatar", "assignees__email", "assignees__first_name", "assignees__last_name")
)
if segment: if segment:
segment_zero = [] segment_zero = []
for item in distribution: for item in distribution:
@ -81,8 +92,21 @@ def analytic_export_task(email, data, slug):
generated_row.append(value[0].get(key)) generated_row.append(value[0].get(key))
else: else:
generated_row.append("0") generated_row.append("0")
# x-axis replacement for names
if x_axis in ["assignees__email"]:
assignee = [user for user in assignee_details if str(user.get("assignees__email")) == str(item)]
if len(assignee):
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__email"] then replace segment_zero rows with first and last names
if segmented in ["assignees__email"]:
for index, segm in enumerate(row_zero[2:]):
# find the name of the user
assignee = [user for user in assignee_details if str(user.get("assignees__email")) == str(segm)]
if len(assignee):
row_zero[index] = 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()
writer = csv.writer(csv_buffer, delimiter=",", quoting=csv.QUOTE_ALL) writer = csv.writer(csv_buffer, delimiter=",", quoting=csv.QUOTE_ALL)
@ -110,17 +134,19 @@ def analytic_export_task(email, data, slug):
] ]
rows = [] rows = []
for item in distribution: for item in distribution:
rows.append( row = [
tuple(
[
item, item,
distribution.get(item)[0].get("count") distribution.get(item)[0].get("count")
if y_axis == "issue_count" if y_axis == "issue_count"
else distribution.get(item)[0].get("estimate "), else distribution.get(item)[0].get("estimate "),
] ]
) # x-axis replacement to names
) if x_axis in ["assignees__email"]:
assignee = [user for user in assignee_details if str(user.get("assignees__email")) == str(item)]
if len(assignee):
row[0] = str(assignee[0].get("assignees__first_name")) + " " + str(assignee[0].get("assignees__last_name"))
rows.append(tuple(row))
rows = [tuple(row_zero)] + rows rows = [tuple(row_zero)] + rows
csv_buffer = io.StringIO() csv_buffer = io.StringIO()
writer = csv.writer(csv_buffer, delimiter=",", quoting=csv.QUOTE_ALL) writer = csv.writer(csv_buffer, delimiter=",", quoting=csv.QUOTE_ALL)