biometrics_tracker.model.json_handler module
- class biometrics_tracker.model.json_handler.BiometricsJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)
Bases:
JSONEncoder
Implements a custom json.JSONEncoder to encode instances of model.BodyWeight, model.Pulse, etc. The result will be stored in the data property of an instance of one the classes that extend model.DataPoint. The purpose of this encoding is to allow the various types of readings to be stored in a single SQL table, rather than requiring a table for each type of reading
- Parameters
obj (Any) – the object to be converted to JSON format
- default(obj: Any)
Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
- biometrics_tracker.model.json_handler.biometrics_object_hook(obj_dict: dict)
A custom object hook function to handle the decoding of JSON representations of model.BodyWeight, model.Pulse, etc. instances
- Parameters
obj_dict (dict[str, str]) – a dict containing JSON names and values
- Returns
an instance of the appropriate class (e.g. biometrics_tracker.model.BodyWeight, model.Pulse)
- Return type
biometrics_tracker.model.datapoints.dp_type_union