Skip to content

Commit

Permalink
Release 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
point85 committed Oct 9, 2019
1 parent d6f8350 commit b3fa382
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 75 deletions.
44 changes: 3 additions & 41 deletions PyCaliper/test/test_snippet.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,8 @@
import unittest, math

from PyCaliper.uom.measurement_system import MeasurementSystem
from PyCaliper.uom.cache_manager import CacheManager
from PyCaliper.uom.enums import Unit, UnitType, Constant
from PyCaliper.uom.quantity import Quantity
from PyCaliper.test.testing_utils import TestingUtils
from PyCaliper.uom.prefix import Prefix
import unittest


class TestSnippet(unittest.TestCase):
def testOne(self):
msys = MeasurementSystem.instance()

# convert Unit to nanokatal
u = msys.getUOM(Unit.UNIT)
katal = msys.getUOM(Unit.KATAL)
q1 = Quantity(1.0, u)
q2 = q1.convert(msys.createPrefixedUOM(Prefix.nano(), katal))

# test result Equivalent
eq = msys.getUOM(Unit.EQUIVALENT)
litre = msys.getUOM(Unit.LITRE)
mEqPerL = msys.createQuotientUOM(UnitType.MOLAR_CONCENTRATION, None, "milliNormal", "mEq/L",
"solute per litre of solvent ", msys.createPrefixedUOM(Prefix.milli(), eq), litre)
testResult = Quantity(5.0, mEqPerL)

# blood cell count test results
k = msys.createPrefixedUOM(Prefix.kilo(), msys.getOne())
uL = msys.createPrefixedUOM(Prefix.micro(), litre)
kul = msys.createQuotientUOM(UnitType.MOLAR_CONCENTRATION, None, "K/uL", "K/uL",
"thousands per microlitre", k, uL)
testResult = Quantity(7.0, kul)

fL = msys.createPrefixedUOM(Prefix.femto(), litre)
testResult = Quantity(90, fL)

# TSH test result
uIU = msys.createPrefixedUOM(Prefix.micro(), msys.getUOM(Unit.INTERNATIONAL_UNIT))
mL = msys.createPrefixedUOM(Prefix.milli(), litre)
uiuPerml = msys.createQuotientUOM(UnitType.MOLAR_CONCENTRATION, None, "uIU/mL", "uIU/mL",
"micro IU per millilitre", uIU, mL)
testResult = Quantity(2.0, uiuPerml)

print(testResult)
pass


2 changes: 1 addition & 1 deletion PyCaliper/uom/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MeasurementType(Enum):
POWER = auto()

##
#This enumeration contains the values for fundamental constants commonly used in science, technology, engineering and math.
# This enumeration contains the values for fundamental constants commonly used in science, technology, engineering and math.
#
class Constant(Enum):
LIGHT_VELOCITY = auto()
Expand Down
25 changes: 0 additions & 25 deletions PyCaliper/uom/locales/test_locale.pot

This file was deleted.

4 changes: 2 additions & 2 deletions PyCaliper/uom/measurement_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ def getQuantity(self, constant):
elif (constant == Constant.MAGNETIC_PERMEABILITY):
# mu0
hm = self.createUnclassifiedQuotientUOM(self.getUOM(Unit.HENRY), self.getUOM(Unit.METRE))
fourPi = 4.0# math.pi# 1.0E-07
fourPi = 4.0 * math.pi * 1.0E-07
named = Quantity(fourPi, hm)
named.name = Localizer.instance().langStr("mu0.name")
named.symbol = Localizer.instance().langStr("mu0.symbol")
Expand Down Expand Up @@ -1145,7 +1145,7 @@ def getUOMKey(uom):
# @return List of {@link UnitOfMeasure}
def getRegisteredUOMs(self):
units = CacheManager.instance().getCachedUOMs()
return sorted(units, key = MeasurementSystem.getUOMKey)
return sorted(units, key=MeasurementSystem.getUOMKey)

##
# Get all the units of measure of the specified type
Expand Down
3 changes: 2 additions & 1 deletion PyCaliper/uom/unit_of_measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def __init__(self, pathUOM, pathFactor):
class UnitOfMeasure(Symbolic):
MAX_SYMBOL_LENGTH = 16

