prl.utils package

Submodules

prl.utils.loggers module

class Logger[source]

Bases: object

Class for logging scalar values to limited queues. Logged data send to each client is tracked by the Logger, so each client can ask for unseen data and recieve it.

add(key, value)[source]

Add a value to queue assigned to key value.

Parameters:
  • key (str) – logged value name
  • value (Number) – logged number
flush(consumer_id)[source]

Method used by clients to recieve only new unseed data from logger.

Parameters:consumer_id (int) – value returned by register method.
Return type:(typing.Dict[str, typing.List], typing.Dict[str, range], typing.Dict[str, typing.List])
Returns:dict with new data.
get_data()[source]
Return type:Dict[str, deque]
Returns:all logged data.
register()[source]

Registers client in order to receive data from Logger object.

Return type:int
Returns:client ID used to identify client while requesting for a new data.
save(path)[source]

Saves data to file.

Parameters:path (str) – path to the file.
class TimeLogger[source]

Bases: prl.utils.loggers.Logger

Storage for measurements of function and methods exectuion time. Used by timeit function/decorator. Can be used to print summary of a time profiling or save all data to generate a plot how execution times are changing during the program execution.

limited_deque()[source]

Auxiliary function for Logger class.

Returns: Deque with maximum length set to DEQUE_MAX_LEN

prl.utils.misc module

class colors[source]

Bases: object

Color codes for unocode strings. Used for output string formatting.

BLUE = '\x1b[94m'
BOLD = '\x1b[1m'
END_FORMAT = '\x1b[0m'
GREEN = '\x1b[92m'
RED = '\x1b[91m'
UNDERLINE = '\x1b[4m'
YELLOW = '\x1b[93m'

prl.utils.utils module

timeit(func, profiled_function_name=None)[source]

Decorator for profiling execution time for the functions and methods. To measure time of a method or function you have to put @timeit in line nefore function, or wrap a function in the code:

@timeit def func(a, b, c=”1”):

pass

or in the code:

result = timeit(func, profiled_function_name=”Profiled function func”)(5,5)

To print results of measurment you have to print time_logger object from this package at the end of the program execution. When the name of the function can be ambiguous in the profiler data use profiled_function_name parameter.

Parameters:
  • func – function, which execution time we wan to measure
  • profiled_function_name – user defined name for the wrapped function.
Returns:

wrapped function

Module contents