use Base 1000 instead 1024 for capacity prefix

This commit is contained in:
Hendrik Schutter 2022-12-07 18:00:12 +01:00
parent 12a4da0902
commit 5de6b107d2
2 changed files with 9 additions and 2 deletions

View File

@ -62,13 +62,20 @@ def get_font_path_bold():
files = glob.glob(path + "/**/DejaVuSans-Bold.ttf", recursive = True)
return files[0]
def human_readable_capacity(size, decimal_places=0):
def human_readable_capacity_1024(size, decimal_places=0):
for unit in ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB']:
if size < 1024.0 or unit == 'PiB':
break
size /= 1024.0
return f"{size:.{decimal_places}f} {unit}"
def human_readable_capacity_1000(size, decimal_places=0):
for unit in ['B', 'KB', 'MB', 'GB', 'TB', 'PB']:
if size < 1000.0 or unit == 'PB':
break
size /= 1000.0
return f"{size:.{decimal_places}f} {unit}"
def human_readable_power_on_hours(hours, decimal_places=2):
return str(hours) + "h or " + str(int(hours/24)) + "d or " + str("{:.2f}".format(float(hours/24/365))) + "y"
@ -82,7 +89,7 @@ def format_to_printable(drive):
return DriveDataPrintable(
cut_string(20, re.sub(r"[^a-zA-Z0-9. ]", "", drive.modelfamiliy)),\
cut_string(20, re.sub(r"[^a-zA-Z0-9. ]", "", drive.modelname)),\
cut_string(20, human_readable_capacity(drive.capacity)),\
cut_string(20, human_readable_capacity_1000(drive.capacity)),\
cut_string(16, re.sub(r"[^a-zA-Z0-9.-_]", "", drive.serialnumber)),\
cut_string(30, human_readable_power_on_hours(drive.power_on_hours)),\
cut_string(10, str(drive.power_cycle)),\

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB