rhyton.utils

Module for general utily functions.

class Format[source]

Bases: object

Class for formatting keys and values to meet sql-standards

static formatNumber(number, key, unitSuffix)[source]

Formats a number.

Parameters

number (float) – The number to format.

Returns

The formatted number.

Return type

float

static key(key)[source]

Sanitize given key to meet rhyton standards.

Parameters

key (str) – The key to clean.

Returns

The sanitized key.

Return type

str

static value(value)[source]

Sanitize given value to meet rhyton standards.

Parameters

value (str) – The value to clean.

Returns

The sanitized value.

Return type

str

detectType(value)[source]

Tries to convert a given string to an integer, number or boolean. If no conversion is possible, the original string is returned.

Parameters

value (str) – The string to convert.

displayKey(key, rmPrefix=None)[source]

Formats an SQL-style key (‘snake_case’) for display. Optionally removes a prefix.

Example:

displayKey("xyz_some_area", prefix="xyz_")
>>> "Some Area"
Parameters
  • key (str) – The text to format.

  • rmPrefix (str, optional) – A prefix to remove. Defaults to None.

Returns

_description_

Return type

_type_

groupGuidsBy(data, keys)[source]

Re-organizes a list of dictionaies by given key. All dicts in the list that share the same values for given keys will be merged into one dict. All the “guid”s of the source dicts get stored as a list under the “guid” key in the merged dict and the source dicts are removed from the list. All keys other than the input keys will be removed in the process to prevent ambiguity.

Parameters
  • data (dict) – The Dictionary to re-organize.

  • keys (list[str]) – The list of keys to group by.

removePrefix(string, prefix)[source]

Removes a prefix from a string. Python 2.7 substitute for ‘string.removeprefix(str)’

Parameters
  • string (str) – The text to remove the prefix from.

  • prefix (str) – The prefix to remove from the string.

Returns

The resulting string.

Return type

str

toList(data)[source]

Ensures that the input data is a list.

Parameters

data (mixed) – The object to check

Returns

The original object or the object wrapped in a list.

Return type

list