From 5a3394c0f4050a9e848ec2b3313a357720f4ac9e Mon Sep 17 00:00:00 2001 From: Robin Avery Date: Wed, 25 Sep 2024 21:00:17 -0400 Subject: [PATCH] Update `wiki_tu` to new report format (#1469) --- tools/wiki_tu.py | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/tools/wiki_tu.py b/tools/wiki_tu.py index e66425125f..e2d53306e2 100755 --- a/tools/wiki_tu.py +++ b/tools/wiki_tu.py @@ -8,12 +8,7 @@ import humanfriendly import mistletoe -from mistletoe.block_token import ( - BlockToken, - Table, - TableRow, - re, -) +from mistletoe.block_token import BlockToken, Table, TableRow, re from mistletoe.span_token import RawText from mistletoe.token import Token @@ -86,23 +81,21 @@ def write(args): ) for unit in data["units"] or []: - def friendly_size(key: str) -> str: - return ( - f"`{humanfriendly.format_size(unit[key] or 0).replace('bytes', 'B')}`" - ) + def friendly_size(value: int) -> str: + return f"`{humanfriendly.format_size(value).replace('bytes', 'B')}`" # Strip "main/" by splitting on "/" and recombining file = "/".join((unit["name"] or "/").split("/")[1:]) # Link to source file file_link = f"[`{file}`](../blob/master/src/{file}.c)" - matched_code = float(unit["matched_code"]) - total_code = float(unit["total_code"]) - code_percent = (matched_code / total_code if total_code else 0) * 100 - matched = f"{friendly_size('matched_code')}" - total = f"{friendly_size('total_code')}" + matched_code = int(unit["measures"].get("matched_code") or 0) + total_code = int(unit["measures"].get("total_code") or 0) + code_percent = float(unit["measures"].get("matched_code_percent") or 0) + matched = f"{friendly_size(matched_code)}" + total = f"{friendly_size(total_code)}" percent = f"`{humanfriendly.round_number(code_percent)}%`" - linked = ":heavy_check_mark:" if unit["complete"] else ":x:" + linked = ":heavy_check_mark:" if unit["metadata"].get("complete") else ":x:" if assignee := assignees.get(file): discord = f"`{assignee['discord']}`"