Skip to content

Commit 6c4bca4

Browse files
committed
Changed format_total() to not abbr 10k-999m
1 parent 4b26f44 commit 6c4bca4

1 file changed

Lines changed: 24 additions & 7 deletions

File tree

utils/update_root_downloads_shield.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,30 @@ def get_downloads(pkg: str, max_retries: int = 5, get_delay: int = 1) -> int:
4747
print(f'{pkg}: Failed after {max_retries} retries')
4848
return 0
4949

50-
def format_total(num: int) -> str: # abbr ints to e.g. 1.5k, 2b
51-
return (
52-
f'{num / 1000000000:.1f}B' if num >= 1000000000
53-
else f'{num / 1000000:.1f}M' if num >= 1000000
54-
else f'{num / 1000:.1f}K' if num >= 1000
55-
else str(num)
56-
).replace('.0', '')
50+
def format_total(num: int) -> str:
51+
first_digit = str(num)[0] if num else '0'
52+
second_digit = str(num)[1] if num > 9 else '0'
53+
second_digit_rounded = '0' if int(second_digit) < 5 else '5'
54+
if num >= 1_000_000_000:
55+
formatted = f'{num // 1_000_000_000}'
56+
remainder = (num % 1_000_000_000) // 100_000_000
57+
if remainder : formatted += f'.{remainder}'
58+
return formatted + 'B+'
59+
elif num >= 10_000_000:
60+
return f'{(num // 1_000_000) * 1_000_000:,}+'
61+
elif num >= 1_000_000:
62+
return f'{first_digit},{second_digit}00,000+'
63+
elif num >= 100_000:
64+
return f'{first_digit}{second_digit_rounded}0,000+'
65+
elif num >= 10_000:
66+
return f'{first_digit}0,000+'
67+
elif num >= 1_000:
68+
formatted = f'{num // 1000}'
69+
remainder = (num % 1000) // 100
70+
if remainder : formatted += f'.{remainder}'
71+
return formatted + 'K'
72+
else:
73+
return str(num)
5774

5875
def read_file(file_path: str) -> list[str]:
5976
with open(file_path, 'r', encoding='utf-8') as file:

0 commit comments

Comments
 (0)