Skip to content

Commit

Permalink
Fix long stat value units (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
R055A authored Oct 17, 2023
1 parent 0b40900 commit 33e8634
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/generate_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def add_metric_unit(num):
metric_units = ['K', 'M', 'B', 'T']
metric_units_index = -1

num = int(num.replace(',', ''))

if num > 9999:
while num > 999:
num /= 1000
Expand Down Expand Up @@ -121,9 +123,9 @@ async def generate_overview(self) -> None:
output)

forks = f"{await self.__stats.forks:,}"
forks = forks if len(str(forks)) < TXT_SPACER_MAX_LEN else add_metric_unit(int(forks))
forks = forks if len(str(forks)) < TXT_SPACER_MAX_LEN else add_metric_unit(forks)
stars = f"{await self.__stats.stargazers:,}"
stars = stars if len(str(stars)) < TXT_SPACER_MAX_LEN else add_metric_unit(int(stars))
stars = stars if len(str(stars)) < TXT_SPACER_MAX_LEN else add_metric_unit(stars)
forks_and_stars = \
forks + ' ' * max(1, TXT_SPACER_MAX_LEN - len(str(forks)) + 1) + '| ' + stars
output = sub("{{ forks_and_stars }}",
Expand Down Expand Up @@ -163,9 +165,9 @@ async def generate_overview(self) -> None:

pull_requests = f"{await self.__stats.pull_requests:,}"
pull_requests = pull_requests if len(str(pull_requests)) < TXT_SPACER_MAX_LEN \
else add_metric_unit(int(pull_requests))
else add_metric_unit(pull_requests)
issues = f"{await self.__stats.issues:,}"
issues = stars if len(str(issues)) < TXT_SPACER_MAX_LEN else add_metric_unit(int(issues))
issues = stars if len(str(issues)) < TXT_SPACER_MAX_LEN else add_metric_unit(issues)
pull_requests_and_issues = \
pull_requests + ' ' * max(1, TXT_SPACER_MAX_LEN - len(str(pull_requests)) + 1) + '| ' + issues
output = sub("{{ pull_requests_and_issues }}",
Expand Down

0 comments on commit 33e8634

Please sign in to comment.