-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from jackra1n/lavalink_stats
Lavalink stats
- Loading branch information
Showing
5 changed files
with
77 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import ux as ux | ||
from .general import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import math | ||
|
||
__all__ = ("seconds_to_human_readable", "bytes_to_human_readable") | ||
|
||
|
||
def seconds_to_human_readable(seconds: int) -> str: | ||
if seconds <= 60: | ||
return "<1 minute" | ||
elif 3600 > seconds > 60: | ||
minutes = seconds // 60 | ||
seconds = seconds % 60 | ||
return f"{int(minutes)}m {int(seconds)}s" | ||
hours = seconds // 3600 # Seconds divided by 3600 gives amount of hours | ||
minutes = (seconds % 3600) // 60 # The remaining seconds are looked at to see how many minutes they make up | ||
if hours >= 24: | ||
days = hours // 24 | ||
hours = hours % 24 | ||
return f"{int(days)}d {int(hours)}h {int(minutes)}m" | ||
return f"{int(hours)}h {int(minutes)}m" | ||
|
||
|
||
def bytes_to_human_readable(size_in_bytes: int) -> str: | ||
units = ("B", "KB", "MB", "GB", "TB") | ||
power = int(math.log(size_in_bytes, 1024)) | ||
return f"{size_in_bytes / (1024 ** power):.1f} {units[power]}" |