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

Split out the summary table into 2 tables #148

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 11 additions & 4 deletions markdown_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def write_to_markdown(
file.write("# Issue Metrics\n\n")

# Write first table with overall metrics
write_overall_metrics_table(
write_overall_metrics_tables(
issues_with_metrics,
average_time_to_first_response,
average_time_to_close,
Expand Down Expand Up @@ -168,7 +168,7 @@ def write_to_markdown(
print("Wrote issue metrics to issue_metrics.md")


def write_overall_metrics_table(
def write_overall_metrics_tables(
issues_with_metrics,
stats_time_to_first_response,
stats_time_to_close,
Expand All @@ -180,7 +180,7 @@ def write_overall_metrics_table(
columns,
file,
):
"""Write the overall metrics table to the markdown file."""
"""Write the overall metrics tables to the markdown file."""
file.write("| Metric | Average | Median | 90th percentile |\n")
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe before doing any of this, one would have to check if the 1st stable will contain any data?

Something along the lines of this:

    if "Time to first response" in columns \
        or "Time to close" in columns \
        or "Time to answer" in columns \
        or labels:

Copy link
Contributor

Choose a reason for hiding this comment

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

I did a quick test locally, and confirmed that this would indeed prevent the generation of the 1st table in this scenario.

I also confirmed that if at least one of these columns exists, the 1st table will be generated.

However we should probably add a real test case for this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm on it! Thanks @spier!

Copy link
Member Author

Choose a reason for hiding this comment

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

Check out 3da633e

Copy link
Member Author

Choose a reason for hiding this comment

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

Shifted the logic you suggested for the labels a bit since there is a corner case where there are labels but a user has marked HIDE_LABELS_COLUMN as True.

file.write("| --- | --- | --- | ---: |\n")
if "Time to first response" in columns:
Expand Down Expand Up @@ -215,13 +215,20 @@ def write_overall_metrics_table(
file.write("| Time to answer | None | None | None |\n")
if labels and stats_time_in_labels:
for label in labels:
if f"Time spent in {label}" in columns and label in stats_time_in_labels['avg']:
if (
f"Time spent in {label}" in columns
and label in stats_time_in_labels["avg"]
):
file.write(
f"| Time spent in {label} "
f"| {stats_time_in_labels['avg'][label]} "
f"| {stats_time_in_labels['med'][label]} "
f"| {stats_time_in_labels['90p'][label]} |\n"
)
# Write count stats to a separate table
file.write("\n")
file.write("| Metric | Count |\n")
file.write("| --- | ---: |\n")
file.write(f"| Number of items that remain open | {num_issues_opened} |\n")
file.write(f"| Number of items closed | {num_issues_closed} |\n")
file.write(f"| Total number of items created | {len(issues_with_metrics)} |\n\n")
66 changes: 42 additions & 24 deletions test_markdown_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

class TestWriteToMarkdown(unittest.TestCase):
"""Test the write_to_markdown function."""

maxDiff = None

def test_write_to_markdown(self):
Expand Down Expand Up @@ -50,21 +51,25 @@ def test_write_to_markdown(self):
),
]
time_to_first_response = {
'avg': timedelta(days=2),
'med': timedelta(days=2),
'90p': timedelta(days=2)}
"avg": timedelta(days=2),
"med": timedelta(days=2),
"90p": timedelta(days=2),
}
time_to_close = {
'avg': timedelta(days=3),
'med': timedelta(days=3),
'90p': timedelta(days=3)}
"avg": timedelta(days=3),
"med": timedelta(days=3),
"90p": timedelta(days=3),
}
time_to_answer = {
'avg': timedelta(days=4),
'med': timedelta(days=4),
'90p': timedelta(days=4)}
"avg": timedelta(days=4),
"med": timedelta(days=4),
"90p": timedelta(days=4),
}
time_in_labels = {
'avg': {"bug": "1 day, 12:00:00"},
'med': {"bug": "1 day, 12:00:00"},
'90p': {"bug": "1 day, 12:00:00"}}
"avg": {"bug": "1 day, 12:00:00"},
"med": {"bug": "1 day, 12:00:00"},
"90p": {"bug": "1 day, 12:00:00"},
}

num_issues_opened = 2
num_issues_closed = 1
Expand Down Expand Up @@ -93,6 +98,9 @@ def test_write_to_markdown(self):
"| Time to close | 3 days, 0:00:00 | 3 days, 0:00:00 | 3 days, 0:00:00 |\n"
"| Time to answer | 4 days, 0:00:00 | 4 days, 0:00:00 | 4 days, 0:00:00 |\n"
"| Time spent in bug | 1 day, 12:00:00 | 1 day, 12:00:00 | 1 day, 12:00:00 |\n"
"\n"
"| Metric | Count |\n"
"| --- | ---: |\n"
"| Number of items that remain open | 2 |\n"
"| Number of items closed | 1 |\n"
"| Total number of items created | 2 |\n\n"
Expand Down Expand Up @@ -140,21 +148,25 @@ def test_write_to_markdown_with_vertical_bar_in_title(self):
),
]
average_time_to_first_response = {
'avg': timedelta(days=2),
'med': timedelta(days=2),
'90p': timedelta(days=2)}
"avg": timedelta(days=2),
"med": timedelta(days=2),
"90p": timedelta(days=2),
}
average_time_to_close = {
'avg': timedelta(days=3),
'med': timedelta(days=3),
'90p': timedelta(days=3)}
"avg": timedelta(days=3),
"med": timedelta(days=3),
"90p": timedelta(days=3),
}
average_time_to_answer = {
'avg': timedelta(days=4),
'med': timedelta(days=4),
'90p': timedelta(days=4)}
"avg": timedelta(days=4),
"med": timedelta(days=4),
"90p": timedelta(days=4),
}
average_time_in_labels = {
'avg': {"bug": "1 day, 12:00:00"},
'med': {"bug": "1 day, 12:00:00"},
'90p': {"bug": "1 day, 12:00:00"}}
"avg": {"bug": "1 day, 12:00:00"},
"med": {"bug": "1 day, 12:00:00"},
"90p": {"bug": "1 day, 12:00:00"},
}

num_issues_opened = 2
num_issues_closed = 1
Expand Down Expand Up @@ -182,6 +194,9 @@ def test_write_to_markdown_with_vertical_bar_in_title(self):
"| Time to close | 3 days, 0:00:00 | 3 days, 0:00:00 | 3 days, 0:00:00 |\n"
"| Time to answer | 4 days, 0:00:00 | 4 days, 0:00:00 | 4 days, 0:00:00 |\n"
"| Time spent in bug | 1 day, 12:00:00 | 1 day, 12:00:00 | 1 day, 12:00:00 |\n"
"\n"
"| Metric | Count |\n"
"| --- | ---: |\n"
"| Number of items that remain open | 2 |\n"
"| Number of items closed | 1 |\n"
"| Total number of items created | 2 |\n\n"
Expand Down Expand Up @@ -288,6 +303,9 @@ def test_writes_markdown_file_with_non_hidden_columns_only(self):
"# Issue Metrics\n\n"
"| Metric | Average | Median | 90th percentile |\n"
"| --- | --- | --- | ---: |\n"
"\n"
"| Metric | Count |\n"
"| --- | ---: |\n"
"| Number of items that remain open | 2 |\n"
"| Number of items closed | 1 |\n"
"| Total number of items created | 2 |\n\n"
Expand Down