Skip to content

Commit 3536281

Browse files
committed
Replaces references to avg with stats.
In previous commits pure averages were replace by a dict of avg, median, 90th percentile. This makes that switch visible in docs, method names, variable names.
1 parent 9194d6c commit 3536281

10 files changed

+76
-76
lines changed

issue_metrics.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
from classes import IssueWithMetrics
3333
from discussions import get_discussions
3434
from json_writer import write_to_json
35-
from labels import get_average_time_in_labels, get_label_metrics
35+
from labels import get_stats_time_in_labels, get_label_metrics
3636
from markdown_writer import write_to_markdown
37-
from time_to_answer import get_average_time_to_answer, measure_time_to_answer
38-
from time_to_close import get_average_time_to_close, measure_time_to_close
37+
from time_to_answer import get_stats_time_to_answer, measure_time_to_answer
38+
from time_to_close import get_stats_time_to_close, measure_time_to_close
3939
from time_to_ready_for_review import get_time_to_ready_for_review
4040
from time_to_merge import measure_time_to_merge
4141
from time_to_first_response import (
42-
get_average_time_to_first_response,
42+
get_stats_time_to_first_response,
4343
measure_time_to_first_response,
4444
)
4545

@@ -317,36 +317,36 @@ def main():
317317
ignore_users=ignore_users,
318318
)
319319

