Skip to content

Commit 6bc5254

Browse files
authored
Merge pull request #164 from eichisanden/feat-median-and-90-percentile
feature: support median and 90 percentile in json format.
2 parents e8db113 + 7ad1caf commit 6bc5254

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

json_writer.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,30 +76,57 @@ def write_to_json(
7676
if not issues_with_metrics:
7777
return ""
7878

79+
# time to first response
7980
average_time_to_first_response = None
81+
med_time_to_first_response = None
82+
p90_time_to_first_response = None
8083
if stats_time_to_first_response is not None:
8184
average_time_to_first_response = stats_time_to_first_response['avg']
85+
med_time_to_first_response = stats_time_to_first_response['med']
86+
p90_time_to_first_response = stats_time_to_first_response['90p']
8287

88+
# time to close
8389
average_time_to_close = None
90+
med_time_to_close = None
91+
p90_time_to_close = None
8492
if stats_time_to_close is not None:
8593
average_time_to_close = stats_time_to_close['avg']
94+
med_time_to_close = stats_time_to_close['med']
95+
p90_time_to_close = stats_time_to_close['90p']
8696

97+
# time to answer
8798
average_time_to_answer = None
99+
med_time_to_answer = None
100+
p90_time_to_answer = None
88101
if stats_time_to_answer is not None:
89102
average_time_to_answer = stats_time_to_answer['avg']
103+
med_time_to_answer = stats_time_to_answer['med']
104+
p90_time_to_answer = stats_time_to_answer['90p']
90105

91106
average_time_in_labels = {}
92-
for stats_type, labels in stats_time_in_labels.items():
93-
if stats_type == 'avg':
94-
for label, time in labels.items():
95-
average_time_in_labels[label] = str(time)
107+
med_time_in_labels = {}
108+
p90_time_in_labels = {}
109+
for label, time in stats_time_in_labels['avg'].items():
110+
average_time_in_labels[label] = str(time)
111+
for label, time in stats_time_in_labels['med'].items():
112+
med_time_in_labels[label] = str(time)
113+
for label, time in stats_time_in_labels['90p'].items():
114+
p90_time_in_labels[label] = str(time)
96115

97116
# Create a dictionary with the metrics
98117
metrics = {
99118
"average_time_to_first_response": str(average_time_to_first_response),
100119
"average_time_to_close": str(average_time_to_close),
101120
"average_time_to_answer": str(average_time_to_answer),
102121
"average_time_in_labels": average_time_in_labels,
122+
"median_time_to_first_response": str(med_time_to_first_response),
123+
"median_time_to_close": str(med_time_to_close),
124+
"median_time_to_answer": str(med_time_to_answer),
125+
"median_time_in_labels": med_time_in_labels,
126+
"90_percentile_time_to_first_response": str(p90_time_to_first_response),
127+
"90_percentile_time_to_close": str(p90_time_to_close),
128+
"90_percentile_time_to_answer": str(p90_time_to_answer),
129+
"90_percentile_time_in_labels": p90_time_in_labels,
103130
"num_items_opened": num_issues_opened,
104131
"num_items_closed": num_issues_closed,
105132
"total_item_count": len(issues_with_metrics),

test_json_writer.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ def test_write_to_json(self):
6666
"average_time_to_close": "5 days, 0:00:00",
6767
"average_time_to_answer": "1 day, 0:00:00",
6868
"average_time_in_labels": {"bug": "1 day, 16:24:12"},
69+
"median_time_to_first_response": "2 days, 12:00:00",
70+
"median_time_to_close": "4 days, 0:00:00",
71+
"median_time_to_answer": "2 days, 0:00:00",
72+
"median_time_in_labels": {"bug": "1 day, 16:24:12"},
73+
"90_percentile_time_to_first_response": "1 day, 12:00:00",
74+
"90_percentile_time_to_close": "3 days, 0:00:00",
75+
"90_percentile_time_to_answer": "3 days, 0:00:00",
76+
"90_percentile_time_in_labels": {"bug": "1 day, 16:24:12"},
6977
"num_items_opened": 2,
7078
"num_items_closed": 1,
7179
"total_item_count": 2,
@@ -146,6 +154,14 @@ def test_write_to_json_with_no_response(self):
146154
"average_time_to_close": "None",
147155
"average_time_to_answer": "None",
148156
"average_time_in_labels": {},
157+
"median_time_to_first_response": "None",
158+
"median_time_to_close": "None",
159+
"median_time_to_answer": "None",
160+
"median_time_in_labels": {},
161+
"90_percentile_time_to_first_response": "None",
162+
"90_percentile_time_to_close": "None",
163+
"90_percentile_time_to_answer": "None",
164+
"90_percentile_time_in_labels": {},
149165
"num_items_opened": 2,
150166
"num_items_closed": 0,
151167
"total_item_count": 2,

0 commit comments

Comments
 (0)