rhyton.utils¶
Module for general utily functions.
- class Format[source]¶
Bases:
objectClass for formatting keys and values to meet sql-standards
- static formatNumber(number, key)[source]¶
Formats a number.
- Parameters
number (float) – The number to format.
- Returns
The formatted number.
- Return type
float
- detectType(value)[source]¶
Tries to convert a given string to a number, boolean or string.
- 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.