unitcorn 0.9.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of unitcorn might be problematic. Click here for more details.
- unitcorn/__init__.py +110 -0
- unitcorn/airQuality/__init__.py +99 -0
- unitcorn/area/__init__.py +3 -0
- unitcorn/area/area.py +103 -0
- unitcorn/base/Decorators.py +72 -0
- unitcorn/base/Registry.py +75 -0
- unitcorn/base/SmartBases.py +26 -0
- unitcorn/base/_Algebra.py +205 -0
- unitcorn/base/_Measurement.py +1122 -0
- unitcorn/base/_ScalingMeasurement.py +398 -0
- unitcorn/base/_SmartFloat.py +1635 -0
- unitcorn/base/__init__.py +6 -0
- unitcorn/config/__init__.py +318 -0
- unitcorn/config/__main__.py +8 -0
- unitcorn/config/si.toml +53 -0
- unitcorn/config/template.toml +146 -0
- unitcorn/config/us.toml +53 -0
- unitcorn/defaults/WeatherFlow/__init__.py +176 -0
- unitcorn/defaults/__init__.py +1 -0
- unitcorn/derived/__init__.py +16 -0
- unitcorn/derived/density.py +26 -0
- unitcorn/derived/partsPer.py +96 -0
- unitcorn/derived/precipitation.py +96 -0
- unitcorn/derived/rate.py +80 -0
- unitcorn/derived/volume.py +122 -0
- unitcorn/derived/wind.py +54 -0
- unitcorn/digital/__init__.py +21 -0
- unitcorn/energy/__init__.py +4 -0
- unitcorn/energy/energy.py +120 -0
- unitcorn/energy/power.py +83 -0
- unitcorn/errors/Conversion.py +12 -0
- unitcorn/errors/Unit.py +4 -0
- unitcorn/errors/__init__.py +7 -0
- unitcorn/length/__init__.py +19 -0
- unitcorn/length/imperial.py +46 -0
- unitcorn/length/length.py +74 -0
- unitcorn/length/metric.py +56 -0
- unitcorn/mass/__init__.py +15 -0
- unitcorn/mass/imperial.py +47 -0
- unitcorn/mass/mass.py +57 -0
- unitcorn/mass/metric.py +47 -0
- unitcorn/others/__init__.py +338 -0
- unitcorn/others/light.py +51 -0
- unitcorn/pressure/__init__.py +3 -0
- unitcorn/pressure/pressure.py +189 -0
- unitcorn/py.typed +0 -0
- unitcorn/temperature/__init__.py +19 -0
- unitcorn/temperature/celsius.py +23 -0
- unitcorn/temperature/change.py +156 -0
- unitcorn/temperature/fahrenheit.py +24 -0
- unitcorn/temperature/kelvin.py +25 -0
- unitcorn/temperature/temperature.py +154 -0
- unitcorn/time_/__init__.py +1 -0
- unitcorn/time_/time.py +387 -0
- unitcorn/utils.py +399 -0
- unitcorn-0.9.0.dist-info/METADATA +536 -0
- unitcorn-0.9.0.dist-info/RECORD +59 -0
- unitcorn-0.9.0.dist-info/WHEEL +4 -0
- unitcorn-0.9.0.dist-info/licenses/LICENSE.txt +17 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
from ..base.Decorators import UnitType, Tiny, Small, Medium, Large, Huge
|
|
2
|
+
from ..base import both, Scale, ScalingMeasurement
|
|
3
|
+
|
|
4
|
+
__all__ = ['Energy']
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@UnitType
|
|
8
|
+
class Energy(ScalingMeasurement, baseUnit='Joule', system=both):
|
|
9
|
+
Joule: type
|
|
10
|
+
Kilojoule: type
|
|
11
|
+
Megajoule: type
|
|
12
|
+
Gigajoule: type
|
|
13
|
+
WattHour: type
|
|
14
|
+
KilowattHour: type
|
|
15
|
+
MegawattHour: type
|
|
16
|
+
Calorie: type
|
|
17
|
+
BritishThermalUnit: type
|
|
18
|
+
|
|
19
|
+
class _Scale(Scale):
|
|
20
|
+
Joule = 1
|
|
21
|
+
Kilojoule = 1000
|
|
22
|
+
Megajoule = 1000
|
|
23
|
+
Gigajoule = 1000
|
|
24
|
+
Base = 'Joule'
|
|
25
|
+
# Variants are given as their size in joules.
|
|
26
|
+
WattHour = 3600.
|
|
27
|
+
KilowattHour = 3.6e6
|
|
28
|
+
MegawattHour = 3.6e9
|
|
29
|
+
Calorie = 4.184
|
|
30
|
+
BritishThermalUnit = 1055.05585262
|
|
31
|
+
|
|
32
|
+
@property
|
|
33
|
+
def joule(self):
|
|
34
|
+
return Joule(self)
|
|
35
|
+
|
|
36
|
+
@property
|
|
37
|
+
def kilojoule(self):
|
|
38
|
+
return Kilojoule(self)
|
|
39
|
+
|
|
40
|
+
@property
|
|
41
|
+
def megajoule(self):
|
|
42
|
+
return Megajoule(self)
|
|
43
|
+
|
|
44
|
+
@property
|
|
45
|
+
def gigajoule(self):
|
|
46
|
+
return Gigajoule(self)
|
|
47
|
+
|
|
48
|
+
@property
|
|
49
|
+
def wattHour(self):
|
|
50
|
+
return WattHour(self)
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def kilowattHour(self):
|
|
54
|
+
return KilowattHour(self)
|
|
55
|
+
|
|
56
|
+
@property
|
|
57
|
+
def megawattHour(self):
|
|
58
|
+
return MegawattHour(self)
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def calorie(self):
|
|
62
|
+
return Calorie(self)
|
|
63
|
+
|
|
64
|
+
@property
|
|
65
|
+
def britishThermalUnit(self):
|
|
66
|
+
return BritishThermalUnit(self)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@Tiny
|
|
70
|
+
class Joule(Energy):
|
|
71
|
+
_unit = 'J'
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@Small
|
|
75
|
+
class Kilojoule(Energy):
|
|
76
|
+
_unit = 'kJ'
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@Medium
|
|
80
|
+
class Megajoule(Energy):
|
|
81
|
+
_unit = 'MJ'
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
@Large
|
|
85
|
+
class Gigajoule(Energy):
|
|
86
|
+
_unit = 'GJ'
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class WattHour(Energy):
|
|
90
|
+
_unit = 'Wh'
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class KilowattHour(Energy):
|
|
94
|
+
_unit = 'kWh'
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class MegawattHour(Energy):
|
|
98
|
+
_unit = 'MWh'
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class Calorie(Energy):
|
|
102
|
+
_unit = 'cal'
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class BritishThermalUnit(Energy):
|
|
106
|
+
_unit = 'BTU'
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
Energy.Joule = Joule
|
|
110
|
+
Energy.Kilojoule = Kilojoule
|
|
111
|
+
Energy.Megajoule = Megajoule
|
|
112
|
+
Energy.Gigajoule = Gigajoule
|
|
113
|
+
Energy.WattHour = WattHour
|
|
114
|
+
Energy.KilowattHour = KilowattHour
|
|
115
|
+
Energy.MegawattHour = MegawattHour
|
|
116
|
+
Energy.Calorie = Calorie
|
|
117
|
+
Energy.BritishThermalUnit = BritishThermalUnit
|
|
118
|
+
Energy.Wh = Energy.wattHour
|
|
119
|
+
Energy.kWh = Energy.kilowattHour
|
|
120
|
+
Energy.MWh = Energy.megawattHour
|
unitcorn/energy/power.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
from ..base.Decorators import UnitType, Tiny, Small, Medium, Large, Huge
|
|
2
|
+
from ..base import both, Scale, ScalingMeasurement
|
|
3
|
+
|
|
4
|
+
__all__ = ['Power']
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@UnitType
|
|
8
|
+
class Power(ScalingMeasurement, baseUnit='Watt', system=both):
|
|
9
|
+
Watt: type
|
|
10
|
+
Kilowatt: type
|
|
11
|
+
Megawatt: type
|
|
12
|
+
Gigawatt: type
|
|
13
|
+
Horsepower: type
|
|
14
|
+
BritishThermalUnitPerHour: type
|
|
15
|
+
|
|
16
|
+
class _Scale(Scale):
|
|
17
|
+
Watt = 1
|
|
18
|
+
Kilowatt = 1000
|
|
19
|
+
Megawatt = 1000
|
|
20
|
+
Gigawatt = 1000
|
|
21
|
+
Base = 'Watt'
|
|
22
|
+
# Variants are given as their size in watts.
|
|
23
|
+
Horsepower = 745.69987158227
|
|
24
|
+
BritishThermalUnitPerHour = 0.29307107
|
|
25
|
+
|
|
26
|
+
@property
|
|
27
|
+
def watt(self):
|
|
28
|
+
return Watt(self)
|
|
29
|
+
|
|
30
|
+
@property
|
|
31
|
+
def kilowatt(self):
|
|
32
|
+
return Kilowatt(self)
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
def megawatt(self):
|
|
36
|
+
return Megawatt(self)
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def gigawatt(self):
|
|
40
|
+
return Gigawatt(self)
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def horsepower(self):
|
|
44
|
+
return Horsepower(self)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@Tiny
|
|
48
|
+
class Watt(Power):
|
|
49
|
+
_unit = 'W'
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@Small
|
|
53
|
+
class Kilowatt(Power):
|
|
54
|
+
_unit = 'kW'
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@Medium
|
|
58
|
+
class Megawatt(Power):
|
|
59
|
+
_unit = 'MW'
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@Large
|
|
63
|
+
class Gigawatt(Power):
|
|
64
|
+
_unit = 'GW'
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class Horsepower(Power):
|
|
68
|
+
_unit = 'hp'
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class BritishThermalUnitPerHour(Power):
|
|
72
|
+
_unit = 'BTU/h'
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
Power.Watt = Watt
|
|
76
|
+
Power.Kilowatt = Kilowatt
|
|
77
|
+
Power.Megawatt = Megawatt
|
|
78
|
+
Power.Gigawatt = Gigawatt
|
|
79
|
+
Power.Horsepower = Horsepower
|
|
80
|
+
Power.BritishThermalUnitPerHour = BritishThermalUnitPerHour
|
|
81
|
+
Power.W = Power.watt
|
|
82
|
+
Power.kW = Power.kilowatt
|
|
83
|
+
Power.MW = Power.megawatt
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class BadConversion(Exception):
|
|
2
|
+
"""These two measurements can not be converted this way"""
|
|
3
|
+
def __init__(self, first, second):
|
|
4
|
+
self.message = f"{first} can not be converted to {second} this way"
|
|
5
|
+
super().__init__(self.message)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class UnknownUnit(Exception):
|
|
9
|
+
"""This measurement can not be converted to that unit"""
|
|
10
|
+
def __init__(self, measurement, unit: str):
|
|
11
|
+
self.message = f"{measurement} can not be converted to '{unit}'"
|
|
12
|
+
super().__init__(self.message)
|
unitcorn/errors/Unit.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from .length import Length
|
|
2
|
+
from .metric import *
|
|
3
|
+
from .imperial import *
|
|
4
|
+
|
|
5
|
+
__all__ = ['Length']
|
|
6
|
+
|
|
7
|
+
Length.Millimeter = Millimeter
|
|
8
|
+
Length.Centimeter = Centimeter
|
|
9
|
+
Length.Decimeter = Decimeter
|
|
10
|
+
Length.Meter = Meter
|
|
11
|
+
Length.Decameter = Decameter
|
|
12
|
+
Length.Hectometer = Hectometer
|
|
13
|
+
Length.Kilometer = Kilometer
|
|
14
|
+
|
|
15
|
+
Length.Line = Line
|
|
16
|
+
Length.Inch = Inch
|
|
17
|
+
Length.Foot = Foot
|
|
18
|
+
Length.Yard = Yard
|
|
19
|
+
Length.Mile = Mile
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from ..base.Decorators import Tiny, Small, Medium, Large
|
|
2
|
+
from ..base import Scale, ScalingMeasurement
|
|
3
|
+
from ..base import imperial
|
|
4
|
+
from .length import Length
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ImperialLength(ScalingMeasurement, Length, system=imperial, baseUnit='Foot'):
|
|
8
|
+
|
|
9
|
+
common = {'Inch', 'Foot', 'Yard', 'Mile'}
|
|
10
|
+
|
|
11
|
+
class _Scale(Scale):
|
|
12
|
+
Line = 1
|
|
13
|
+
Inch = 12
|
|
14
|
+
Foot = 12
|
|
15
|
+
Yard = 3
|
|
16
|
+
Mile = 1760
|
|
17
|
+
Base = 'Foot'
|
|
18
|
+
|
|
19
|
+
def _meter(self):
|
|
20
|
+
return self.changeScale(self._Scale.Foot) * 0.3048
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@Tiny
|
|
24
|
+
class Line(ImperialLength):
|
|
25
|
+
_unit = 'ln'
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@Small
|
|
29
|
+
class Inch(ImperialLength):
|
|
30
|
+
_unit = 'in'
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@Medium
|
|
34
|
+
class Foot(ImperialLength, pluralName='Feet'):
|
|
35
|
+
_unit = 'ft'
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@Medium
|
|
39
|
+
class Yard(ImperialLength):
|
|
40
|
+
_unit = 'yd'
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@Large
|
|
44
|
+
class Mile(ImperialLength):
|
|
45
|
+
_unit = 'mi'
|
|
46
|
+
_precision = 1
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
from ..base import Dimension
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Length(metaclass=Dimension, symbol='L'):
|
|
5
|
+
Millimeter: type
|
|
6
|
+
Centimeter: type
|
|
7
|
+
Decimeter: type
|
|
8
|
+
Meter: type
|
|
9
|
+
Decameter: type
|
|
10
|
+
Hectometer: type
|
|
11
|
+
Kilometer: type
|
|
12
|
+
|
|
13
|
+
Line: type
|
|
14
|
+
Inch: type
|
|
15
|
+
Foot: type
|
|
16
|
+
Yard: type
|
|
17
|
+
Mile: type
|
|
18
|
+
|
|
19
|
+
@property
|
|
20
|
+
def millimeter(self):
|
|
21
|
+
from . import Millimeter
|
|
22
|
+
return Millimeter(self)
|
|
23
|
+
mm = millimeter
|
|
24
|
+
|
|
25
|
+
@property
|
|
26
|
+
def centimeter(self):
|
|
27
|
+
from . import Centimeter
|
|
28
|
+
return Centimeter(self)
|
|
29
|
+
cm = centimeter
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def meter(self):
|
|
33
|
+
from . import Meter
|
|
34
|
+
return Meter(self)
|
|
35
|
+
m = meter
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
def kilometer(self):
|
|
39
|
+
from . import Kilometer
|
|
40
|
+
return Kilometer(self)
|
|
41
|
+
km = kilometer
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def line(self):
|
|
45
|
+
from . import Line
|
|
46
|
+
return Line(self)
|
|
47
|
+
ln = line
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def inch(self):
|
|
51
|
+
from . import Inch
|
|
52
|
+
return Inch(self)
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def foot(self):
|
|
56
|
+
from . import Foot
|
|
57
|
+
return Foot(self)
|
|
58
|
+
ft = foot
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def yard(self):
|
|
62
|
+
from . import Yard
|
|
63
|
+
return Yard(self)
|
|
64
|
+
yd = yard
|
|
65
|
+
|
|
66
|
+
@property
|
|
67
|
+
def mile(self):
|
|
68
|
+
from . import Mile
|
|
69
|
+
return Mile(self)
|
|
70
|
+
mi = mile
|
|
71
|
+
|
|
72
|
+
def __getitem__(self, item):
|
|
73
|
+
item = 'inch' if item == 'in' else item
|
|
74
|
+
super().__getitem__(item)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
from ..base.Decorators import Tiny, Small, Medium, Large
|
|
2
|
+
from ..base import Scale, ScalingMeasurement
|
|
3
|
+
from ..base import metric
|
|
4
|
+
from .length import Length
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class MetricLength(ScalingMeasurement, Length, system=metric, baseUnit='Meter'):
|
|
8
|
+
|
|
9
|
+
common = {'Kilometer', 'Meter', 'Centimeter', 'Millimeter'}
|
|
10
|
+
|
|
11
|
+
class _Scale(Scale):
|
|
12
|
+
Millimeter = 1
|
|
13
|
+
Centimeter = 10
|
|
14
|
+
Decimeter = 10
|
|
15
|
+
Meter = 10
|
|
16
|
+
Decameter = 10
|
|
17
|
+
Hectometer = 10
|
|
18
|
+
Kilometer = 10
|
|
19
|
+
Base = 'Meter'
|
|
20
|
+
|
|
21
|
+
def _foot(self):
|
|
22
|
+
return self.changeScale(self._Scale.Meter) * 3.280839895013123
|
|
23
|
+
|
|
24
|
+
@Tiny
|
|
25
|
+
class Millimeter(MetricLength):
|
|
26
|
+
_unit = 'mm'
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@Small
|
|
30
|
+
class Centimeter(MetricLength):
|
|
31
|
+
_unit = 'cm'
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@Small
|
|
35
|
+
class Decimeter(MetricLength):
|
|
36
|
+
_unit = 'dm'
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@Medium
|
|
40
|
+
class Meter(MetricLength):
|
|
41
|
+
_unit = 'm'
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@Medium
|
|
45
|
+
class Decameter(MetricLength):
|
|
46
|
+
_unit = 'dam'
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@Large
|
|
50
|
+
class Hectometer(MetricLength):
|
|
51
|
+
_unit = 'hm'
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@Large
|
|
55
|
+
class Kilometer(MetricLength):
|
|
56
|
+
_unit = 'km'
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from .mass import Mass
|
|
2
|
+
from .metric import *
|
|
3
|
+
from .imperial import *
|
|
4
|
+
|
|
5
|
+
__all__ = ['Mass']
|
|
6
|
+
|
|
7
|
+
Mass.Microgram = Microgram
|
|
8
|
+
Mass.Milligram = Milligram
|
|
9
|
+
Mass.Gram = Gram
|
|
10
|
+
Mass.Kilogram = Kilogram
|
|
11
|
+
Mass.Dram = Dram
|
|
12
|
+
Mass.Ounce = Ounce
|
|
13
|
+
Mass.Pound = Pound
|
|
14
|
+
Mass.Hundredweight = Hundredweight
|
|
15
|
+
Mass.Ton = Ton
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from ..base.Decorators import Tiny, Small, Large, Huge
|
|
2
|
+
from ..base import Scale, ScalingMeasurement, Dimension, imperial
|
|
3
|
+
from .mass import Mass
|
|
4
|
+
|
|
5
|
+
__all__ = ['Dram', 'Ounce', 'Pound', 'Hundredweight', 'Ton']
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Imperial(ScalingMeasurement, Mass, metaclass=Dimension, system=imperial, baseUnit='Pound'):
|
|
9
|
+
|
|
10
|
+
common = {'Gram', 'Pound', 'Ounce', 'Ton'}
|
|
11
|
+
|
|
12
|
+
class _Scale(Scale):
|
|
13
|
+
Dram = 1
|
|
14
|
+
Ounce = 16
|
|
15
|
+
Pound = 16
|
|
16
|
+
Hundredweight = 100
|
|
17
|
+
Ton = 20
|
|
18
|
+
Base = 'Pound'
|
|
19
|
+
|
|
20
|
+
def _gram(self):
|
|
21
|
+
return self.changeScale(self._Scale.Ounce) * 28.349523125
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@Tiny
|
|
25
|
+
class Dram(Imperial):
|
|
26
|
+
_unit = 'dr'
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@Small
|
|
30
|
+
class Ounce(Imperial):
|
|
31
|
+
_unit = 'oz'
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@Small
|
|
35
|
+
class Pound(Imperial):
|
|
36
|
+
_unit = 'lbs'
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@Large
|
|
40
|
+
class Hundredweight(Imperial):
|
|
41
|
+
_unit = 'cwt'
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@Huge
|
|
45
|
+
class Ton(Imperial):
|
|
46
|
+
_id = 'tUS'
|
|
47
|
+
_unit = 't'
|
unitcorn/mass/mass.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
from ..base import Dimension
|
|
2
|
+
|
|
3
|
+
__all__ = ['Mass']
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Mass(metaclass=Dimension, symbol='M'):
|
|
7
|
+
Gram: type
|
|
8
|
+
Microgram: type
|
|
9
|
+
Milligram: type
|
|
10
|
+
Kilogram: type
|
|
11
|
+
Dram: type
|
|
12
|
+
Ounce: type
|
|
13
|
+
Pound: type
|
|
14
|
+
Hundredweight: type
|
|
15
|
+
Ton: type
|
|
16
|
+
|
|
17
|
+
@property
|
|
18
|
+
def microgram(self):
|
|
19
|
+
from . import Microgram
|
|
20
|
+
return Microgram(self)
|
|
21
|
+
|
|
22
|
+
@property
|
|
23
|
+
def milligram(self):
|
|
24
|
+
from . import Milligram
|
|
25
|
+
return Milligram(self)
|
|
26
|
+
|
|
27
|
+
@property
|
|
28
|
+
def gram(self):
|
|
29
|
+
from . import Gram
|
|
30
|
+
return Gram(self)
|
|
31
|
+
|
|
32
|
+
@property
|
|
33
|
+
def kilogram(self):
|
|
34
|
+
from . import Kilogram
|
|
35
|
+
return Kilogram(self)
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
def dram(self):
|
|
39
|
+
from . import Dram
|
|
40
|
+
return Dram(self)
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def ounce(self):
|
|
44
|
+
from . import Ounce
|
|
45
|
+
return Ounce(self)
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
def pound(self):
|
|
49
|
+
from . import Pound
|
|
50
|
+
return Pound(self)
|
|
51
|
+
|
|
52
|
+
ug = microgram
|
|
53
|
+
mg = milligram
|
|
54
|
+
g = gram
|
|
55
|
+
kg = kilogram
|
|
56
|
+
oz = ounce
|
|
57
|
+
lbs = pound
|
unitcorn/mass/metric.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from ..base.Decorators import Tiny, Small, Large, Huge
|
|
2
|
+
from ..base import Scale, ScalingMeasurement, metric
|
|
3
|
+
from .mass import Mass
|
|
4
|
+
|
|
5
|
+
__all__ = ['Metric', 'Microgram', 'Milligram', 'Gram', 'Kilogram', 'Tonne']
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Metric(ScalingMeasurement, Mass, system=metric, baseUnit='Kilogram'):
|
|
9
|
+
|
|
10
|
+
common = {'Kilogram', 'Gram', 'Milligram'}
|
|
11
|
+
|
|
12
|
+
class _Scale(Scale):
|
|
13
|
+
Microgram = 1
|
|
14
|
+
Milligram = 1000
|
|
15
|
+
Gram = 1000
|
|
16
|
+
Kilogram = 1000
|
|
17
|
+
Tonne = 1000
|
|
18
|
+
Base = 'Kilogram'
|
|
19
|
+
|
|
20
|
+
def _pound(self):
|
|
21
|
+
return self.changeScale(self._Scale.Kilogram) * 2.2046226218
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@Tiny
|
|
25
|
+
class Microgram(Metric):
|
|
26
|
+
_unit = 'μg'
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@Tiny
|
|
30
|
+
class Milligram(Metric):
|
|
31
|
+
_unit = 'mg'
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@Small
|
|
35
|
+
class Gram(Metric):
|
|
36
|
+
_unit = 'g'
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@Large
|
|
40
|
+
class Kilogram(Metric):
|
|
41
|
+
_unit = 'kg'
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@Huge
|
|
45
|
+
class Tonne(Metric):
|
|
46
|
+
_id = 'tSI'
|
|
47
|
+
_unit = 't'
|