320-
average_time_to_first_response = get_average_time_to_first_response(
320+
stats_time_to_first_response = get_stats_time_to_first_response(
321321
issues_with_metrics
322322
)
323-
average_time_to_close = None
323+
stats_time_to_close = None
324324
if num_issues_closed > 0:
325-
average_time_to_close = get_average_time_to_close(issues_with_metrics)
325+
stats_time_to_close = get_stats_time_to_close(issues_with_metrics)
326326

327-
average_time_to_answer = get_average_time_to_answer(issues_with_metrics)
327+
stats_time_to_answer = get_stats_time_to_answer(issues_with_metrics)
328328

329-
# Get the average time in label for each label and store it in a dictionary
329+
# Get stats describing the time in label for each label and store it in a dictionary
330330
# where the key is the label and the value is the average time
331-
average_time_in_labels = get_average_time_in_labels(issues_with_metrics, labels)
331+
stats_time_in_labels = get_stats_time_in_labels(issues_with_metrics, labels)
332332

333333
# Write the results to json and a markdown file
334334
write_to_json(
335335
issues_with_metrics,
336-
average_time_to_first_response,
337-
average_time_to_close,
338-
average_time_to_answer,
339-
average_time_in_labels,
336+
stats_time_to_first_response,
337+
stats_time_to_close,
338+
stats_time_to_answer,
339+
stats_time_in_labels,
340340
num_issues_open,
341341
num_issues_closed,
342342
search_query,
343343
)
344344
write_to_markdown(
345345
issues_with_metrics,
346-
average_time_to_first_response,
347-
average_time_to_close,
348-
average_time_to_answer,
349-
average_time_in_labels,
346+
stats_time_to_first_response,
347+
stats_time_to_close,
348+
stats_time_to_answer,
349+
stats_time_in_labels,
350350
num_issues_open,
351351
num_issues_closed,
352352
labels,

labels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ def get_label_metrics(issue: github3.issues.Issue, labels: List[str]) -> dict:
8989
return label_metrics
9090

9191

92-
def get_average_time_in_labels(
92+
def get_stats_time_in_labels(
9393
issues_with_metrics: List[IssueWithMetrics],
9494
labels: List[str],
9595
) -> dict[str, timedelta]:
96-
"""Calculate the average time spent in each label."""
96+
"""Calculate stats describing time spent in each label."""
9797
time_in_labels = {}
9898
for issue in issues_with_metrics:
9999
if issue.label_metrics:

test_issue_metrics.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class TestMain(unittest.TestCase):
133133
@patch("issue_metrics.auth_to_github")
134134
@patch("issue_metrics.search_issues")
135135
@patch("issue_metrics.measure_time_to_first_response")
136-
@patch("issue_metrics.get_average_time_to_first_response")
136+
@patch("issue_metrics.get_stats_time_to_first_response")
137137
@patch.dict(
138138
os.environ,
139139
{
@@ -142,7 +142,7 @@ class TestMain(unittest.TestCase):
142142
)
143143
def test_main(
144144
self,
145-
mock_get_average_time_to_first_response,
145+
mock_get_stats_time_to_first_response,
146146
mock_measure_time_to_first_response,
147147
mock_search_issues,
148148
mock_auth_to_github,
@@ -179,10 +179,10 @@ def test_main(
179179
]
180180
mock_measure_time_to_first_response.return_value = mock_issues_with_ttfr
181181

182-
# Set up the mock get_average_time_to_first_response function
183-
mock_average_time_to_first_response = 15
184-
mock_get_average_time_to_first_response.return_value = (
185-
mock_average_time_to_first_response
182+
# Set up the mock get_stats_time_to_first_response function
183+
mock_stats_time_to_first_response = 15
184+
mock_get_stats_time_to_first_response.return_value = (
185+
mock_stats_time_to_first_response
186186
)
187187

188188
# Call main and check that it runs without errors

test_labels.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pytz
88
from classes import IssueWithMetrics
99

10-
from labels import get_average_time_in_labels, get_label_events, get_label_metrics
10+
from labels import get_stats_time_in_labels, get_label_events, get_label_metrics
1111

1212

1313
class TestLabels(unittest.TestCase):
@@ -69,7 +69,7 @@ def test_get_label_metrics_open_issue(self):
6969

7070

7171
class TestGetAverageTimeInLabels(unittest.TestCase):
72-
"""Unit tests for get_average_time_in_labels"""
72+
"""Unit tests for get_stats_time_in_labels"""
7373

7474
def setUp(self):
7575
self.issues_with_metrics = MagicMock()
@@ -79,10 +79,10 @@ def setUp(self):
7979
),
8080
]
8181

82-
def test_get_average_time_in_labels(self):
83-
"""Test get_average_time_in_labels"""
82+
def test_get_stats_time_in_labels(self):
83+
"""Test get_stats_time_in_labels"""
8484
labels = ["bug", "feature"]
85-
metrics = get_average_time_in_labels(self.issues_with_metrics, labels)
85+
metrics = get_stats_time_in_labels(self.issues_with_metrics, labels)
8686
print(metrics)
8787
self.assertEqual(len(metrics['avg']), 2)
8888
self.assertEqual(metrics['avg']["bug"], timedelta(days=2))

test_time_to_answer.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
from typing import List
66

77
from classes import IssueWithMetrics
8-
from time_to_answer import get_average_time_to_answer, measure_time_to_answer
8+
from time_to_answer import get_stats_time_to_answer, measure_time_to_answer
99

1010

1111
class TestGetAverageTimeToAnswer(unittest.TestCase):
12-
"""A test case for the get_average_time_to_answer function.
12+
"""A test case for the get_stats_time_to_answer function.
1313
1414
This test case includes three test methods:
1515
- test_returns_none_for_empty_list
1616
- test_returns_none_for_list_with_no_time_to_answer
17-
- test_returns_average_time_to_answer
17+
- test_returns_stats_time_to_answer
1818
"""
1919

2020
def test_returns_none_for_empty_list(self):
@@ -23,7 +23,7 @@ def test_returns_none_for_empty_list(self):
2323
issues_with_metrics: List[IssueWithMetrics] = []
2424

2525
# Act
26-
result = get_average_time_to_answer(issues_with_metrics)
26+
result = get_stats_time_to_answer(issues_with_metrics)
2727

2828
# Assert
2929
self.assertIsNone(result)
@@ -40,12 +40,12 @@ def test_returns_none_for_list_with_no_time_to_answer(self):
4040
]
4141

4242
# Act
43-
result = get_average_time_to_answer(issues_with_metrics)
43+
result = get_stats_time_to_answer(issues_with_metrics)
4444

4545
# Assert
4646
self.assertIsNone(result)
4747

48-
def test_returns_average_time_to_answer(self):
48+
def test_returns_stats_time_to_answer(self):
4949
"""
5050
Tests that the function correctly calculates the average
5151
time to answer for a list of issues with time to answer.
@@ -59,7 +59,7 @@ def test_returns_average_time_to_answer(self):
5959
]
6060

6161
# Act
62-
result = get_average_time_to_answer(issues_with_metrics)['avg']
62+
result = get_stats_time_to_answer(issues_with_metrics)['avg']
6363

6464
# Assert
6565
self.assertEqual(result, timedelta(seconds=20))

test_time_to_close.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
"""A module containing unit tests for the time_to_close module.
22
33
This module contains unit tests for the measure_time_to_close and
4-
get_average_time_to_close functions in the time_to_close module.
4+
get_stats_time_to_close functions in the time_to_close module.
55
The tests use mock GitHub issues to test the functions' behavior.
66
77
Classes:
88
TestMeasureTimeToClose: A class to test the measure_time_to_close function.
9-
TestGetAverageTimeToClose: A class to test the get_average_time_to_close function.
9+
TestGetStatsTimeToClose: A class to test the get_stats_time_to_close function.
1010
1111
"""
1212
from datetime import timedelta
1313
import unittest
1414
from unittest.mock import MagicMock
1515
from classes import IssueWithMetrics
1616

17-
from time_to_close import get_average_time_to_close, measure_time_to_close
17+
from time_to_close import get_stats_time_to_close, measure_time_to_close
1818

1919

2020
class TestGetAverageTimeToClose(unittest.TestCase):
21-
"""Test suite for the get_average_time_to_close function."""
21+
"""Test suite for the get_stats_time_to_close function."""
2222

23-
def test_get_average_time_to_close(self):
23+
def test_get_stats_time_to_close(self):
2424
"""Test that the function correctly calculates the average time to close."""
2525
# Create mock data
2626
issues_with_metrics = [
@@ -44,11 +44,11 @@ def test_get_average_time_to_close(self):
4444
]
4545

4646
# Call the function and check the result
47-
result = get_average_time_to_close(issues_with_metrics)['avg']
47+
result = get_stats_time_to_close(issues_with_metrics)['avg']
4848
expected_result = timedelta(days=3)
4949
self.assertEqual(result, expected_result)
5050

51-
def test_get_average_time_to_close_no_issues(self):
51+
def test_get_stats_time_to_close_no_issues(self):
5252
"""Test that the function returns None if there are no issues with time to close."""
5353
# Create mock data
5454
issues_with_metrics = [
@@ -64,7 +64,7 @@ def test_get_average_time_to_close_no_issues(self):
6464
]
6565

6666
# Call the function and check the result
67-
result = get_average_time_to_close(issues_with_metrics)
67+
result = get_stats_time_to_close(issues_with_metrics)
6868
expected_result = None
6969
self.assertEqual(result, expected_result)
7070

test_time_to_first_response.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"""A module containing unit tests for the time_to_first_response module.
22
33
This module contains unit tests for the measure_time_to_first_response and
4-
get_average_time_to_first_response functions in the time_to_first_response module.
4+
get_stats_time_to_first_response functions in the time_to_first_response module.
55
The tests use mock GitHub issues and comments to test the functions' behavior.
66
77
Classes:
88
TestMeasureTimeToFirstResponse: A class to test the measure_time_to_first_response function.
99
TestGetAverageTimeToFirstResponse: A class to test the
10-
get_average_time_to_first_response function.
10+
get_stats_time_to_first_response function.
1111
1212
"""
1313
import unittest
@@ -16,7 +16,7 @@
1616

1717
from classes import IssueWithMetrics
1818
from time_to_first_response import (
19-
get_average_time_to_first_response,
19+
get_stats_time_to_first_response,
2020
measure_time_to_first_response,
2121
)
2222

@@ -311,14 +311,14 @@ def test_measure_time_to_first_response_ignore_bot(self):
311311
self.assertEqual(result, expected_result)
312312

313313

314-
class TestGetAverageTimeToFirstResponse(unittest.TestCase):
315-
"""Test the get_average_time_to_first_response function."""
314+
class TestGetStatsTimeToFirstResponse(unittest.TestCase):
315+
"""Test the get_stats_time_to_first_response function."""
316316

317-
def test_get_average_time_to_first_response(self):
318-
"""Test that get_average_time_to_first_response calculates the correct average.
317+
def test_get_stats_time_to_first_response(self):
318+
"""Test that get_stats_time_to_first_response calculates the correct average.
319319
320320
This test creates a list of mock GitHub issues with time to first response
321-
attributes, calls get_average_time_to_first_response with the list, and
321+
attributes, calls get_stats_time_to_first_response with the list, and
322322
checks that the function returns the correct average time to first response.
323323
324324
"""
@@ -334,12 +334,12 @@ def test_get_average_time_to_first_response(self):
334334
]
335335

336336
# Call the function and check the result
337-
result = get_average_time_to_first_response(issues_with_metrics)['avg']
337+
result = get_stats_time_to_first_response(issues_with_metrics)['avg']
338338
expected_result = timedelta(days=1.5)
339339
self.assertEqual(result, expected_result)
340340

341-
def test_get_average_time_to_first_response_with_all_none(self):
342-
"""Test that get_average_time_to_first_response with all None data."""
341+
def test_get_stats_time_to_first_response_with_all_none(self):
342+
"""Test that get_stats_time_to_first_response with all None data."""
343343

344344
# Create mock data with all None
345345
issues_with_metrics = [
@@ -348,6 +348,6 @@ def test_get_average_time_to_first_response_with_all_none(self):
348348
]
349349

350350
# Call the function and check the result
351-
result = get_average_time_to_first_response(issues_with_metrics)
351+
result = get_stats_time_to_first_response(issues_with_metrics)
352352
expected_result = None
353353
self.assertEqual(result, expected_result)

time_to_answer.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"""A module for measuring the time it takes to answer a GitHub discussion.
22
33
This module provides functions for measuring the time it takes to answer a GitHub
4-
discussion, as well as calculating the average time to answer for a list of discussions.
4+
discussion, as well as calculating stats describing the time to answer for a list of discussions.
55
66
Functions:
7-
get_average_time_to_answer(
7+
get_stats_time_to_answer(
88
issues_with_metrics: List[IssueWithMetrics]
99
) -> Union[timedelta, None]:
10-
Calculate the average time to answer for a list of issues with metrics.
10+
Calculate stats describing the time to answer for a list of issues with metrics.
1111
measure_time_to_answer(
1212
discussion: dict
1313
) -> Union[timedelta, None]:
@@ -22,11 +22,11 @@
2222
from classes import IssueWithMetrics
2323

2424

25-
def get_average_time_to_answer(
25+
def get_stats_time_to_answer(
2626
issues_with_metrics: List[IssueWithMetrics],
2727
) -> Union[timedelta, None]:
2828
"""
29-
Calculate the average time to answer for a list of issues.
29+
Calculate stats describing the time to answer for a list of issues.
3030
"""
3131
# Filter out issues with no time to answer
3232
issues_with_time_to_answer = [
@@ -40,7 +40,7 @@ def get_average_time_to_answer(
4040
if issue.time_to_answer:
4141
answer_times.append(issue.time_to_answer.total_seconds())
4242

43-
# Calculate the average time to answer
43+
# Calculate stats describing time to answer
4444
num_issues_with_time_to_answer = len(issues_with_time_to_answer)
4545
if num_issues_with_time_to_answer > 0:
4646
average_time_to_answer = numpy.average(answer_times)

0 commit comments

Comments
 (0)