Skip to content

Commit

Permalink
Merge pull request #164 from eichisanden/feat-median-and-90-percentile
Browse files Browse the repository at this point in the history
feature: support median and 90 percentile in json format.
  • Loading branch information
zkoppert authored Nov 1, 2023
2 parents e8db113 + 7ad1caf commit 6bc5254
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
35 changes: 31 additions & 4 deletions json_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,30 +76,57 @@ def write_to_json(
if not issues_with_metrics:
return ""

# time to first response
average_time_to_first_response = None
med_time_to_first_response = None
p90_time_to_first_response = None
if stats_time_to_first_response is not None:
average_time_to_first_response = stats_time_to_first_response['avg']
med_time_to_first_response = stats_time_to_first_response['med']
p90_time_to_first_response = stats_time_to_first_response['90p']

# time to close
average_time_to_close = None
med_time_to_close = None
p90_time_to_close = None
if stats_time_to_close is not None:
average_time_to_close = stats_time_to_close['avg']
med_time_to_close = stats_time_to_close['med']
p90_time_to_close = stats_time_to_close['90p']

# time to answer
average_time_to_answer = None
med_time_to_answer = None
p90_time_to_answer = None
if stats_time_to_answer is not None:
average_time_to_answer = stats_time_to_answer['avg']
med_time_to_answer = stats_time_to_answer['med']
p90_time_to_answer = stats_time_to_answer['90p']

average_time_in_labels = {}
for stats_type, labels in stats_time_in_labels.items():
if stats_type == 'avg':
for label, time in labels.items():
average_time_in_labels[label] = str(time)
med_time_in_labels = {}
p90_time_in_labels = {}
for label, time in stats_time_in_labels['avg'].items():
average_time_in_labels[label] = str(time)
for label, time in stats_time_in_labels['med'].items():
med_time_in_labels[label] = str(time)
for label, time in stats_time_in_labels['90p'].items():
p90_time_in_labels[label] = str(time)

# Create a dictionary with the metrics
metrics = {
"average_time_to_first_response": str(average_time_to_first_response),
"average_time_to_close": str(average_time_to_close),
"average_time_to_answer": str(average_time_to_answer),
"average_time_in_labels": average_time_in_labels,
"median_time_to_first_response": str(med_time_to_first_response),
"median_time_to_close": str(med_time_to_close),
"median_time_to_answer": str(med_time_to_answer),
"median_time_in_labels": med_time_in_labels,
"90_percentile_time_to_first_response": str(p90_time_to_first_response),
"90_percentile_time_to_close": str(p90_time_to_close),
"90_percentile_time_to_answer": str(p90_time_to_answer),
"90_percentile_time_in_labels": p90_time_in_labels,
"num_items_opened": num_issues_opened,
"num_items_closed": num_issues_closed,
"total_item_count": len(issues_with_metrics),
Expand Down
16 changes: 16 additions & 0 deletions test_json_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ def test_write_to_json(self):
"average_time_to_close": "5 days, 0:00:00",
"average_time_to_answer": "1 day, 0:00:00",
"average_time_in_labels": {"bug": "1 day, 16:24:12"},
"median_time_to_first_response": "2 days, 12:00:00",
"median_time_to_close": "4 days, 0:00:00",
"median_time_to_answer": "2 days, 0:00:00",
"median_time_in_labels": {"bug": "1 day, 16:24:12"},
"90_percentile_time_to_first_response": "1 day, 12:00:00",
"90_percentile_time_to_close": "3 days, 0:00:00",
"90_percentile_time_to_answer": "3 days, 0:00:00",
"90_percentile_time_in_labels": {"bug": "1 day, 16:24:12"},
"num_items_opened": 2,
"num_items_closed": 1,
"total_item_count": 2,
Expand Down Expand Up @@ -146,6 +154,14 @@ def test_write_to_json_with_no_response(self):
"average_time_to_close": "None",
"average_time_to_answer": "None",
"average_time_in_labels": {},
"median_time_to_first_response": "None",
"median_time_to_close": "None",
"median_time_to_answer": "None",
"median_time_in_labels": {},
"90_percentile_time_to_first_response": "None",
"90_percentile_time_to_close": "None",
"90_percentile_time_to_answer": "None",
"90_percentile_time_in_labels": {},
"num_items_opened": 2,
"num_items_closed": 0,
"total_item_count": 2,
Expand Down

0 comments on commit 6bc5254

Please sign in to comment.