util#

class predict_backend.utils.util.ExtendedEnum(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)#

Bases: Enum

Extends Python’s generic enumeration

classmethod check_valid_enum(e)#
Return type:

bool

classmethod get_valid_enums()#
Return type:

list

classmethod validate(e, return_none=True)#
predict_backend.utils.util.fig_to_img(fig, *args, **kwargs)#

Convert a Matplotlib figure to a PIL Image and return it. Additional arguments are passed to the figure’s savefig function.

Parameters:

fig (Figure) – The figure to convert into a PIL Image.

Return type:

Image

Returns:

The saved PIL Image of fig.

predict_backend.utils.util.generate_id(time_precision=100.0)#

Generates a unique id. We want a time sorted UUID to improve DB performance since this column is heavily indexed

Returns:

str, a unique id

predict_backend.utils.util.get_ends(s)#

Assuming a format for categorical keys (e.g. Precipitation_Yes) get the data value part of the string.

Parameters:

s (str) – Column data point.

Return type:

str

Returns:

The data value excluding the categorical name.

predict_backend.utils.util.get_next_key(dictionary, target_key)#

Gets the next key from the target key in a dict

Parameters:
  • dictionary – dict, a dictionary of key, values

  • target_key – the target key to lookup

Returns:

the key after the target key, or None if not found

predict_backend.utils.util.get_package_from_obj(obj)#

Returns the base package of a module an object was defined in

Parameters:

obj – the Python object

Returns:

str, base package name

predict_backend.utils.util.get_previous_key(dictionary, target_key)#

Gets the previous key from the target key in a dict

Parameters:
  • dictionary – dict, a dictionary of key, values

  • target_key – the target key to lookup

Returns:

the key before the target key, or None if not found

predict_backend.utils.util.is_backend()#
predict_backend.utils.util.is_multiple(value, stepSize, min)#

Returns true if value is a multiple of step size Works for decimals with up to two decimal places Implicitly this function also checks that it is a multiple given the starting minimum value in this list

predict_backend.utils.util.quiet_error(error, quiet)#

Raise an error or return false if quiet is True

Return type:

bool

predict_backend.utils.util.read_timestamp(time, micro=False)#

Transforms a datetime string into a Python datetime object

Parameters:
  • time – a datetime string, format of “%Y-%m-%dT%H:%M:%S%z” or “%Y-%m-%dT%H:%M:%S.%f%z” for micro

  • micro – whether microseconds are included in the string

Returns:

A Python datetime object

predict_backend.utils.util.ssf_decode(created_in_ssf, obj)#

Decodes a Python object in a way compatible for SSF

Parameters:
  • created_in_ssf (bool) – Whether to apply SSF-compatible decoding

  • obj – The object to decode

Returns:

The decoded object

predict_backend.utils.util.ssf_encode(created_in_ssf, obj)#

Encodes a Python object in a way compatible for SSFs

Parameters:
  • created_in_ssf (bool) – Whether or not to apply SSF-compatible encoding

  • obj – The object to encode

Returns:

The encoded object

predict_backend.utils.util.timef(f)#

Times a provided function as a wrapper

Returns:

None

predict_backend.utils.util.timestamp(micro=False)#

Returns the current time in the form of a string, with or without microseconds

Parameters:

micro – Whether to return microseconds

Returns:

a str of the datetime in the format of “%Y-%m-%dT%H:%M:%S%z” or “%Y-%m-%dT%H:%M:%S.%f%z” for micro

predict_backend.utils.util.validate_flow_metadata(meta)#

Ensure a dictionary inclues flow metadata. Logs a warning if necessary keys aren’t included.

Parameters:

meta (dict) – Flow metadata.

Returns:

None