Indent file with TABS

This commit is contained in:
Mario Hüttel 2022-08-05 21:47:33 +02:00
parent b00cc19e61
commit ac0f363a1e

View File

@ -1,67 +1,67 @@
class EngineeringNumberConverter(): class EngineeringNumberConverter():
prefixes = [ prefixes = [
('y', 1e-24), ('y', 1e-24),
('z', 1e-21), ('z', 1e-21),
('a', 1e-18), ('a', 1e-18),
('f', 1e-15), ('f', 1e-15),
('p', 1e-12), ('p', 1e-12),
('n', 1e-9), ('n', 1e-9),
('u', 1e-6), ('u', 1e-6),
('m', 1e-3), ('m', 1e-3),
# We skip centi and dezi because no one really uses these besides for length measurements # We skip centi and dezi because no one really uses these besides for length measurements
('', 1), ('', 1),
# We also skip h for hekto # We also skip h for hekto
('k', 1e3), ('k', 1e3),
('M', 1e6), ('M', 1e6),
('G', 1e9), ('G', 1e9),
('T', 1e12), ('T', 1e12),
('P', 1e15), ('P', 1e15),
('E', 1e18), ('E', 1e18),
('Z', 1e21), ('Z', 1e21),
('Y', 1e24), ('Y', 1e24),
] ]
it_prefixes = [ it_prefixes = [
('', 1), ('', 1),
('Ki', 1024), ('Ki', 1024),
('Mi', 1024*1024), ('Mi', 1024*1024),
('Gi', 1024*1024*1024), ('Gi', 1024*1024*1024),
('Ti', 1024*1024*1024*1024) ('Ti', 1024*1024*1024*1024)
] ]
@classmethod
def number_to_engineering(c, number, it_unit = False):
"""
Convert a number to engineering SI syntax with prefix.
This function will return a tuple of (new_number, prefix)
"""
if it_unit:
used_prefixes = c.it_prefixes
else:
used_prefixes = c.prefixes
if (len(used_prefixes) < 2): @classmethod
return (number / used_prefixes[0][1], used_prefixes[0]) def number_to_engineering(c, number, it_unit=False):
"""
for i, (prefix, scale) in enumerate(used_prefixes[1:], 1): Convert a number to engineering SI syntax with prefix.
if number < scale: This function will return a tuple of (new_number, prefix)
return (number / used_prefixes[i-1][1], used_prefixes[i-1][0]) """
if it_unit:
return (number / used_prefixes[-1][1], used_prefixes[-1][0]) used_prefixes = c.it_prefixes
else:
used_prefixes = c.prefixes
@classmethod if (len(used_prefixes) < 2):
def engineering_to_number(c, input): return (number / used_prefixes[0][1], used_prefixes[0])
cleaned_input = input.strip().replace(' ', '')
selected_scaling = 1 for i, (prefix, scale) in enumerate(used_prefixes[1:], 1):
if number < scale:
return (number / used_prefixes[i-1][1], used_prefixes[i-1][0])
for (prefix, scale) in c.prefixes+c.it_prefixes: return (number / used_prefixes[-1][1], used_prefixes[-1][0])
if prefix == '':
continue @classmethod
if cleaned_input.endswith(prefix): def engineering_to_number(c, input):
cleaned_input = cleaned_input.replace(prefix, '') cleaned_input = input.strip().replace(' ', '')
selected_scaling = scale
break selected_scaling = 1
return float(cleaned_input) * selected_scaling for (prefix, scale) in c.prefixes+c.it_prefixes:
if prefix == '':
continue
if cleaned_input.endswith(prefix):
cleaned_input = cleaned_input.replace(prefix, '')
selected_scaling = scale
break
return float(cleaned_input) * selected_scaling