-
Notifications
You must be signed in to change notification settings - Fork 373
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
Improve size tracking table #3117
Changes from 3 commits
4d88fd7
52114cb
18827f2
3a9619f
66ec193
f264a29
69d8de1
1f77420
d0da78f
cb697eb
941ec5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,7 +95,7 @@ def render(self, data: list[dict[str, str]]) -> str: | |
return render_table_dict(data) | ||
|
||
|
||
def compare(previous_path: str, current_path: str, threshold: float) -> None: | ||
def compare(previous_path: str, current_path: str, threshold: float, before_header: str, after_header: str) -> None: | ||
previous = json.loads(Path(previous_path).read_text()) | ||
current = json.loads(Path(current_path).read_text()) | ||
|
||
|
@@ -109,21 +109,25 @@ def compare(previous_path: str, current_path: str, threshold: float) -> None: | |
entries[name] = {} | ||
entries[name]["previous"] = entry | ||
|
||
headers = ["Name", "Previous", "Current", "Change"] | ||
headers = ["Name", before_header, after_header, "Change"] | ||
rows: list[tuple[str, str, str, str]] = [] | ||
for name, entry in entries.items(): | ||
if "previous" in entry and "current" in entry: | ||
previous = float(entry["previous"]["value"]) * DIVISORS[entry["previous"]["unit"]] | ||
current = float(entry["current"]["value"]) * DIVISORS[entry["current"]["unit"]] | ||
|
||
min_change = previous * (threshold / 100) | ||
|
||
unit = get_unit(min(previous, current)) | ||
div = get_divisor(unit) | ||
|
||
change = ((previous / current) * 100) - 100 | ||
sign = "+" if change > 0 else "" | ||
change = abs(((current - previous) / previous) * 100) | ||
jprochazk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if current < previous: | ||
sign = "-" | ||
elif current > previous: | ||
sign = "+" | ||
else: | ||
sign = "" | ||
|
||
min_change = previous * (threshold / 100) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The units here confuse me. What unit does I prefer to not use percentages except for ui:s (i.e. multiply with 100 during the formatting). It usually ends up with far less There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you're about to use the script, you're going to run |
||
if abs(current - previous) >= min_change: | ||
rows.append( | ||
( | ||
|
@@ -186,6 +190,20 @@ def main() -> None: | |
default=20, | ||
help="Only print row if value is N%% larger or smaller", | ||
) | ||
compare_parser.add_argument( | ||
"--before-header", | ||
type=str, | ||
required=False, | ||
default="Before", | ||
help="Header for before column", | ||
) | ||
compare_parser.add_argument( | ||
"--after-header", | ||
type=str, | ||
required=False, | ||
default="After", | ||
help="Header for after column", | ||
) | ||
|
||
measure_parser = cmds_parser.add_parser("measure", help="Measure sizes") | ||
measure_parser.add_argument( | ||
|
@@ -200,7 +218,13 @@ def main() -> None: | |
args = parser.parse_args() | ||
|
||
if args.cmd == "compare": | ||
compare(args.before, args.after, args.threshold) | ||
compare( | ||
args.before, | ||
args.after, | ||
args.threshold, | ||
args.before_header, | ||
args.after_header, | ||
) | ||
elif args.cmd == "measure": | ||
measure(args.files, args.format) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that
sizes.py --help
explains the unit ofthreshold
, but that helps very little when reading this file 🤷♂️Not a blocker, just trying to explain my reasoning a bit further.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but I also think that
0.05
is as ambigous as5
if there's no unit :/There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe - but
0.05
is less likely to be of unit Bytes at least :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--threshold-percent
would be very clear in any caseThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do crimes instead:
The
%
is optionalThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, now we're talking 😆