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

Report warnings count and delta, if enabled in the report artifact #101

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
47 changes: 38 additions & 9 deletions reportsizedeltas/reportsizedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class ReportKeys:
maximum = "maximum"
sketches = "sketches"
compilation_success = "compilation_success"
warnings = "warnings"

def __init__(self, repository_name: str, sketches_reports_source: str, token: str) -> None:
self.repository_name = repository_name
Expand Down Expand Up @@ -414,7 +415,9 @@ def add_summary_report_row(self, report_data, fqbn_data) -> None:
# Populate the row with data
for size_data in fqbn_data[self.ReportKeys.sizes]:
# Determine column number for this memory type
column_number = get_report_column_number(report=report_data, column_heading=size_data[self.ReportKeys.name])
column_number = get_report_column_number(
report=report_data, column_heading=size_data[self.ReportKeys.name], extra_column_heading="%"
)

# Add the memory data to the cell
if self.ReportKeys.delta in size_data:
Expand All @@ -441,6 +444,17 @@ def add_summary_report_row(self, report_data, fqbn_data) -> None:
report_data[row_number][column_number + 1] = self.get_summary_value(
show_emoji=False, minimum=self.not_applicable_indicator, maximum=self.not_applicable_indicator
)
if self.ReportKeys.warnings in fqbn_data:
column_number = get_report_column_number(
report=report_data, column_heading="Warnings<br>+/-", extra_column_heading=None
)
warnings_data = fqbn_data[self.ReportKeys.warnings]
deltas = warnings_data[self.ReportKeys.delta][self.ReportKeys.absolute]
report_data[row_number][column_number] = self.get_summary_value(
show_emoji=True,
minimum=deltas[self.ReportKeys.minimum],
maximum=deltas[self.ReportKeys.maximum],
)

def add_detailed_report_row(self, report_data, fqbn_data) -> None:
"""Add a row to the detailed report.
Expand All @@ -466,6 +480,7 @@ def add_detailed_report_row(self, report_data, fqbn_data) -> None:
sketch_name=sketch[self.ReportKeys.name], size_name=size_data[self.ReportKeys.name]
)
),
extra_column_heading="%",
)

# Add the memory data to the cell
Expand All @@ -484,6 +499,20 @@ def add_detailed_report_row(self, report_data, fqbn_data) -> None:
# Relative
report_data[row_number][column_number + 1] = self.not_applicable_indicator

if self.ReportKeys.warnings in sketch:
warnings_data = sketch[self.ReportKeys.warnings]
column_number = get_report_column_number(
report=report_data,
column_heading=(
"`{sketch_name}`<br>Warnings<br>+/-".format(sketch_name=sketch[self.ReportKeys.name])
),
extra_column_heading="Warnings<br>current",
)
report_data[row_number][column_number] = warnings_data[self.ReportKeys.delta][self.ReportKeys.absolute]
report_data[row_number][column_number + 1] = warnings_data[self.ReportKeys.current][
self.ReportKeys.absolute
]

def get_summary_value(self, show_emoji: bool, minimum, maximum) -> str:
"""Return the Markdown formatted text for a memory change data cell in the report table.

Expand Down Expand Up @@ -740,14 +769,13 @@ def get_page_count(link_header: str | None) -> int:
return page_count


def get_report_column_number(report, column_heading: str) -> int:
def get_report_column_number(report, column_heading: str, extra_column_heading: str | None) -> int:
"""Return the column number of the given heading.

Keyword arguments:
column_heading -- the text of the column heading. If it doesn't exist, a column will be created with this heading.
extra_column_heading -- if not None, an additional column with this header (needs not be unique) will be created.
"""
relative_column_heading = "%"

try:
column_number = report[0].index(column_heading, 1)
except ValueError:
Expand All @@ -760,11 +788,12 @@ def get_report_column_number(report, column_heading: str) -> int:
# Expand the size of the final row (the current row) to match the new number of columns
report[len(report) - 1].append("")

# Relative column
# Add the heading
report[0].append(relative_column_heading)
# Expand the size of the final row (the current row) to match the new number of columns
report[len(report) - 1].append("")
if extra_column_heading is not None:
# Extra column
# Add the heading
report[0].append(extra_column_heading)
# Expand the size of the final row (the current row) to match the new number of columns
report[len(report) - 1].append("")

return column_number

Expand Down
4 changes: 3 additions & 1 deletion reportsizedeltas/tests/test_reportsizedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,9 @@ def test_get_page_count():
)
def test_get_report_column_number(report, column_heading, expected_column_number, expected_report):
assert (
reportsizedeltas.get_report_column_number(report=report, column_heading=column_heading)
reportsizedeltas.get_report_column_number(
report=report, column_heading=column_heading, extra_column_heading="%"
)
== expected_column_number
)
assert report == expected_report
Expand Down
Loading