Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove sub-seconds from stats #147

Merged
merged 5 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,25 @@ def get_stats_time_in_labels(
if issue.label_metrics[label] is None:
continue
if label not in time_in_labels:
time_in_labels[label] = [issue.label_metrics[label]]
time_in_labels[label] = [issue.label_metrics[label].total_seconds()]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of this PR is add numpy.round() and some cosmetic changes.

Just curious, why did you have to add the .total_seconds here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was definitely a mistake. In fact if the label is not in time_in_labels then I don't think we should be doing anything! I'll fix the total_seconds part here and remove the whole line in a separate PR with some testing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I was wrong. 😄 This is needed. This part of the code stores the timedelta information for a given label and instead of storing it as a timedelta object, i'm choosing to store it as a number representing total_seconds so that round and averaging is easier. It is later converted back into a timedelta object after the math operations are complete.

else:
time_in_labels[label].append(issue.label_metrics[label])
time_in_labels[label].append(
issue.label_metrics[label].total_seconds()
)

average_time_in_labels = {}
med_time_in_labels = {}
ninety_percentile_in_labels = {}
for label, time_list in time_in_labels.items():
average_time_in_labels[label] = numpy.average(time_list)
med_time_in_labels[label] = numpy.median(time_list)
ninety_percentile_in_labels[label] = numpy.percentile(time_list, 90, axis=0)
average_time_in_labels[label] = timedelta(
seconds=numpy.round(numpy.average(time_list))
)
med_time_in_labels[label] = timedelta(
seconds=numpy.round(numpy.median(time_list))
)
ninety_percentile_in_labels[label] = timedelta(
seconds=numpy.round(numpy.percentile(time_list, 90, axis=0))
)

for label in labels:
if label not in average_time_in_labels:
Expand All @@ -120,8 +128,8 @@ def get_stats_time_in_labels(
ninety_percentile_in_labels[label] = None

stats = {
'avg': average_time_in_labels,
'med': med_time_in_labels,
'90p': ninety_percentile_in_labels
"avg": average_time_in_labels,
"med": med_time_in_labels,
"90p": ninety_percentile_in_labels,
}
return stats
15 changes: 9 additions & 6 deletions time_to_answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,19 @@ def get_stats_time_to_answer(
# Calculate stats describing time to answer
num_issues_with_time_to_answer = len(issues_with_time_to_answer)
if num_issues_with_time_to_answer > 0:
average_time_to_answer = numpy.average(answer_times)
med_time_to_answer = numpy.median(answer_times)
ninety_percentile_time_to_answer = numpy.percentile(answer_times, 90, axis=0)
average_time_to_answer = numpy.round(numpy.average(answer_times))
med_time_to_answer = numpy.round(numpy.median(answer_times))
ninety_percentile_time_to_answer = numpy.round(
numpy.percentile(answer_times, 90, axis=0)
)
else:
return None

stats = {
'avg': timedelta(seconds=average_time_to_answer),
'med': timedelta(seconds=med_time_to_answer),
'90p': timedelta(seconds=ninety_percentile_time_to_answer)}
"avg": timedelta(seconds=average_time_to_answer),
"med": timedelta(seconds=med_time_to_answer),
"90p": timedelta(seconds=ninety_percentile_time_to_answer),
}

# Print the average time to answer converting seconds to a readable time format
print(f"Average time to answer: {timedelta(seconds=average_time_to_answer)}")
Expand Down
15 changes: 9 additions & 6 deletions time_to_close.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,19 @@ def get_stats_time_to_close(
# Calculate stats describing time to close
num_issues_with_time_to_close = len(issues_with_time_to_close)
if num_issues_with_time_to_close > 0 and total_time_to_close is not None:
average_time_to_close = numpy.average(close_times)
med_time_to_close = numpy.median(close_times)
ninety_percentile_time_to_close = numpy.percentile(close_times, 90, axis=0)
average_time_to_close = numpy.round(numpy.average(close_times))
med_time_to_close = numpy.round(numpy.median(close_times))
ninety_percentile_time_to_close = numpy.round(
numpy.percentile(close_times, 90, axis=0)
)
else:
return None

stats = {
'avg': timedelta(seconds=average_time_to_close),
'med': timedelta(seconds=med_time_to_close),
'90p': timedelta(seconds=ninety_percentile_time_to_close)}
"avg": timedelta(seconds=average_time_to_close),
"med": timedelta(seconds=med_time_to_close),
"90p": timedelta(seconds=ninety_percentile_time_to_close),
}

# Print the average time to close converting seconds to a readable time format
print(f"Time to close: {timedelta(seconds=average_time_to_close)}")
Expand Down
35 changes: 25 additions & 10 deletions time_to_first_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ def measure_time_to_first_response(
number=20, sort="created", direction="asc"
) # type: ignore
for comment in comments:
if ignore_comment(issue.issue.user, comment.user, ignore_users, comment.created_at, ready_for_review_at):
if ignore_comment(
issue.issue.user,
comment.user,
ignore_users,
comment.created_at,
ready_for_review_at,
):
continue
first_comment_time = comment.created_at
break
Expand All @@ -68,8 +74,13 @@ def measure_time_to_first_response(
if pull_request:
review_comments = pull_request.reviews(number=50) # type: ignore
for review_comment in review_comments:
if ignore_comment(issue.issue.user, review_comment.user, ignore_users,
review_comment.submitted_at, ready_for_review_at):
if ignore_comment(
issue.issue.user,
review_comment.user,
ignore_users,
review_comment.submitted_at,
ready_for_review_at,
):
continue
first_review_comment_time = review_comment.submitted_at
break
Expand Down Expand Up @@ -119,7 +130,8 @@ def ignore_comment(
# ignore comments by the issue creator
or comment_user.login == issue_user.login
# ignore comments created before the issue was ready for review
or (ready_for_review_at and comment_created_at < ready_for_review_at))
or (ready_for_review_at and comment_created_at < ready_for_review_at)
)


def get_stats_time_to_first_response(
Expand All @@ -145,14 +157,17 @@ def get_stats_time_to_first_response(
if len(issues) - none_count <= 0:
return None

average_seconds_to_first_response = numpy.average(response_times)
med_seconds_to_first_response = numpy.median(response_times)
ninety_percentile_seconds_to_first_response = numpy.percentile(response_times, 90, axis=0)
average_seconds_to_first_response = numpy.round(numpy.average(response_times))
med_seconds_to_first_response = numpy.round(numpy.median(response_times))
ninety_percentile_seconds_to_first_response = numpy.round(
numpy.percentile(response_times, 90, axis=0)
)

stats = {
'avg': timedelta(seconds=average_seconds_to_first_response),
'med': timedelta(seconds=med_seconds_to_first_response),
'90p': timedelta(seconds=ninety_percentile_seconds_to_first_response)}
"avg": timedelta(seconds=average_seconds_to_first_response),
"med": timedelta(seconds=med_seconds_to_first_response),
"90p": timedelta(seconds=ninety_percentile_seconds_to_first_response),
}

# Print the average time to first response converting seconds to a readable time format
print(
Expand Down