def __init__(self, unitType = UnitType.UNCLASSIFIED, name = None, symbol = None, description = None):
def __init__(self, unitType=UnitType.UNCLASSIFIED, name=None, symbol=None, description=None):
super().__init__(name, symbol, description)

self.conversionRegistry = {}
Expand Down Expand Up @@ -792,6 +792,7 @@ def getBridgeFactor(self, uom):
factor = 1.0 / uom.bridgeScalingFactor

return factor

##
# Divide two units of measure to create a third one.
#
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# PyCaliper
The PyCaliper library project manages units of measure and conversions between them. PyCaliper is designed to be lightweight and simple to use, yet comprehensive. It includes a large number of pre-defined units of measure commonly found in science, engineering, technology, finance and the household. These recognized systems of measurement include the International System of Units (SI), International Customary, United States and British Imperial. Custom units of measure can also be created in the PyCaliper unified measurement system. Custom units are specific to a trade or industry such as industrial packaging where units of can, bottle, case and pallet are typical. Custom units can be added to the unified system for units that are not pre-defined. The PyCaliper library is also available in Java at https://github.com/point85/Caliper and in C# at https://github.com/point85/PyCaliperSharp.
The PyCaliper library project manages units of measure and conversions between them. PyCaliper is designed to be lightweight and simple to use, yet comprehensive. It includes a large number of pre-defined units of measure commonly found in science, engineering, technology, finance and the household. These recognized systems of measurement include the International System of Units (SI), International Customary, United States and British Imperial. Custom units of measure can also be created in the PyCaliper unified measurement system. Custom units are specific to a trade or industry such as industrial packaging where units of can, bottle, case and pallet are typical. Custom units can be added to the unified system for units that are not pre-defined. The PyCaliper library is also available in Java at https://github.com/point85/Caliper and in C# at https://github.com/point85/CaliperSharp.

A PyCaliper measurement system is a collection of units of measure where each pair has a linear relationship, i.e. y = ax + b where 'x' is the abscissa unit to be converted, 'y' (the ordinate) is the converted unit, 'a' is the scaling factor and 'b' is the offset. In the absence of a defined conversion, a unit will always have a conversion to itself. A bridge unit conversion is defined to convert between the fundamental SI and International customary units of mass (i.e. kilogram to pound mass), length (i.e. metre to foot) and temperature (i.e. Kelvin to Rankine). These three bridge conversions permit unit of measure conversions between the two systems. A custom unit can define any bridge conversion such as a bottle to US fluid ounces or litres.

Expand Down Expand Up @@ -275,8 +275,8 @@ e = m.multiply(c).multiply(c)
```

```python
// A Tesla Model S battery has a capacity of 100 KwH.
// When fully charged, how many electrons are in the battery?
# A Tesla Model S battery has a capacity of 100 KwH.
# When fully charged, how many electrons are in the battery?
c = msys.getQuantity(Constant.LIGHT_VELOCITY)
me = msys.getQuantity(Constant.ELECTRON_MASS)
kwh = Quantity(100, msys.createPrefixedUOM(Prefix.kilo(), msys.getUOM(Unit.WATT_HOUR)))
Expand Down Expand Up @@ -454,8 +454,8 @@ msgstr "The unit of measure {0} of type {1} must be the same as {2} of type {3}.
The PyCaliper library depends on version 3.7+.

The PyCaliper library has the following structure:
* `/PyCaliper` - docs.zip (HTML API documentation, setup.py)
* `/PyCaliper/uom` - python library source files
* `/PyCaliper` - docs.zip (HTML API documentation), setup.py
* `/PyCaliper/uom` - python library source files, pycaliper.doxygen (Doxygen documentor configuration)
* `/PyCaliper/uom/locales` - localizable messages.po file to define error messages and localizable units.po file to define the unit's name, symbol and description.
* `/PyCaliper/test` - unittest source files for the library
* `/PyCaliper/scripts` - scripts to convert .po to .mo file
Expand Down

0 comments on commit b3fa382

Please sign in to comment.