Closed anthonyverghese closed 6 years ago
In a test we wrote, the input json object is displayed below.
"test_key_2": { "value": 10.00, "units": "mg/L" },
In the test, we check to make sure that calling read_json on this json object is equivalent to "10.00 mg/L". However, an error occurs, AssertionError: '10.0 mg/L' != '10.00 mg/L'. This displays that the input json object is not being converted with the proper precision. It seems as though calling
str(parsed_json[json_key])
in utils.py changes the precision of the number specified by parsed_json[json_key].
This is an interesting issue. You are currently saving the value as a float, thus strange float magic in python land happens. One option is to save "10.00" as a string (surround with ""). And the other thing we just recently learned about AIDE is that there will not be two values to specify an amount (units and value). Instead, there will be a single string with the units appended between a space. Example: "10 in" or "24 m" or "1.533 m^3/s". These are then parsed directly by fusion. This means that this is now how you can assume the values are given. To make potential unit conversions more simple, you should use a units library, specifically pint (this is the library the rest of AguaClara uses.) Therefor you eed to make a function that converts these strings to valid pint objects. Next, conversion is as simple as a single function call. My recommendation for now, however, is to ignore any of this, and just know that measurements are given in string form. Assume this is a readable, correct-unit string form!
When read_json is called on some json objects, the precision of the number inputted is changed, which causes some tests to fail.