source_unit_uri: the URI of a Unit in the jena-fuseki database
destination_unit_uri: the URI of a Unit in the jena-fuseki database
source_value: a numerical value to be converted.
Return:
The converted value. Assume that "source_value" has "source_unit_uri" as its Unit. Discover and perform the numerical conversion to find the new value with "destination_unit_uri" as the Unit.
Background Information
The QUDT ontology includes the information necessary to convert between units that share a unit class. Units include conversionOffset and conversionMultiplier fields that are used for this purpose.
Examples
Kelvin
conversionMultiplier = 1.0
conversionOffset = 0.0
DegreeCelcius
conversionMultiplier = 1.0
conversionOffset = 273.15
DegreeFarenheit
conversionMultiplier = 0.5555555555555556
conversionOffset = 255.37037037037038
Exceptions
In some cases, it will not be possible to convert between units. In these cases, a ValueError exception must be thrown.
Units not in same class
If the two input Units are not in the same class, the function should return an exception. The conversion is not possible.
Unit is missing conversionMultiplier or conversionOffset
The conversion will not be possible
Unit Tests
Some unit tests should be implemented to verify that this function works correctly. Use Python's unittest package to build unit test functions. There should be functions that test correct operation, but there should also be assertRaises() tests to verify that exceptions are raised in the correct cases.
These tests should be implemented in the file test_qudt4dt.py in the repository. Refactor the tests in this file as a unit test class, and add new tests for convert_value.
To work on this issue, create a new Git Branch called "issue-3".
In qudt4dt/init.py there is a function
Parameters:
Return: The converted value. Assume that "source_value" has "source_unit_uri" as its Unit. Discover and perform the numerical conversion to find the new value with "destination_unit_uri" as the Unit.
Background Information
The QUDT ontology includes the information necessary to convert between units that share a unit class. Units include conversionOffset and conversionMultiplier fields that are used for this purpose.
Examples
Exceptions
In some cases, it will not be possible to convert between units. In these cases, a
ValueError
exception must be thrown.Unit Tests
Some unit tests should be implemented to verify that this function works correctly. Use Python's unittest package to build unit test functions. There should be functions that test correct operation, but there should also be
assertRaises()
tests to verify that exceptions are raised in the correct cases.These tests should be implemented in the file
test_qudt4dt.py
in the repository. Refactor the tests in this file as a unit test class, and add new tests forconvert_value
.