def __init__(self, value, unit): super(Acceleration, self).__init__(value, unit) # meters per second squared new_unit = UnitOfMeasure( 'm/s^2', lambda x: x, lambda y: y) new_unit.addAlias('meters per second squared') self.registerUnitOfMeasure(new_unit)
def __init__(self, value, unit): super(LuminousIntensity, self).__init__(value, unit) # Candela new_unit = UnitOfMeasure( 'cd', lambda x: x, lambda y: y ) new_unit.addAlias('candela') self.registerUnitOfMeasure(new_unit)
def __init__(self, value, unit): super(Velocity, self).__init__(value, unit) # meter per second new_unit = UnitOfMeasure( 'm/s', lambda x: x, lambda y: y ) new_unit.addAlias('meters per second') new_unit.addAlias('meter per second') self.registerUnitOfMeasure(new_unit)
def __init__(self, value, unit): super(ElectricCurrent, self).__init__(value, unit) # Ampere new_unit = UnitOfMeasure( 'A', lambda x: x, lambda y: y ) new_unit.addAlias('amp') new_unit.addAlias('amps') new_unit.addAlias('ampere') new_unit.addAlias('amperes') self.registerUnitOfMeasure(new_unit)
def __init__(self, value, unit): super(Velocity, self).__init__(value, unit) # meter per second new_unit = UnitOfMeasure('m/s', lambda x: x, lambda y: y) new_unit.addAlias('meters per second') new_unit.addAlias('meter per second') self.registerUnitOfMeasure(new_unit)
def __init__(self, value, unit): super(Time, self).__init__(value, unit) # Second new_unit = UnitOfMeasure( 's', lambda x: x, lambda y: y ) new_unit.addAlias('second') new_unit.addAlias('seconds') self.registerUnitOfMeasure(new_unit)
def __init__(self, value, unit): super(Pressure, self).__init__(value, unit) # Pascal new_unit = UnitOfMeasure("Pa", lambda x: x, lambda y: y) new_unit.addAlias("pascal") self.registerUnitOfMeasure(new_unit) # Atmosphere new_unit = UnitOfMeasure("atm", lambda x: x / 101325, lambda y: y * 101325) new_unit.addAlias("atmosphere") new_unit.addAlias("atmospheres") self.registerUnitOfMeasure(new_unit) # Bar new_unit = UnitOfMeasure("bar", lambda x: x / 1e5, lambda y: y * 1e5) new_unit.addAlias("bar") self.registerUnitOfMeasure(new_unit) # Inch of Mercury new_unit = UnitOfMeasure("inHg", lambda x: x / 3.386389e3, lambda y: y * 3.386389e3) new_unit.addAlias("inches of mercury") self.registerUnitOfMeasure(new_unit) # Milimeter of Mercury new_unit = UnitOfMeasure("mmHg", lambda x: x / 133.3224, lambda y: y * 133.3224) new_unit.addAlias("milimeters of mercury") new_unit.addAlias("torr") self.registerUnitOfMeasure(new_unit) # Pound per Square Inch new_unit = UnitOfMeasure("psi", lambda x: x / 6.894757e3, lambda y: y * 6.894757e3) new_unit.addAlias("pounds per square inch") self.registerUnitOfMeasure(new_unit)
def __init__(self, value, unit): super(Area, self).__init__(value, unit) # Meters squared new_unit = UnitOfMeasure( 'm^2', lambda x: x, lambda y: y ) new_unit.addAlias('m²') new_unit.addAlias('meter squared') new_unit.addAlias('meters squared') self.registerUnitOfMeasure(new_unit) # Millimeter squared new_unit = UnitOfMeasure( 'mm^2', lambda x: x / 1e-6, lambda y: y * 1e-6, ) new_unit.addAlias('mm²') new_unit.addAlias('millimeter squared') new_unit.addAlias('millimeters squared') self.registerUnitOfMeasure(new_unit) # Centimeter squared new_unit = UnitOfMeasure( 'cm^2', lambda x: x / 1e-4, lambda y: y * 1e-4 ) new_unit.addAlias('cm²') new_unit.addAlias('centimeter squared') new_unit.addAlias('centimeters squared') self.registerUnitOfMeasure(new_unit) # Decimeter squared new_unit = UnitOfMeasure( 'dm^2', lambda x: x / 1e-2, lambda y: y * 1e-2 ) new_unit.addAlias('dm²') new_unit.addAlias('decimeter squared') new_unit.addAlias('decimeters squared') self.registerUnitOfMeasure(new_unit) # Kilometer squared new_unit = UnitOfMeasure( 'km^2', lambda x: x / 1e6, lambda y: y * 1e6 ) new_unit.addAlias('km²') new_unit.addAlias('kilometer squared') new_unit.addAlias('kilometers squared') self.registerUnitOfMeasure(new_unit) # Foot squared new_unit = UnitOfMeasure( 'ft^2', lambda x: x / 9.290304e-2, lambda y: y * 9.290304e-2 ) new_unit.addAlias('ft²') new_unit.addAlias('foot squared') new_unit.addAlias('feet squared') self.registerUnitOfMeasure(new_unit) # Inch squared new_unit = UnitOfMeasure( 'in^2', lambda x: x / 6.4516e-4, lambda y: y * 6.4516e-4 ) new_unit.addAlias('in²') new_unit.addAlias('inch squared') new_unit.addAlias('inches squared') self.registerUnitOfMeasure(new_unit) # Mile squared new_unit = UnitOfMeasure( 'mi^2', lambda x: x / 2.589988e6, lambda y: y * 2.589988e6 ) new_unit.addAlias('mi²') new_unit.addAlias('mile squared') new_unit.addAlias('miles squared') self.registerUnitOfMeasure(new_unit) # Yard squared new_unit = UnitOfMeasure( 'yd^2', lambda x: x / 8.361274e-1, lambda y: y * 8.361274e-1 ) new_unit.addAlias('yd²') new_unit.addAlias('yard squared') new_unit.addAlias('yards squared') self.registerUnitOfMeasure(new_unit)
def __init__(self, value, unit): super(Pressure, self).__init__(value, unit) # Pascal new_unit = UnitOfMeasure('Pa', lambda x: x, lambda y: y) new_unit.addAlias('pascal') self.registerUnitOfMeasure(new_unit) # Atmosphere new_unit = UnitOfMeasure('atm', lambda x: x / 101325, lambda y: y * 101325) new_unit.addAlias('atmosphere') new_unit.addAlias('atmospheres') self.registerUnitOfMeasure(new_unit) # Bar new_unit = UnitOfMeasure('bar', lambda x: x / 1e5, lambda y: y * 1e5) new_unit.addAlias('bar') self.registerUnitOfMeasure(new_unit) # Inch of Mercury new_unit = UnitOfMeasure('inHg', lambda x: x / 3.386389e3, lambda y: y * 3.386389e3) new_unit.addAlias('inches of mercury') self.registerUnitOfMeasure(new_unit) # Milimeter of Mercury new_unit = UnitOfMeasure('mmHg', lambda x: x / 133.3224, lambda y: y * 133.3224) new_unit.addAlias('milimeters of mercury') new_unit.addAlias('torr') self.registerUnitOfMeasure(new_unit) # Pound per Square Inch new_unit = UnitOfMeasure('psi', lambda x: x / 6.894757e3, lambda y: y * 6.894757e3) new_unit.addAlias('pounds per square inch') self.registerUnitOfMeasure(new_unit)
def __init__(self, value, unit): super(Temperature, self).__init__(value, unit) # Degree Kelvin new_unit = UnitOfMeasure( u"\u212A", lambda x: x, lambda y: y ) new_unit.addAlias('K') new_unit.addAlias('kelvin') self.registerUnitOfMeasure(new_unit) # Degree Celsius new_unit = UnitOfMeasure( u"\u2103", lambda x: x - 273.15, lambda y: y + 273.15 ) new_unit.addAlias('C') new_unit.addAlias('celsius') self.registerUnitOfMeasure(new_unit) # Degree Fahrenheit new_unit = UnitOfMeasure( u"\u2109", lambda x: x * (9.0 / 5.0) - 459.67, lambda y: (y + 459.67) * (5.0 / 9.0) ) new_unit.addAlias('F') new_unit.addAlias('fahrenheit') self.registerUnitOfMeasure(new_unit)
def __init__(self, value, unit): super(Temperature, self).__init__(value, unit) # Degree Kelvin new_unit = UnitOfMeasure(u"\u212A", lambda x: x, lambda y: y) new_unit.addAlias('K') new_unit.addAlias('kelvin') self.registerUnitOfMeasure(new_unit) # Degree Celsius new_unit = UnitOfMeasure(u"\u2103", lambda x: x - 273.15, lambda y: y + 273.15) new_unit.addAlias('C') new_unit.addAlias('celsius') self.registerUnitOfMeasure(new_unit) # Degree Fahrenheit new_unit = UnitOfMeasure(u"\u2109", lambda x: x * (9.0 / 5.0) - 459.67, lambda y: (y + 459.67) * (5.0 / 9.0)) new_unit.addAlias('F') new_unit.addAlias('fahrenheit') self.registerUnitOfMeasure(new_unit)
def __init__(self, value, unit): super(Volume, self).__init__(value, unit) # Cubic meter new_unit = UnitOfMeasure('m^3', lambda x: x, lambda y: y) new_unit.addAlias('m³') new_unit.addAlias('cubic meter') new_unit.addAlias('cubic meters') self.registerUnitOfMeasure(new_unit) # Cubic millimeter new_unit = UnitOfMeasure('mm^3', lambda x: x / 1e-9, lambda y: y * 1e-9) new_unit.addAlias('mm³') new_unit.addAlias('cubic millimeter') new_unit.addAlias('cubic millimeters') self.registerUnitOfMeasure(new_unit) # Cubic centimeter new_unit = UnitOfMeasure('cm^3', lambda x: x / 1e-6, lambda y: y * 1e-6) new_unit.addAlias('cm³') new_unit.addAlias('cubic centimeter') new_unit.addAlias('cubic centimeters') self.registerUnitOfMeasure(new_unit) # Cubic decimeter new_unit = UnitOfMeasure('dm^3', lambda x: x / 1e-3, lambda y: y * 1e-3) new_unit.addAlias('dm³') new_unit.addAlias('cubic decimeter') new_unit.addAlias('cubic decimeters') self.registerUnitOfMeasure(new_unit) # Cubic kilometer new_unit = UnitOfMeasure('km^3', lambda x: x / 1e9, lambda y: y * 1e9) new_unit.addAlias('km³') new_unit.addAlias('cubic kilometer') new_unit.addAlias('cubic kilometers') self.registerUnitOfMeasure(new_unit) # Cubic foot new_unit = UnitOfMeasure('ft^3', lambda x: x / 2.831685e-2, lambda y: y * 2.831685e-2) new_unit.addAlias('ft³') new_unit.addAlias('cubic foot') new_unit.addAlias('cubic feet') self.registerUnitOfMeasure(new_unit) # Cubic inch new_unit = UnitOfMeasure('in^3', lambda x: x / 1.638706e-5, lambda y: y * 1.638706e-5) new_unit.addAlias('in³') new_unit.addAlias('cubic inch') new_unit.addAlias('cubic inches') self.registerUnitOfMeasure(new_unit) # Cubic yard new_unit = UnitOfMeasure('yd^3', lambda x: x / 7.645549e-1, lambda y: y * 7.645549e-1) new_unit.addAlias('yd³') new_unit.addAlias('cubic yard') new_unit.addAlias('cubic yards') self.registerUnitOfMeasure(new_unit) # Milliliters new_unit = UnitOfMeasure('ml', lambda x: x / 1e-6, lambda y: y * 1e-6) new_unit.addAlias('milliliter') new_unit.addAlias('milliliters') self.registerUnitOfMeasure(new_unit) # Centiliters new_unit = UnitOfMeasure('cl', lambda x: x / 1e-5, lambda y: y * 1e-5) new_unit.addAlias('centiliter') new_unit.addAlias('centiliters') self.registerUnitOfMeasure(new_unit) # Deciliter new_unit = UnitOfMeasure('dl', lambda x: x / 1e-4, lambda y: y * 1e-4) new_unit.addAlias('deciliter') new_unit.addAlias('deciliters') self.registerUnitOfMeasure(new_unit) # Liter new_unit = UnitOfMeasure('l', lambda x: x / 1e-3, lambda y: y * 1e-3) new_unit.addAlias('liter') new_unit.addAlias('liters') self.registerUnitOfMeasure(new_unit) # Decaliter new_unit = UnitOfMeasure('dal', lambda x: x / 1e-2, lambda y: y * 1e-2) new_unit.addAlias('decaliter') new_unit.addAlias('decaliters') self.registerUnitOfMeasure(new_unit) # Hectoliter new_unit = UnitOfMeasure('hl', lambda x: x / 1e-1, lambda y: y * 1e-1) new_unit.addAlias('hectoliter') new_unit.addAlias('hectoliters') self.registerUnitOfMeasure(new_unit) # Cup new_unit = UnitOfMeasure('cup', lambda x: x / 2.365882e-4, lambda y: y * 2.365882e-4) new_unit.addAlias('cup') new_unit.addAlias('cups') self.registerUnitOfMeasure(new_unit)
def __init__(self, value, unit): super(Length, self).__init__(value, unit) # Meter new_unit = UnitOfMeasure('m', lambda x: x, lambda y: y) new_unit.addAlias('meter') new_unit.addAlias('meters') self.registerUnitOfMeasure(new_unit) # Millimeter new_unit = UnitOfMeasure( 'mm', lambda x: x / 0.001, lambda y: y * 0.001, ) new_unit.addAlias('millimeter') new_unit.addAlias('millimeters') self.registerUnitOfMeasure(new_unit) # Centimeter new_unit = UnitOfMeasure( 'cm', lambda x: x / 0.01, lambda y: y * 0.01, ) new_unit.addAlias('centimeter') new_unit.addAlias('centimeters') self.registerUnitOfMeasure(new_unit) # Decimeter new_unit = UnitOfMeasure( 'dm', lambda x: x / 0.1, lambda y: y * 0.1, ) new_unit.addAlias('decimeter') new_unit.addAlias('decimeters') self.registerUnitOfMeasure(new_unit) # Kilometer new_unit = UnitOfMeasure( 'km', lambda x: x / 1000, lambda y: y * 1000, ) new_unit.addAlias('kilometer') new_unit.addAlias('kilometers') self.registerUnitOfMeasure(new_unit) # Foot new_unit = UnitOfMeasure( 'ft', lambda x: x / 0.3048, lambda y: y * 0.3048, ) new_unit.addAlias('foot') new_unit.addAlias('feet') self.registerUnitOfMeasure(new_unit) # Inch new_unit = UnitOfMeasure( 'in', lambda x: x / 0.0254, lambda y: y * 0.0254, ) new_unit.addAlias('inch') new_unit.addAlias('inches') self.registerUnitOfMeasure(new_unit) # Mile new_unit = UnitOfMeasure( 'mi', lambda x: x / 1609.344, lambda y: y * 1609.344, ) new_unit.addAlias('mile') new_unit.addAlias('miles') self.registerUnitOfMeasure(new_unit) # Yard new_unit = UnitOfMeasure( 'yd', lambda x: x / 0.9144, lambda y: y * 0.9144, ) new_unit.addAlias('yard') new_unit.addAlias('yards') self.registerUnitOfMeasure(new_unit)
def __init__(self, value, unit): super(Length, self).__init__(value, unit) # Meter new_unit = UnitOfMeasure( 'm', lambda x: x, lambda y: y) new_unit.addAlias('meter') new_unit.addAlias('meters') self.registerUnitOfMeasure(new_unit) # Millimeter new_unit = UnitOfMeasure( 'mm', lambda x: x / 0.001, lambda y: y * 0.001, ) new_unit.addAlias('millimeter') new_unit.addAlias('millimeters') self.registerUnitOfMeasure(new_unit) # Centimeter new_unit = UnitOfMeasure( 'cm', lambda x: x / 0.01, lambda y: y * 0.01, ) new_unit.addAlias('centimeter') new_unit.addAlias('centimeters') self.registerUnitOfMeasure(new_unit) # Decimeter new_unit = UnitOfMeasure( 'dm', lambda x: x / 0.1, lambda y: y * 0.1, ) new_unit.addAlias('decimeter') new_unit.addAlias('decimeters') self.registerUnitOfMeasure(new_unit) # Kilometer new_unit = UnitOfMeasure( 'km', lambda x: x / 1000, lambda y: y * 1000, ) new_unit.addAlias('kilometer') new_unit.addAlias('kilometers') self.registerUnitOfMeasure(new_unit) # Foot new_unit = UnitOfMeasure( 'ft', lambda x: x / 0.3048, lambda y: y * 0.3048, ) new_unit.addAlias('foot') new_unit.addAlias('feet') self.registerUnitOfMeasure(new_unit) # Inch new_unit = UnitOfMeasure( 'in', lambda x: x / 0.0254, lambda y: y * 0.0254, ) new_unit.addAlias('inch') new_unit.addAlias('inches') self.registerUnitOfMeasure(new_unit) # Mile new_unit = UnitOfMeasure( 'mi', lambda x: x / 1609.344, lambda y: y * 1609.344, ) new_unit.addAlias('mile') new_unit.addAlias('miles') self.registerUnitOfMeasure(new_unit) # Yard new_unit = UnitOfMeasure( 'yd', lambda x: x / 0.9144, lambda y: y * 0.9144, ) new_unit.addAlias('yard') new_unit.addAlias('yards') self.registerUnitOfMeasure(new_unit)
def __init__(self, value, unit): super(Angle, self).__init__(value, unit) # Degrees new_unit = UnitOfMeasure( u"\u00b0", lambda x: x, lambda y: y ) new_unit.addAlias('deg') new_unit.addAlias('degs') new_unit.addAlias('degree') new_unit.addAlias('degrees') self.registerUnitOfMeasure(new_unit) # Radians new_unit = UnitOfMeasure( 'rad', lambda x: x * pi / 180, lambda y: y / pi * 180 ) new_unit.addAlias('rads') new_unit.addAlias('radian') new_unit.addAlias('radians') self.registerUnitOfMeasure(new_unit)
def __init__(self, value, unit): super(Mass, self).__init__(value, unit) # Kilogram new_unit = UnitOfMeasure('kg', lambda x: x, lambda y: y) new_unit.addAlias('kilogram') new_unit.addAlias('kilograms') self.registerUnitOfMeasure(new_unit) # Milligram new_unit = UnitOfMeasure('mg', lambda x: x / 1e-6, lambda y: y * 1e-6) new_unit.addAlias('milligram') new_unit.addAlias('milligrams') self.registerUnitOfMeasure(new_unit) # Centigram new_unit = UnitOfMeasure('cg', lambda x: x / 1e-5, lambda y: y * 1e-5) new_unit.addAlias('centigram') new_unit.addAlias('centigrams') self.registerUnitOfMeasure(new_unit) # Gram new_unit = UnitOfMeasure('g', lambda x: x / 1e-3, lambda y: y * 1e-3) new_unit.addAlias('gram') new_unit.addAlias('grams') self.registerUnitOfMeasure(new_unit) # Tonne (metric) new_unit = UnitOfMeasure('t', lambda x: x / 1e3, lambda y: y * 1e3) new_unit.addAlias('ton') new_unit.addAlias('tons') new_unit.addAlias('tonne') new_unit.addAlias('tonnes') self.registerUnitOfMeasure(new_unit) # Pound new_unit = UnitOfMeasure('lb', lambda x: x / 4.535924e-1, lambda y: y * 4.535924e-1) new_unit.addAlias('lbs') new_unit.addAlias('pound') new_unit.addAlias('pounds') self.registerUnitOfMeasure(new_unit) # Ounce new_unit = UnitOfMeasure('oz', lambda x: x / 2.834952e-2, lambda y: y * 2.834952e-2) new_unit.addAlias('ounce') new_unit.addAlias('ounces') self.registerUnitOfMeasure(new_unit)
def __init__(self, value, unit): super(Volume, self).__init__(value, unit) # Cubic meter new_unit = UnitOfMeasure( 'm^3', lambda x: x, lambda y: y ) new_unit.addAlias('m³') new_unit.addAlias('cubic meter') new_unit.addAlias('cubic meters') self.registerUnitOfMeasure(new_unit) # Cubic millimeter new_unit = UnitOfMeasure( 'mm^3', lambda x: x / 1e-9, lambda y: y * 1e-9 ) new_unit.addAlias('mm³') new_unit.addAlias('cubic millimeter') new_unit.addAlias('cubic millimeters') self.registerUnitOfMeasure(new_unit) # Cubic centimeter new_unit = UnitOfMeasure( 'cm^3', lambda x: x / 1e-6, lambda y: y * 1e-6 ) new_unit.addAlias('cm³') new_unit.addAlias('cubic centimeter') new_unit.addAlias('cubic centimeters') self.registerUnitOfMeasure(new_unit) # Cubic decimeter new_unit = UnitOfMeasure( 'dm^3', lambda x: x / 1e-3, lambda y: y * 1e-3 ) new_unit.addAlias('dm³') new_unit.addAlias('cubic decimeter') new_unit.addAlias('cubic decimeters') self.registerUnitOfMeasure(new_unit) # Cubic kilometer new_unit = UnitOfMeasure( 'km^3', lambda x: x / 1e9, lambda y: y * 1e9 ) new_unit.addAlias('km³') new_unit.addAlias('cubic kilometer') new_unit.addAlias('cubic kilometers') self.registerUnitOfMeasure(new_unit) # Cubic foot new_unit = UnitOfMeasure( 'ft^3', lambda x: x / 2.831685e-2, lambda y: y * 2.831685e-2 ) new_unit.addAlias('ft³') new_unit.addAlias('cubic foot') new_unit.addAlias('cubic feet') self.registerUnitOfMeasure(new_unit) # Cubic inch new_unit = UnitOfMeasure( 'in^3', lambda x: x / 1.638706e-5, lambda y: y * 1.638706e-5 ) new_unit.addAlias('in³') new_unit.addAlias('cubic inch') new_unit.addAlias('cubic inches') self.registerUnitOfMeasure(new_unit) # Cubic yard new_unit = UnitOfMeasure( 'yd^3', lambda x: x / 7.645549e-1, lambda y: y * 7.645549e-1 ) new_unit.addAlias('yd³') new_unit.addAlias('cubic yard') new_unit.addAlias('cubic yards') self.registerUnitOfMeasure(new_unit) # Milliliters new_unit = UnitOfMeasure( 'ml', lambda x: x / 1e-6, lambda y: y * 1e-6 ) new_unit.addAlias('milliliter') new_unit.addAlias('milliliters') self.registerUnitOfMeasure(new_unit) # Centiliters new_unit = UnitOfMeasure( 'cl', lambda x: x / 1e-5, lambda y: y * 1e-5 ) new_unit.addAlias('centiliter') new_unit.addAlias('centiliters') self.registerUnitOfMeasure(new_unit) # Deciliter new_unit = UnitOfMeasure( 'dl', lambda x: x / 1e-4, lambda y: y * 1e-4 ) new_unit.addAlias('deciliter') new_unit.addAlias('deciliters') self.registerUnitOfMeasure(new_unit) # Liter new_unit = UnitOfMeasure( 'l', lambda x: x / 1e-3, lambda y: y * 1e-3 ) new_unit.addAlias('liter') new_unit.addAlias('liters') self.registerUnitOfMeasure(new_unit) # Decaliter new_unit = UnitOfMeasure( 'dal', lambda x: x / 1e-2, lambda y: y * 1e-2 ) new_unit.addAlias('decaliter') new_unit.addAlias('decaliters') self.registerUnitOfMeasure(new_unit) # Hectoliter new_unit = UnitOfMeasure( 'hl', lambda x: x / 1e-1, lambda y: y * 1e-1 ) new_unit.addAlias('hectoliter') new_unit.addAlias('hectoliters') self.registerUnitOfMeasure(new_unit) # Cup new_unit = UnitOfMeasure( 'cup', lambda x: x / 2.365882e-4, lambda y: y * 2.365882e-4 ) new_unit.addAlias('cup') new_unit.addAlias('cups') self.registerUnitOfMeasure(new_unit)
def __init__(self, value, unit): super(Area, self).__init__(value, unit) # Meters squared new_unit = UnitOfMeasure("m^2", lambda x: x, lambda y: y) new_unit.addAlias("m²") new_unit.addAlias("meter squared") new_unit.addAlias("meters squared") self.registerUnitOfMeasure(new_unit) # Millimeter squared new_unit = UnitOfMeasure("mm^2", lambda x: x / 1e-6, lambda y: y * 1e-6) new_unit.addAlias("mm²") new_unit.addAlias("millimeter squared") new_unit.addAlias("millimeters squared") self.registerUnitOfMeasure(new_unit) # Centimeter squared new_unit = UnitOfMeasure("cm^2", lambda x: x / 1e-4, lambda y: y * 1e-4) new_unit.addAlias("cm²") new_unit.addAlias("centimeter squared") new_unit.addAlias("centimeters squared") self.registerUnitOfMeasure(new_unit) # Decimeter squared new_unit = UnitOfMeasure("dm^2", lambda x: x / 1e-2, lambda y: y * 1e-2) new_unit.addAlias("dm²") new_unit.addAlias("decimeter squared") new_unit.addAlias("decimeters squared") self.registerUnitOfMeasure(new_unit) # Kilometer squared new_unit = UnitOfMeasure("km^2", lambda x: x / 1e6, lambda y: y * 1e6) new_unit.addAlias("km²") new_unit.addAlias("kilometer squared") new_unit.addAlias("kilometers squared") self.registerUnitOfMeasure(new_unit) # Foot squared new_unit = UnitOfMeasure("ft^2", lambda x: x / 9.290304e-2, lambda y: y * 9.290304e-2) new_unit.addAlias("ft²") new_unit.addAlias("foot squared") new_unit.addAlias("feet squared") self.registerUnitOfMeasure(new_unit) # Inch squared new_unit = UnitOfMeasure("in^2", lambda x: x / 6.4516e-4, lambda y: y * 6.4516e-4) new_unit.addAlias("in²") new_unit.addAlias("inch squared") new_unit.addAlias("inches squared") self.registerUnitOfMeasure(new_unit) # Mile squared new_unit = UnitOfMeasure("mi^2", lambda x: x / 2.589988e6, lambda y: y * 2.589988e6) new_unit.addAlias("mi²") new_unit.addAlias("mile squared") new_unit.addAlias("miles squared") self.registerUnitOfMeasure(new_unit) # Yard squared new_unit = UnitOfMeasure("yd^2", lambda x: x / 8.361274e-1, lambda y: y * 8.361274e-1) new_unit.addAlias("yd²") new_unit.addAlias("yard squared") new_unit.addAlias("yards squared") self.registerUnitOfMeasure(new_unit)
def __init__(self, value, unit): super(Mass, self).__init__(value, unit) # Kilogram new_unit = UnitOfMeasure( 'kg', lambda x: x, lambda y: y ) new_unit.addAlias('kilogram') new_unit.addAlias('kilograms') self.registerUnitOfMeasure(new_unit) # Milligram new_unit = UnitOfMeasure( 'mg', lambda x: x / 1e-6, lambda y: y * 1e-6 ) new_unit.addAlias('milligram') new_unit.addAlias('milligrams') self.registerUnitOfMeasure(new_unit) # Centigram new_unit = UnitOfMeasure( 'cg', lambda x: x / 1e-5, lambda y: y * 1e-5 ) new_unit.addAlias('centigram') new_unit.addAlias('centigrams') self.registerUnitOfMeasure(new_unit) # Gram new_unit = UnitOfMeasure( 'g', lambda x: x / 1e-3, lambda y: y * 1e-3 ) new_unit.addAlias('gram') new_unit.addAlias('grams') self.registerUnitOfMeasure(new_unit) # Tonne (metric) new_unit = UnitOfMeasure( 't', lambda x: x / 1e3, lambda y: y * 1e3 ) new_unit.addAlias('ton') new_unit.addAlias('tons') new_unit.addAlias('tonne') new_unit.addAlias('tonnes') self.registerUnitOfMeasure(new_unit) # Pound new_unit = UnitOfMeasure( 'lb', lambda x: x / 4.535924e-1, lambda y: y * 4.535924e-1 ) new_unit.addAlias('lbs') new_unit.addAlias('pound') new_unit.addAlias('pounds') self.registerUnitOfMeasure(new_unit) # Ounce new_unit = UnitOfMeasure( 'oz', lambda x: x / 2.834952e-2, lambda y: y * 2.834952e-2 ) new_unit.addAlias('ounce') new_unit.addAlias('ounces') self.registerUnitOfMeasure(new_unit)