Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(FUS-1124): add new unit types #14

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ Metric to metric:
mass_grams = converter.convert(unit_from="kg", unit_to="g", value=1)


# Contribution

1. Cover your changes with unit tests.
2. Bump version in src/version.py if you want your changes to be released.


# Testing

1. Create virtualenv via your favourite tool, for example
Expand Down
2 changes: 2 additions & 0 deletions src/corva_unit_converter/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
"torque": definitions.torque.rule,
"volume_concentration": definitions.volume_concentration.rule,
"volume_flow_rate": definitions.volume_flow_rate.rule,
"voltage": definitions.voltage.rule,
"viscosity": definitions.viscosity.rule
}


Expand Down
4 changes: 3 additions & 1 deletion src/corva_unit_converter/definitions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
temperature,
time,
torque,
viscosity,
voltage,
volume_concentration,
volume_flow_rate,
Expand Down Expand Up @@ -71,5 +72,6 @@
"torque",
"voltage",
"volume_concentration",
"volume_flow_rate"
"volume_flow_rate",
"viscosity"
]
36 changes: 32 additions & 4 deletions src/corva_unit_converter/definitions/density.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,19 @@
"gm/3",
"gm/c"
]
}
},
"mg/l": {
"name": {
"singular": "Milligram per Liter",
"plural": "Milligrams per Liter",
"display": "mg/l"
},
"to_anchor": 1 / 1000000,
"aliases": [
"mg/l",
"mg/L"
]
},
}

imperial = {
Expand All @@ -82,7 +94,10 @@
},
"to_anchor": 1,
"aliases": [
"lb/gal"
"lb/gal",
"lbm/gal",
"lbm/galUS",
"lbs/galUS"
]
},
# https://glossary.slb.com/en/terms/p/ppg
Expand All @@ -109,7 +124,8 @@
},
"to_anchor": 1 / 1000,
"aliases": [
"lb/Mgal"
"lb/Mgal",
"lbm/Mgal"
]
},
"lb/ft3": {
Expand All @@ -135,7 +151,19 @@
"aliases": [
"lb/in3"
]
}
},
"lb/bbl": {
"name": {
"singular": "Pound Per Barrel",
"plural": "Pounds Per Barrel",
"display": "lb/bbl"
},
"to_anchor": 1 / 42,
"aliases": [
"lb/bbl",
"lbm/bbl",
],
},
}

rule = {
Expand Down
4 changes: 3 additions & 1 deletion src/corva_unit_converter/definitions/gas_concentration.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
},
"to_anchor": 1,
"aliases": [
"%"
"%",
"%%",
"% by vol"
]
},
"ppm": {
Expand Down
17 changes: 14 additions & 3 deletions src/corva_unit_converter/definitions/gas_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
"plural": "Millilitres",
"display": "ml"
},
"to_anchor": 1 / 1000000
"to_anchor": 1 / 1000000,
"aliases": [
"mL",
"ml of",
"mL of"
]
},
"cl": {
"name": {
Expand Down Expand Up @@ -177,7 +182,10 @@
"plural": "Gallons",
"display": "gal"
},
"to_anchor": 0.000133
"to_anchor": 0.000133,
"aliases": [
"gals",
]
},
"ft3": {
"name": {
Expand All @@ -201,7 +209,10 @@
"plural": "Oil barrels",
"display": "bbl"
},
"to_anchor": 0.0056
"to_anchor": 0.0056,
"aliases": [
"bbls",
]
},
"Mscf": {
"name": {
Expand Down
11 changes: 10 additions & 1 deletion src/corva_unit_converter/definitions/length.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
'display': 'ft'
},
'to_anchor': 1,
'aliases': ['f', 'ft', "'", 'feet'],
'aliases': ['f', 'ft', "'", 'feet', "ftUS"],
},
'mi': {
'name': {
Expand All @@ -73,6 +73,15 @@
},
'to_anchor': 5280,
'aliases': ['mi'],
},
'32nd': {
'name': {
'singular': '1/32 part of an Inch',
'plural': '32 parts of an Inch',
'display': '¹/₃₂ part of an Inch'
},
'to_anchor': 1 / 384,
'aliases': ['32nd', "32nd in", "in/32"],
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/corva_unit_converter/definitions/mass.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
},
"to_anchor": 1,
"aliases": [
"lb"
"lb",
"lbs"
]
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/corva_unit_converter/definitions/pressure.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@
},
"to_anchor": ((1 / 144) / 100000),
"aliases": [
"hsf"
"hsf",
"lbf/100 ft2",
"lbf/100ft2",
"lbf/(100·ft²)",
"lb/100ft2"
]
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/corva_unit_converter/definitions/temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"to_anchor": 1,
"anchor_shift": 0,
"aliases": [
"degc"
"degc",
"degC",
"°C"
]
},
"K": {
Expand All @@ -34,7 +36,10 @@
},
"to_anchor": 1,
"aliases": [
"degf"
"degf",
"degF",
"°F",
"deg/F"
]
}
}
Expand Down
30 changes: 30 additions & 0 deletions src/corva_unit_converter/definitions/viscosity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
metric = {
"mpas": {
"name": {
"singular": "Millipascal-second",
"plural": "Millipascal-seconds",
"display": "mPa·s",
},
"to_anchor": 1,
"aliases": ["cP", "mPa·s", "mPa.s", "mPa*s"],
},
"pas": {
"name": {
"singular": "Pascal-second",
"plural": "Pascal-seconds",
"display": "Pa·s",
},
"to_anchor": 1000,
"aliases": ["Pa·s", "Pa.s", "Pa*s"],
},
}

