plafosim.util module

class plafosim.util.FakeLog[source]

Bases: object

A fake logger, hide LOG behind this and be happy.

debug(*arg, **kwd)[source]
error(*arg, **kwd)[source]
fatal(*arg, **kwd)[source]
info(*arg, **kwd)[source]
trace(*arg, **kwd)[source]
warn(*arg, **kwd)[source]
warning(*arg, **kwd)[source]
plafosim.util.acceleration2speed(acceleration: float, time_interval: float = 1.0) float[source]

Convert an acceleration to a driving speed for a given time interval.

Parameters:
  • acceleration (float) – The acceleration to be converted

  • time_interval (float, optional) – The time to consider

Returns:

float

Return type:

The converted value

plafosim.util.add_logging_level(level_name: str, level_num: int, method_name: str | None = None)[source]

Comprehensively adds a new logging level to the logging module and the currently configured logging class.

level_name becomes an attribute of the logging module with the value level_num. method_name becomes a convenience method for both logging itself and the class returned by logging.getLoggerClass() (usually just logging.Logger). If method_name is not specified, level_name.lower() is used.

To avoid accidental clobberings of existing attributes, this method will raise an AttributeError if the level name is already an attribute of the logging module or if the method name is already present.

Taken from https://stackoverflow.com/a/35804945.

Parameters:
  • level_name (str) – The name of the level to add

  • level_num (int) – The number of the level to add

  • method_name (str) – The name of the method for the level to add

plafosim.util.assert_index_equal(one, two) bool[source]

Ensure the indices of two Sequences/DataFrames are equal.

Parameters:
  • one (pandas.Sequence / pandas.DataFrame) – The first object for the comparison

  • two (pandas.Sequence / pandas.DataFrame) – The second object for the comparsion

Returns:

bool

Return type:

Whether the two indices are equal

plafosim.util.distance2speed(distance: float, time_interval: float = 1.0) float[source]

Convert a driven distance to a driving speed for a given time interval.

Parameters:
  • distance (float) – The distance to be converted

  • time_interval (float, optional) – The time to consider

Returns:

float

Return type:

The converted value

plafosim.util.find_resource(path: str) str[source]

Find the resouces under relpath locally or as a packaged resource.

Parameters:

path (str) – The path to search for the ressource

Returns:

str

Return type:

The path of the resource

plafosim.util.hex2rgb(c_hex: str) tuple[source]

Convert a color in hex values to a color in RGB values.

Parameters:

c_hex (str) – The color in hex values

Returns:

tuple(int, int, int)

Return type:

The color in RGB values

plafosim.util.rgb2hex(c_rgb: tuple) str[source]

Convert a color in RGB values to a color in hex values.

Parameters:

c_rgb (tuple(int, int, int)) – The color in RGB values

Returns:

str

Return type:

The color in hex values

plafosim.util.round_to_next_base(value: float, base: float) float[source]

Round a value to the next base value.

Parameters:
  • value (float) – The value to round

  • base (float) – The base value to round to

Returns:

float

Return type:

The rounded value

plafosim.util.speed2acceleration(speed_from: float, speed_to: float, time_interval: float = 1.0) float[source]

Convert a speed range to an acceleration within a given time interval.

Parameters:
  • speed_from (float) – The initial speed

  • speed_to (float) – The target speed

  • time_interval (float, optional) – The time to consider

Returns:

float

Return type:

The converted value

plafosim.util.speed2distance(speed: float, time_interval: float = 1.0) float[source]

Convert a driving speed to a distance driven within a given time interval.

Parameters:
  • speed (float) – The speed to be converted

  • time_interval (float, optional) – The time to consider

Returns:

float

Return type:

The converted value