utils module¶
Utility functions and classes for common calculations and networking patterns.
- Jin Cheng 12/12/16:
- StopHeatingError, async
fetch()
function that makes HTTP requests. The Network queue. Number manipulation functions.
-
class
robotchem.utils.
NetworkQueue
(*args, **kwargs)[source]¶ Bases:
asyncio.queues.Queue
A Queue object with additional attribute to store last time an item was retrieved and processed.
-
exception
robotchem.utils.
StopHeatingError
[source]¶ Bases:
BaseException
An exception, when raised, should stop heating in cells and terminate current active calorimetry job.
-
robotchem.utils.
clamp
(number, min_number=0, max_number=100)[source]¶ A function that clamps the input argument number within the given range.
Parameters: - number – The number to be clamped.
- min_number – Minimum value the clamped result can take.
- max_number – Maximum value the clamped result can take.
Returns: The clamped result.
-
robotchem.utils.
fetch
(session, method, url, payload, timeout=5, **kwargs)[source]¶ An asynchronous HTTP request function sending JSON data, with an automatically included ACCESS_CODE field from settings.py.
Parameters: - session – the async HTTP session content manager
- method – method of the HTTP request
- url – URL of the API endpoint
- timeout – raise a time out error after this duration of time (in seconds)
- payload – dictionary containing JSON content
- kwargs – extra JSON data to send, omitting ACCESS_CODE (which is automatically included)
Returns: decoded JSON response as dict or list.
-
robotchem.utils.
roughly_equal
(*args, tolerence=0.01)[source]¶ Compares argument inputs for equality. If all of their differences with each other are within the set tolerance, return True, vice versa.
Parameters: - args – Compared numbers.
- tolerence – If all differences between inputs are within this value, return True.
Returns: Whether the arguments are roughly equal to each other.