rule = {
"metric": metric,
"_anchors": {
"metric": {
"unit": "s",
"ratio": 1
}
}
}
11 changes: 11 additions & 0 deletions src/corva_unit_converter/definitions/voltage.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@
"aliases": [
"mV"
]
},
"nV": {
"name": {
"singular": "Nanovolt",
"plural": "Nanovolts",
"display": "nV"
},
"to_anchor": 1/1000000,
"aliases": [
"nV"
]
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/corva_unit_converter/definitions/volume_flow_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,18 @@
"aliases": [
"km3/s"
]
},
"ml/30min": {
"name": {
"singular": "Millilitre per 30 Minutes",
"plural": "Millilitres per 30 Minutes",
"display": "ml/30min"
},
"to_anchor": 1/1800000,
"aliases": [
"ml/30min",
"mL/30 min"
]
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "0.4.0"
VERSION = "0.5.0"
2 changes: 1 addition & 1 deletion tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_get_measures_returns_correct_keys():
"mass", "mass_flow_rate", "mpl", "porosity", "power", "pressure",
"pressure_gradient", "proportion", "revolution_per_volume", "speed",
"strokes_rate", "temperature", "time", "torque",
"volume_concentration", "volume_flow_rate"
"volume_concentration", "volume_flow_rate", "viscosity", "voltage"
]

assert sorted(result) == sorted(expected_keys)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
"measure": 'density'},
{"from": "ppg", "amount": 1, "to": "lb/in3", "expected": 0.00432900442862808,
"measure": 'density'},
{"from": "mg/l", "amount": 1, "to": "lb/bbl", "expected": 0.000350507,
"measure": 'density'},
{"from": "lb/bbl", "amount": 1, "to": "mg/l", "expected": 2853.0095238095237,
"measure": 'density'},
# {"from": "lb/Mgal", "amount": 1, "to": "kg/m3", "expected": 119826.4},
# {"from": "kg/m3", "amount": 1, "to": "lb/Mgal", "expected": 8.3454e-06}
]
Expand Down
2 changes: 2 additions & 0 deletions tests/test_length.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
{"from": "mi", "amount": 1, "to": "km", "expected": 1.609343502101154},
{"from": "in", "amount": 1, "to": "mm", "expected": 25.4},
{"from": "mm", "amount": 1, "to": "in", "expected": 0.0393701},
{"from": "32nd", "amount": 1, "to": "mm", "expected": 0.7937499746000007},
{"from": "mm", "amount": 1, "to": "32nd", "expected": 1.25984256},
]


Expand Down
10 changes: 10 additions & 0 deletions tests/test_viscosity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .utils import convert_units

cases = [
{"from": "mpas", "amount": 1, "to": "pas", "expected": 0.001},
{"from": "pas", "amount": 1, "to": "mpas", "expected": 1000},
]


def test():
convert_units(cases)
10 changes: 10 additions & 0 deletions tests/test_voltage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .utils import convert_units

cases = [
{"from": "V", "amount": 1, "to": "nV", "expected": 1000000000},
{"from": "nV", "amount": 1, "to": "V", "expected": 0.000000001},
]


def test():
convert_units(cases)
4 changes: 3 additions & 1 deletion tests/test_volume_flow_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
# test cases
cases = [
{"from": "gal/min", "amount": 1, "to": "m3/min", "expected": 0.00378541},
{"from": "m3/min", "amount": 1, "to": "gal/min", "expected": 264.172}
{"from": "m3/min", "amount": 1, "to": "gal/min", "expected": 264.172},
{"from": "gal/min", "amount": 1, "to": "ml/30min", "expected": 113562.354},
{"from": "ml/30min", "amount": 1, "to": "gal/min", "expected": 0.00000880573508},
]


Expand Down
Loading