diff --git a/README.md b/README.md index 8d48e69..123bde7 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ print(results6.to_string(LengthUnits.Meter)) # 1000 m # Complex objects # Any object supports arithmetic operations can be used as well as unit -# see numpay array example: +# see numpy array example: import numpy as np np_array = np.array([[2, 4, 6], [7, 8, 9]]) diff --git a/tests/test_unit_conversion.py b/tests/test_unit_conversion.py index 5822e91..7305480 100644 --- a/tests/test_unit_conversion.py +++ b/tests/test_unit_conversion.py @@ -3,6 +3,7 @@ Angle, Length, LengthUnits, + Information ) @@ -31,6 +32,14 @@ def test_convert_unit_prefix_to_base(self): angle = Angle.from_microradians(3141592.65358979) self.assertAlmostEqual(angle.degrees, 180, delta=0.00001) + def test_convert_bits_prefix_to_base(self): + data = Information.from_kibibits(1) + self.assertAlmostEqual(data.bits, 1024) + + def test_convert_base_to_bits_prefix(self): + data = Information.from_bits(1024) + self.assertAlmostEqual(data.kibibits, 1) + def test_convert_to_specific_unit_enum(self): param_list = [ (LengthUnits.Meter, LengthUnits.Centimeter, 'centimeters'), diff --git a/units_generator/common/utils.py b/units_generator/common/utils.py index 42b05f2..12d4356 100644 --- a/units_generator/common/utils.py +++ b/units_generator/common/utils.py @@ -81,6 +81,12 @@ def upper_to_lower_camelcase(s): 'Nano': 1e-9, 'Pico': 1e-12, 'Femto': 1e-15, + 'Kibi': 1024, + 'Mebi': 1024 ** 2, + 'Gibi': 1024 ** 3, + 'Tebi': 1024 ** 4, + 'Pebi': 1024 ** 5, + 'Exbi': 1024 ** 6 } @@ -99,5 +105,11 @@ def upper_to_lower_camelcase(s): 'Micro': 'μ', 'Nano': 'n', 'Pico': 'p', - 'Femto': 'f' + 'Femto': 'f', + 'Kibi': 'KiB', + 'Mebi': 'MiB', + 'Gibi': 'GiB', + 'Tebi': 'TiB', + 'Pebi': 'PiB', + 'Exbi': 'EiB', } diff --git a/units_generator/templates/readme_template.jinja2 b/units_generator/templates/readme_template.jinja2 index 87038d7..154fbdd 100644 --- a/units_generator/templates/readme_template.jinja2 +++ b/units_generator/templates/readme_template.jinja2 @@ -99,7 +99,7 @@ print(results6.to_string(LengthUnits.Meter)) # 1000 m # Complex objects # Any object supports arithmetic operations can be used as well as unit -# see numpay array example: +# see numpy array example: import numpy as np np_array = np.array([[2, 4, 6], [7, 8, 9]]) diff --git a/unitsnet_py/units/bit_rate.py b/unitsnet_py/units/bit_rate.py index 6f2887f..5aa6d4d 100644 --- a/unitsnet_py/units/bit_rate.py +++ b/unitsnet_py/units/bit_rate.py @@ -50,6 +50,36 @@ class BitRateUnits(Enum): """ + KibibitPerSecond = 'KibibitPerSecond' + """ + + """ + + MebibitPerSecond = 'MebibitPerSecond' + """ + + """ + + GibibitPerSecond = 'GibibitPerSecond' + """ + + """ + + TebibitPerSecond = 'TebibitPerSecond' + """ + + """ + + PebibitPerSecond = 'PebibitPerSecond' + """ + + """ + + ExbibitPerSecond = 'ExbibitPerSecond' + """ + + """ + KilobytePerSecond = 'KilobytePerSecond' """ @@ -80,6 +110,36 @@ class BitRateUnits(Enum): """ + KibibytePerSecond = 'KibibytePerSecond' + """ + + """ + + MebibytePerSecond = 'MebibytePerSecond' + """ + + """ + + GibibytePerSecond = 'GibibytePerSecond' + """ + + """ + + TebibytePerSecond = 'TebibytePerSecond' + """ + + """ + + PebibytePerSecond = 'PebibytePerSecond' + """ + + """ + + ExbibytePerSecond = 'ExbibytePerSecond' + """ + + """ + class BitRateDto: """ @@ -162,6 +222,18 @@ def __init__(self, value: float, from_unit: BitRateUnits = BitRateUnits.BitPerSe self.__exabits_per_second = None + self.__kibibits_per_second = None + + self.__mebibits_per_second = None + + self.__gibibits_per_second = None + + self.__tebibits_per_second = None + + self.__pebibits_per_second = None + + self.__exbibits_per_second = None + self.__kilobytes_per_second = None self.__megabytes_per_second = None @@ -174,6 +246,18 @@ def __init__(self, value: float, from_unit: BitRateUnits = BitRateUnits.BitPerSe self.__exabytes_per_second = None + self.__kibibytes_per_second = None + + self.__mebibytes_per_second = None + + self.__gibibytes_per_second = None + + self.__tebibytes_per_second = None + + self.__pebibytes_per_second = None + + self.__exbibytes_per_second = None + def convert(self, unit: BitRateUnits) -> float: return self.__convert_from_base(unit) @@ -253,6 +337,24 @@ def __convert_from_base(self, from_unit: BitRateUnits) -> float: if from_unit == BitRateUnits.ExabitPerSecond: return ((value) / 1e+18) + if from_unit == BitRateUnits.KibibitPerSecond: + return ((value) / 1024) + + if from_unit == BitRateUnits.MebibitPerSecond: + return ((value) / 1048576) + + if from_unit == BitRateUnits.GibibitPerSecond: + return ((value) / 1073741824) + + if from_unit == BitRateUnits.TebibitPerSecond: + return ((value) / 1099511627776) + + if from_unit == BitRateUnits.PebibitPerSecond: + return ((value) / 1125899906842624) + + if from_unit == BitRateUnits.ExbibitPerSecond: + return ((value) / 1152921504606846976) + if from_unit == BitRateUnits.KilobytePerSecond: return ((value / 8) / 1000.0) @@ -271,6 +373,24 @@ def __convert_from_base(self, from_unit: BitRateUnits) -> float: if from_unit == BitRateUnits.ExabytePerSecond: return ((value / 8) / 1e+18) + if from_unit == BitRateUnits.KibibytePerSecond: + return ((value / 8) / 1024) + + if from_unit == BitRateUnits.MebibytePerSecond: + return ((value / 8) / 1048576) + + if from_unit == BitRateUnits.GibibytePerSecond: + return ((value / 8) / 1073741824) + + if from_unit == BitRateUnits.TebibytePerSecond: + return ((value / 8) / 1099511627776) + + if from_unit == BitRateUnits.PebibytePerSecond: + return ((value / 8) / 1125899906842624) + + if from_unit == BitRateUnits.ExbibytePerSecond: + return ((value / 8) / 1152921504606846976) + return None @@ -300,6 +420,24 @@ def __convert_to_base(self, value: float, to_unit: BitRateUnits) -> float: if to_unit == BitRateUnits.ExabitPerSecond: return ((value) * 1e+18) + if to_unit == BitRateUnits.KibibitPerSecond: + return ((value) * 1024) + + if to_unit == BitRateUnits.MebibitPerSecond: + return ((value) * 1048576) + + if to_unit == BitRateUnits.GibibitPerSecond: + return ((value) * 1073741824) + + if to_unit == BitRateUnits.TebibitPerSecond: + return ((value) * 1099511627776) + + if to_unit == BitRateUnits.PebibitPerSecond: + return ((value) * 1125899906842624) + + if to_unit == BitRateUnits.ExbibitPerSecond: + return ((value) * 1152921504606846976) + if to_unit == BitRateUnits.KilobytePerSecond: return ((value * 8) * 1000.0) @@ -318,6 +456,24 @@ def __convert_to_base(self, value: float, to_unit: BitRateUnits) -> float: if to_unit == BitRateUnits.ExabytePerSecond: return ((value * 8) * 1e+18) + if to_unit == BitRateUnits.KibibytePerSecond: + return ((value * 8) * 1024) + + if to_unit == BitRateUnits.MebibytePerSecond: + return ((value * 8) * 1048576) + + if to_unit == BitRateUnits.GibibytePerSecond: + return ((value * 8) * 1073741824) + + if to_unit == BitRateUnits.TebibytePerSecond: + return ((value * 8) * 1099511627776) + + if to_unit == BitRateUnits.PebibytePerSecond: + return ((value * 8) * 1125899906842624) + + if to_unit == BitRateUnits.ExbibytePerSecond: + return ((value * 8) * 1152921504606846976) + return None @@ -446,6 +602,96 @@ def from_exabits_per_second(exabits_per_second: float): return BitRate(exabits_per_second, BitRateUnits.ExabitPerSecond) + @staticmethod + def from_kibibits_per_second(kibibits_per_second: float): + """ + Create a new instance of BitRate from a value in kibibits_per_second. + + + + :param meters: The BitRate value in kibibits_per_second. + :type kibibits_per_second: float + :return: A new instance of BitRate. + :rtype: BitRate + """ + return BitRate(kibibits_per_second, BitRateUnits.KibibitPerSecond) + + + @staticmethod + def from_mebibits_per_second(mebibits_per_second: float): + """ + Create a new instance of BitRate from a value in mebibits_per_second. + + + + :param meters: The BitRate value in mebibits_per_second. + :type mebibits_per_second: float + :return: A new instance of BitRate. + :rtype: BitRate + """ + return BitRate(mebibits_per_second, BitRateUnits.MebibitPerSecond) + + + @staticmethod + def from_gibibits_per_second(gibibits_per_second: float): + """ + Create a new instance of BitRate from a value in gibibits_per_second. + + + + :param meters: The BitRate value in gibibits_per_second. + :type gibibits_per_second: float + :return: A new instance of BitRate. + :rtype: BitRate + """ + return BitRate(gibibits_per_second, BitRateUnits.GibibitPerSecond) + + + @staticmethod + def from_tebibits_per_second(tebibits_per_second: float): + """ + Create a new instance of BitRate from a value in tebibits_per_second. + + + + :param meters: The BitRate value in tebibits_per_second. + :type tebibits_per_second: float + :return: A new instance of BitRate. + :rtype: BitRate + """ + return BitRate(tebibits_per_second, BitRateUnits.TebibitPerSecond) + + + @staticmethod + def from_pebibits_per_second(pebibits_per_second: float): + """ + Create a new instance of BitRate from a value in pebibits_per_second. + + + + :param meters: The BitRate value in pebibits_per_second. + :type pebibits_per_second: float + :return: A new instance of BitRate. + :rtype: BitRate + """ + return BitRate(pebibits_per_second, BitRateUnits.PebibitPerSecond) + + + @staticmethod + def from_exbibits_per_second(exbibits_per_second: float): + """ + Create a new instance of BitRate from a value in exbibits_per_second. + + + + :param meters: The BitRate value in exbibits_per_second. + :type exbibits_per_second: float + :return: A new instance of BitRate. + :rtype: BitRate + """ + return BitRate(exbibits_per_second, BitRateUnits.ExbibitPerSecond) + + @staticmethod def from_kilobytes_per_second(kilobytes_per_second: float): """ @@ -536,6 +782,96 @@ def from_exabytes_per_second(exabytes_per_second: float): return BitRate(exabytes_per_second, BitRateUnits.ExabytePerSecond) + @staticmethod + def from_kibibytes_per_second(kibibytes_per_second: float): + """ + Create a new instance of BitRate from a value in kibibytes_per_second. + + + + :param meters: The BitRate value in kibibytes_per_second. + :type kibibytes_per_second: float + :return: A new instance of BitRate. + :rtype: BitRate + """ + return BitRate(kibibytes_per_second, BitRateUnits.KibibytePerSecond) + + + @staticmethod + def from_mebibytes_per_second(mebibytes_per_second: float): + """ + Create a new instance of BitRate from a value in mebibytes_per_second. + + + + :param meters: The BitRate value in mebibytes_per_second. + :type mebibytes_per_second: float + :return: A new instance of BitRate. + :rtype: BitRate + """ + return BitRate(mebibytes_per_second, BitRateUnits.MebibytePerSecond) + + + @staticmethod + def from_gibibytes_per_second(gibibytes_per_second: float): + """ + Create a new instance of BitRate from a value in gibibytes_per_second. + + + + :param meters: The BitRate value in gibibytes_per_second. + :type gibibytes_per_second: float + :return: A new instance of BitRate. + :rtype: BitRate + """ + return BitRate(gibibytes_per_second, BitRateUnits.GibibytePerSecond) + + + @staticmethod + def from_tebibytes_per_second(tebibytes_per_second: float): + """ + Create a new instance of BitRate from a value in tebibytes_per_second. + + + + :param meters: The BitRate value in tebibytes_per_second. + :type tebibytes_per_second: float + :return: A new instance of BitRate. + :rtype: BitRate + """ + return BitRate(tebibytes_per_second, BitRateUnits.TebibytePerSecond) + + + @staticmethod + def from_pebibytes_per_second(pebibytes_per_second: float): + """ + Create a new instance of BitRate from a value in pebibytes_per_second. + + + + :param meters: The BitRate value in pebibytes_per_second. + :type pebibytes_per_second: float + :return: A new instance of BitRate. + :rtype: BitRate + """ + return BitRate(pebibytes_per_second, BitRateUnits.PebibytePerSecond) + + + @staticmethod + def from_exbibytes_per_second(exbibytes_per_second: float): + """ + Create a new instance of BitRate from a value in exbibytes_per_second. + + + + :param meters: The BitRate value in exbibytes_per_second. + :type exbibytes_per_second: float + :return: A new instance of BitRate. + :rtype: BitRate + """ + return BitRate(exbibytes_per_second, BitRateUnits.ExbibytePerSecond) + + @property def bits_per_second(self) -> float: """ @@ -624,6 +960,72 @@ def exabits_per_second(self) -> float: return self.__exabits_per_second + @property + def kibibits_per_second(self) -> float: + """ + + """ + if self.__kibibits_per_second != None: + return self.__kibibits_per_second + self.__kibibits_per_second = self.__convert_from_base(BitRateUnits.KibibitPerSecond) + return self.__kibibits_per_second + + + @property + def mebibits_per_second(self) -> float: + """ + + """ + if self.__mebibits_per_second != None: + return self.__mebibits_per_second + self.__mebibits_per_second = self.__convert_from_base(BitRateUnits.MebibitPerSecond) + return self.__mebibits_per_second + + + @property + def gibibits_per_second(self) -> float: + """ + + """ + if self.__gibibits_per_second != None: + return self.__gibibits_per_second + self.__gibibits_per_second = self.__convert_from_base(BitRateUnits.GibibitPerSecond) + return self.__gibibits_per_second + + + @property + def tebibits_per_second(self) -> float: + """ + + """ + if self.__tebibits_per_second != None: + return self.__tebibits_per_second + self.__tebibits_per_second = self.__convert_from_base(BitRateUnits.TebibitPerSecond) + return self.__tebibits_per_second + + + @property + def pebibits_per_second(self) -> float: + """ + + """ + if self.__pebibits_per_second != None: + return self.__pebibits_per_second + self.__pebibits_per_second = self.__convert_from_base(BitRateUnits.PebibitPerSecond) + return self.__pebibits_per_second + + + @property + def exbibits_per_second(self) -> float: + """ + + """ + if self.__exbibits_per_second != None: + return self.__exbibits_per_second + self.__exbibits_per_second = self.__convert_from_base(BitRateUnits.ExbibitPerSecond) + return self.__exbibits_per_second + + @property def kilobytes_per_second(self) -> float: """ @@ -690,6 +1092,72 @@ def exabytes_per_second(self) -> float: return self.__exabytes_per_second + @property + def kibibytes_per_second(self) -> float: + """ + + """ + if self.__kibibytes_per_second != None: + return self.__kibibytes_per_second + self.__kibibytes_per_second = self.__convert_from_base(BitRateUnits.KibibytePerSecond) + return self.__kibibytes_per_second + + + @property + def mebibytes_per_second(self) -> float: + """ + + """ + if self.__mebibytes_per_second != None: + return self.__mebibytes_per_second + self.__mebibytes_per_second = self.__convert_from_base(BitRateUnits.MebibytePerSecond) + return self.__mebibytes_per_second + + + @property + def gibibytes_per_second(self) -> float: + """ + + """ + if self.__gibibytes_per_second != None: + return self.__gibibytes_per_second + self.__gibibytes_per_second = self.__convert_from_base(BitRateUnits.GibibytePerSecond) + return self.__gibibytes_per_second + + + @property + def tebibytes_per_second(self) -> float: + """ + + """ + if self.__tebibytes_per_second != None: + return self.__tebibytes_per_second + self.__tebibytes_per_second = self.__convert_from_base(BitRateUnits.TebibytePerSecond) + return self.__tebibytes_per_second + + + @property + def pebibytes_per_second(self) -> float: + """ + + """ + if self.__pebibytes_per_second != None: + return self.__pebibytes_per_second + self.__pebibytes_per_second = self.__convert_from_base(BitRateUnits.PebibytePerSecond) + return self.__pebibytes_per_second + + + @property + def exbibytes_per_second(self) -> float: + """ + + """ + if self.__exbibytes_per_second != None: + return self.__exbibytes_per_second + self.__exbibytes_per_second = self.__convert_from_base(BitRateUnits.ExbibytePerSecond) + return self.__exbibytes_per_second + + def to_string(self, unit: BitRateUnits = BitRateUnits.BitPerSecond, fractional_digits: int = None) -> str: """ Format the BitRate to a string. @@ -729,6 +1197,24 @@ def to_string(self, unit: BitRateUnits = BitRateUnits.BitPerSecond, fractional_d if unit == BitRateUnits.ExabitPerSecond: return f"""{super()._truncate_fraction_digits(self.exabits_per_second, fractional_digits)} Ebit/s""" + if unit == BitRateUnits.KibibitPerSecond: + return f"""{super()._truncate_fraction_digits(self.kibibits_per_second, fractional_digits)} KiBbit/s""" + + if unit == BitRateUnits.MebibitPerSecond: + return f"""{super()._truncate_fraction_digits(self.mebibits_per_second, fractional_digits)} MiBbit/s""" + + if unit == BitRateUnits.GibibitPerSecond: + return f"""{super()._truncate_fraction_digits(self.gibibits_per_second, fractional_digits)} GiBbit/s""" + + if unit == BitRateUnits.TebibitPerSecond: + return f"""{super()._truncate_fraction_digits(self.tebibits_per_second, fractional_digits)} TiBbit/s""" + + if unit == BitRateUnits.PebibitPerSecond: + return f"""{super()._truncate_fraction_digits(self.pebibits_per_second, fractional_digits)} PiBbit/s""" + + if unit == BitRateUnits.ExbibitPerSecond: + return f"""{super()._truncate_fraction_digits(self.exbibits_per_second, fractional_digits)} EiBbit/s""" + if unit == BitRateUnits.KilobytePerSecond: return f"""{super()._truncate_fraction_digits(self.kilobytes_per_second, fractional_digits)} kB/s""" @@ -747,6 +1233,24 @@ def to_string(self, unit: BitRateUnits = BitRateUnits.BitPerSecond, fractional_d if unit == BitRateUnits.ExabytePerSecond: return f"""{super()._truncate_fraction_digits(self.exabytes_per_second, fractional_digits)} EB/s""" + if unit == BitRateUnits.KibibytePerSecond: + return f"""{super()._truncate_fraction_digits(self.kibibytes_per_second, fractional_digits)} KiBB/s""" + + if unit == BitRateUnits.MebibytePerSecond: + return f"""{super()._truncate_fraction_digits(self.mebibytes_per_second, fractional_digits)} MiBB/s""" + + if unit == BitRateUnits.GibibytePerSecond: + return f"""{super()._truncate_fraction_digits(self.gibibytes_per_second, fractional_digits)} GiBB/s""" + + if unit == BitRateUnits.TebibytePerSecond: + return f"""{super()._truncate_fraction_digits(self.tebibytes_per_second, fractional_digits)} TiBB/s""" + + if unit == BitRateUnits.PebibytePerSecond: + return f"""{super()._truncate_fraction_digits(self.pebibytes_per_second, fractional_digits)} PiBB/s""" + + if unit == BitRateUnits.ExbibytePerSecond: + return f"""{super()._truncate_fraction_digits(self.exbibytes_per_second, fractional_digits)} EiBB/s""" + return f'{self._value}' @@ -781,6 +1285,24 @@ def get_unit_abbreviation(self, unit_abbreviation: BitRateUnits = BitRateUnits.B if unit_abbreviation == BitRateUnits.ExabitPerSecond: return """Ebit/s""" + if unit_abbreviation == BitRateUnits.KibibitPerSecond: + return """KiBbit/s""" + + if unit_abbreviation == BitRateUnits.MebibitPerSecond: + return """MiBbit/s""" + + if unit_abbreviation == BitRateUnits.GibibitPerSecond: + return """GiBbit/s""" + + if unit_abbreviation == BitRateUnits.TebibitPerSecond: + return """TiBbit/s""" + + if unit_abbreviation == BitRateUnits.PebibitPerSecond: + return """PiBbit/s""" + + if unit_abbreviation == BitRateUnits.ExbibitPerSecond: + return """EiBbit/s""" + if unit_abbreviation == BitRateUnits.KilobytePerSecond: return """kB/s""" @@ -798,4 +1320,22 @@ def get_unit_abbreviation(self, unit_abbreviation: BitRateUnits = BitRateUnits.B if unit_abbreviation == BitRateUnits.ExabytePerSecond: return """EB/s""" + + if unit_abbreviation == BitRateUnits.KibibytePerSecond: + return """KiBB/s""" + + if unit_abbreviation == BitRateUnits.MebibytePerSecond: + return """MiBB/s""" + + if unit_abbreviation == BitRateUnits.GibibytePerSecond: + return """GiBB/s""" + + if unit_abbreviation == BitRateUnits.TebibytePerSecond: + return """TiBB/s""" + + if unit_abbreviation == BitRateUnits.PebibytePerSecond: + return """PiBB/s""" + + if unit_abbreviation == BitRateUnits.ExbibytePerSecond: + return """EiBB/s""" \ No newline at end of file diff --git a/unitsnet_py/units/information.py b/unitsnet_py/units/information.py index 2e81ea6..f7ac058 100644 --- a/unitsnet_py/units/information.py +++ b/unitsnet_py/units/information.py @@ -50,6 +50,36 @@ class InformationUnits(Enum): """ + Kibibyte = 'Kibibyte' + """ + + """ + + Mebibyte = 'Mebibyte' + """ + + """ + + Gibibyte = 'Gibibyte' + """ + + """ + + Tebibyte = 'Tebibyte' + """ + + """ + + Pebibyte = 'Pebibyte' + """ + + """ + + Exbibyte = 'Exbibyte' + """ + + """ + Kilobit = 'Kilobit' """ @@ -80,6 +110,36 @@ class InformationUnits(Enum): """ + Kibibit = 'Kibibit' + """ + + """ + + Mebibit = 'Mebibit' + """ + + """ + + Gibibit = 'Gibibit' + """ + + """ + + Tebibit = 'Tebibit' + """ + + """ + + Pebibit = 'Pebibit' + """ + + """ + + Exbibit = 'Exbibit' + """ + + """ + class InformationDto: """ @@ -162,6 +222,18 @@ def __init__(self, value: float, from_unit: InformationUnits = InformationUnits. self.__exabytes = None + self.__kibibytes = None + + self.__mebibytes = None + + self.__gibibytes = None + + self.__tebibytes = None + + self.__pebibytes = None + + self.__exbibytes = None + self.__kilobits = None self.__megabits = None @@ -174,6 +246,18 @@ def __init__(self, value: float, from_unit: InformationUnits = InformationUnits. self.__exabits = None + self.__kibibits = None + + self.__mebibits = None + + self.__gibibits = None + + self.__tebibits = None + + self.__pebibits = None + + self.__exbibits = None + def convert(self, unit: InformationUnits) -> float: return self.__convert_from_base(unit) @@ -253,6 +337,24 @@ def __convert_from_base(self, from_unit: InformationUnits) -> float: if from_unit == InformationUnits.Exabyte: return ((value / 8) / 1e+18) + if from_unit == InformationUnits.Kibibyte: + return ((value / 8) / 1024) + + if from_unit == InformationUnits.Mebibyte: + return ((value / 8) / 1048576) + + if from_unit == InformationUnits.Gibibyte: + return ((value / 8) / 1073741824) + + if from_unit == InformationUnits.Tebibyte: + return ((value / 8) / 1099511627776) + + if from_unit == InformationUnits.Pebibyte: + return ((value / 8) / 1125899906842624) + + if from_unit == InformationUnits.Exbibyte: + return ((value / 8) / 1152921504606846976) + if from_unit == InformationUnits.Kilobit: return ((value) / 1000.0) @@ -271,6 +373,24 @@ def __convert_from_base(self, from_unit: InformationUnits) -> float: if from_unit == InformationUnits.Exabit: return ((value) / 1e+18) + if from_unit == InformationUnits.Kibibit: + return ((value) / 1024) + + if from_unit == InformationUnits.Mebibit: + return ((value) / 1048576) + + if from_unit == InformationUnits.Gibibit: + return ((value) / 1073741824) + + if from_unit == InformationUnits.Tebibit: + return ((value) / 1099511627776) + + if from_unit == InformationUnits.Pebibit: + return ((value) / 1125899906842624) + + if from_unit == InformationUnits.Exbibit: + return ((value) / 1152921504606846976) + return None @@ -300,6 +420,24 @@ def __convert_to_base(self, value: float, to_unit: InformationUnits) -> float: if to_unit == InformationUnits.Exabyte: return ((value * 8) * 1e+18) + if to_unit == InformationUnits.Kibibyte: + return ((value * 8) * 1024) + + if to_unit == InformationUnits.Mebibyte: + return ((value * 8) * 1048576) + + if to_unit == InformationUnits.Gibibyte: + return ((value * 8) * 1073741824) + + if to_unit == InformationUnits.Tebibyte: + return ((value * 8) * 1099511627776) + + if to_unit == InformationUnits.Pebibyte: + return ((value * 8) * 1125899906842624) + + if to_unit == InformationUnits.Exbibyte: + return ((value * 8) * 1152921504606846976) + if to_unit == InformationUnits.Kilobit: return ((value) * 1000.0) @@ -318,6 +456,24 @@ def __convert_to_base(self, value: float, to_unit: InformationUnits) -> float: if to_unit == InformationUnits.Exabit: return ((value) * 1e+18) + if to_unit == InformationUnits.Kibibit: + return ((value) * 1024) + + if to_unit == InformationUnits.Mebibit: + return ((value) * 1048576) + + if to_unit == InformationUnits.Gibibit: + return ((value) * 1073741824) + + if to_unit == InformationUnits.Tebibit: + return ((value) * 1099511627776) + + if to_unit == InformationUnits.Pebibit: + return ((value) * 1125899906842624) + + if to_unit == InformationUnits.Exbibit: + return ((value) * 1152921504606846976) + return None @@ -446,6 +602,96 @@ def from_exabytes(exabytes: float): return Information(exabytes, InformationUnits.Exabyte) + @staticmethod + def from_kibibytes(kibibytes: float): + """ + Create a new instance of Information from a value in kibibytes. + + + + :param meters: The Information value in kibibytes. + :type kibibytes: float + :return: A new instance of Information. + :rtype: Information + """ + return Information(kibibytes, InformationUnits.Kibibyte) + + + @staticmethod + def from_mebibytes(mebibytes: float): + """ + Create a new instance of Information from a value in mebibytes. + + + + :param meters: The Information value in mebibytes. + :type mebibytes: float + :return: A new instance of Information. + :rtype: Information + """ + return Information(mebibytes, InformationUnits.Mebibyte) + + + @staticmethod + def from_gibibytes(gibibytes: float): + """ + Create a new instance of Information from a value in gibibytes. + + + + :param meters: The Information value in gibibytes. + :type gibibytes: float + :return: A new instance of Information. + :rtype: Information + """ + return Information(gibibytes, InformationUnits.Gibibyte) + + + @staticmethod + def from_tebibytes(tebibytes: float): + """ + Create a new instance of Information from a value in tebibytes. + + + + :param meters: The Information value in tebibytes. + :type tebibytes: float + :return: A new instance of Information. + :rtype: Information + """ + return Information(tebibytes, InformationUnits.Tebibyte) + + + @staticmethod + def from_pebibytes(pebibytes: float): + """ + Create a new instance of Information from a value in pebibytes. + + + + :param meters: The Information value in pebibytes. + :type pebibytes: float + :return: A new instance of Information. + :rtype: Information + """ + return Information(pebibytes, InformationUnits.Pebibyte) + + + @staticmethod + def from_exbibytes(exbibytes: float): + """ + Create a new instance of Information from a value in exbibytes. + + + + :param meters: The Information value in exbibytes. + :type exbibytes: float + :return: A new instance of Information. + :rtype: Information + """ + return Information(exbibytes, InformationUnits.Exbibyte) + + @staticmethod def from_kilobits(kilobits: float): """ @@ -536,6 +782,96 @@ def from_exabits(exabits: float): return Information(exabits, InformationUnits.Exabit) + @staticmethod + def from_kibibits(kibibits: float): + """ + Create a new instance of Information from a value in kibibits. + + + + :param meters: The Information value in kibibits. + :type kibibits: float + :return: A new instance of Information. + :rtype: Information + """ + return Information(kibibits, InformationUnits.Kibibit) + + + @staticmethod + def from_mebibits(mebibits: float): + """ + Create a new instance of Information from a value in mebibits. + + + + :param meters: The Information value in mebibits. + :type mebibits: float + :return: A new instance of Information. + :rtype: Information + """ + return Information(mebibits, InformationUnits.Mebibit) + + + @staticmethod + def from_gibibits(gibibits: float): + """ + Create a new instance of Information from a value in gibibits. + + + + :param meters: The Information value in gibibits. + :type gibibits: float + :return: A new instance of Information. + :rtype: Information + """ + return Information(gibibits, InformationUnits.Gibibit) + + + @staticmethod + def from_tebibits(tebibits: float): + """ + Create a new instance of Information from a value in tebibits. + + + + :param meters: The Information value in tebibits. + :type tebibits: float + :return: A new instance of Information. + :rtype: Information + """ + return Information(tebibits, InformationUnits.Tebibit) + + + @staticmethod + def from_pebibits(pebibits: float): + """ + Create a new instance of Information from a value in pebibits. + + + + :param meters: The Information value in pebibits. + :type pebibits: float + :return: A new instance of Information. + :rtype: Information + """ + return Information(pebibits, InformationUnits.Pebibit) + + + @staticmethod + def from_exbibits(exbibits: float): + """ + Create a new instance of Information from a value in exbibits. + + + + :param meters: The Information value in exbibits. + :type exbibits: float + :return: A new instance of Information. + :rtype: Information + """ + return Information(exbibits, InformationUnits.Exbibit) + + @property def bytes(self) -> float: """ @@ -624,6 +960,72 @@ def exabytes(self) -> float: return self.__exabytes + @property + def kibibytes(self) -> float: + """ + + """ + if self.__kibibytes != None: + return self.__kibibytes + self.__kibibytes = self.__convert_from_base(InformationUnits.Kibibyte) + return self.__kibibytes + + + @property + def mebibytes(self) -> float: + """ + + """ + if self.__mebibytes != None: + return self.__mebibytes + self.__mebibytes = self.__convert_from_base(InformationUnits.Mebibyte) + return self.__mebibytes + + + @property + def gibibytes(self) -> float: + """ + + """ + if self.__gibibytes != None: + return self.__gibibytes + self.__gibibytes = self.__convert_from_base(InformationUnits.Gibibyte) + return self.__gibibytes + + + @property + def tebibytes(self) -> float: + """ + + """ + if self.__tebibytes != None: + return self.__tebibytes + self.__tebibytes = self.__convert_from_base(InformationUnits.Tebibyte) + return self.__tebibytes + + + @property + def pebibytes(self) -> float: + """ + + """ + if self.__pebibytes != None: + return self.__pebibytes + self.__pebibytes = self.__convert_from_base(InformationUnits.Pebibyte) + return self.__pebibytes + + + @property + def exbibytes(self) -> float: + """ + + """ + if self.__exbibytes != None: + return self.__exbibytes + self.__exbibytes = self.__convert_from_base(InformationUnits.Exbibyte) + return self.__exbibytes + + @property def kilobits(self) -> float: """ @@ -690,6 +1092,72 @@ def exabits(self) -> float: return self.__exabits + @property + def kibibits(self) -> float: + """ + + """ + if self.__kibibits != None: + return self.__kibibits + self.__kibibits = self.__convert_from_base(InformationUnits.Kibibit) + return self.__kibibits + + + @property + def mebibits(self) -> float: + """ + + """ + if self.__mebibits != None: + return self.__mebibits + self.__mebibits = self.__convert_from_base(InformationUnits.Mebibit) + return self.__mebibits + + + @property + def gibibits(self) -> float: + """ + + """ + if self.__gibibits != None: + return self.__gibibits + self.__gibibits = self.__convert_from_base(InformationUnits.Gibibit) + return self.__gibibits + + + @property + def tebibits(self) -> float: + """ + + """ + if self.__tebibits != None: + return self.__tebibits + self.__tebibits = self.__convert_from_base(InformationUnits.Tebibit) + return self.__tebibits + + + @property + def pebibits(self) -> float: + """ + + """ + if self.__pebibits != None: + return self.__pebibits + self.__pebibits = self.__convert_from_base(InformationUnits.Pebibit) + return self.__pebibits + + + @property + def exbibits(self) -> float: + """ + + """ + if self.__exbibits != None: + return self.__exbibits + self.__exbibits = self.__convert_from_base(InformationUnits.Exbibit) + return self.__exbibits + + def to_string(self, unit: InformationUnits = InformationUnits.Bit, fractional_digits: int = None) -> str: """ Format the Information to a string. @@ -729,6 +1197,24 @@ def to_string(self, unit: InformationUnits = InformationUnits.Bit, fractional_di if unit == InformationUnits.Exabyte: return f"""{super()._truncate_fraction_digits(self.exabytes, fractional_digits)} EB""" + if unit == InformationUnits.Kibibyte: + return f"""{super()._truncate_fraction_digits(self.kibibytes, fractional_digits)} KiBB""" + + if unit == InformationUnits.Mebibyte: + return f"""{super()._truncate_fraction_digits(self.mebibytes, fractional_digits)} MiBB""" + + if unit == InformationUnits.Gibibyte: + return f"""{super()._truncate_fraction_digits(self.gibibytes, fractional_digits)} GiBB""" + + if unit == InformationUnits.Tebibyte: + return f"""{super()._truncate_fraction_digits(self.tebibytes, fractional_digits)} TiBB""" + + if unit == InformationUnits.Pebibyte: + return f"""{super()._truncate_fraction_digits(self.pebibytes, fractional_digits)} PiBB""" + + if unit == InformationUnits.Exbibyte: + return f"""{super()._truncate_fraction_digits(self.exbibytes, fractional_digits)} EiBB""" + if unit == InformationUnits.Kilobit: return f"""{super()._truncate_fraction_digits(self.kilobits, fractional_digits)} kb""" @@ -747,6 +1233,24 @@ def to_string(self, unit: InformationUnits = InformationUnits.Bit, fractional_di if unit == InformationUnits.Exabit: return f"""{super()._truncate_fraction_digits(self.exabits, fractional_digits)} Eb""" + if unit == InformationUnits.Kibibit: + return f"""{super()._truncate_fraction_digits(self.kibibits, fractional_digits)} KiBb""" + + if unit == InformationUnits.Mebibit: + return f"""{super()._truncate_fraction_digits(self.mebibits, fractional_digits)} MiBb""" + + if unit == InformationUnits.Gibibit: + return f"""{super()._truncate_fraction_digits(self.gibibits, fractional_digits)} GiBb""" + + if unit == InformationUnits.Tebibit: + return f"""{super()._truncate_fraction_digits(self.tebibits, fractional_digits)} TiBb""" + + if unit == InformationUnits.Pebibit: + return f"""{super()._truncate_fraction_digits(self.pebibits, fractional_digits)} PiBb""" + + if unit == InformationUnits.Exbibit: + return f"""{super()._truncate_fraction_digits(self.exbibits, fractional_digits)} EiBb""" + return f'{self._value}' @@ -781,6 +1285,24 @@ def get_unit_abbreviation(self, unit_abbreviation: InformationUnits = Informatio if unit_abbreviation == InformationUnits.Exabyte: return """EB""" + if unit_abbreviation == InformationUnits.Kibibyte: + return """KiBB""" + + if unit_abbreviation == InformationUnits.Mebibyte: + return """MiBB""" + + if unit_abbreviation == InformationUnits.Gibibyte: + return """GiBB""" + + if unit_abbreviation == InformationUnits.Tebibyte: + return """TiBB""" + + if unit_abbreviation == InformationUnits.Pebibyte: + return """PiBB""" + + if unit_abbreviation == InformationUnits.Exbibyte: + return """EiBB""" + if unit_abbreviation == InformationUnits.Kilobit: return """kb""" @@ -798,4 +1320,22 @@ def get_unit_abbreviation(self, unit_abbreviation: InformationUnits = Informatio if unit_abbreviation == InformationUnits.Exabit: return """Eb""" + + if unit_abbreviation == InformationUnits.Kibibit: + return """KiBb""" + + if unit_abbreviation == InformationUnits.Mebibit: + return """MiBb""" + + if unit_abbreviation == InformationUnits.Gibibit: + return """GiBb""" + + if unit_abbreviation == InformationUnits.Tebibit: + return """TiBb""" + + if unit_abbreviation == InformationUnits.Pebibit: + return """PiBb""" + + if unit_abbreviation == InformationUnits.Exbibit: + return """EiBb""" \ No newline at end of file