pysmo.tools.utils
#
Pysmo's little helpers.
Functions:
-
average_datetimes
–Average a sequence of datetimes.
-
uuid_shortener
–Shorten a sequence of UUIDs to their shortest unique representation.
average_datetimes
#
Average a sequence of datetimes.
Parameters:
Returns:
-
datetime
–Datetime representing average of all datetimes.
Raises:
-
ValueError
–If an empty sequence is provides as input.
Source code in pysmo/tools/utils.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
uuid_shortener
#
Shorten a sequence of UUIDs to their shortest unique representation.
Parameters:
-
uuids
(Sequence[UUID]
) –UUIDs to shorten.
-
min_length
(int
, default:4
) –Minimum length of the shortened UUID strings.
Returns:
Raises:
-
ValueError
–If an empty sequence is provided as input.
-
ValueError
–If
min_length
is not between 1 and 36.
Examples:
>>> import uuid
>>> from pysmo.tools.utils import uuid_shortener
>>>
>>> uuids = [uuid.uuid4() for _ in range(100)]
>>> for k, v in sorted(uuid_shortener(uuids).items()):
... print(f"{k} -> {v}")
...
01d7 -> 01d74256-3860-4ab6-96a4-02f23ae8cc93
03c7 -> 03c72ba8-d605-4770-8a63-f881ffd0f9d5
080a -> 080aadfb-e7c9-4b26-9141-25c63a9bedd4
0e51 -> 0e51f30d-c6a7-4e39-84b0-32ccd7c524a5
...
>>>
Source code in pysmo/tools/utils.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|