caret_analyze.common.util module

class caret_analyze.common.util.Util

Bases: object

static ext(path: str) str

Get extension from path.

Parameters

pathstr

path name to get extension.

Returns

str

extension.

Note

This function is duplicated. see: get_ext in Util.

static filter_items(f: Callable[[Any], bool], x: Iterable[Any] | None) list[Any]

Filter iterable.

Parameters

fCallable[[Any], bool]

Filtering condition. Items that return True remain.

xIterable[Any] | None

Filtering target.

Returns

list[Any]

Filtered list.

static find_one(condition: Callable[[Any], bool], items: Iterable[Any] | None) Any

Get a single item that matches the condition.

Parameters

conditionCallable[[Any], bool]

condition

itemsIterable[Any] | None

Items to be searched.

Returns

Any

condition matched single item.

Raises

ItemNotFoundError

Failed to find an item that matches the condition.

MultipleItemFoundError

Failed to identify an item that matches the condition.

static find_similar_one(target_name: str, items: ~collections.abc.Collection[~typing.Any], key: ~collections.abc.Callable[[~typing.Any], str] = <function Util.<lambda>>, th: float = 0.6) Any

Get a single item that matches the condition.

Parameters

target_name: str

target_name

items: Collection[Any]

Items to be searched.

key: Callable[[Any], str]

key

th: float

Similarity judgment threshold. A candidate is mentioned only if it is higher than the threshold.

Returns

Any

condition matched single item.

Raises

ItemNotFoundError

Failed to find an item that matches the condition.

static find_similar_one_multi_keys(target_names: dict[str, str | int], items: ~collections.abc.Collection[~typing.Any], keys: ~collections.abc.Callable[[~typing.Any], dict[str, str | int]] = <function Util.<lambda>>, th: float = 0.6) Any

Get a single item that matches the multi conditions.

Parameters

target_names: dict[str, str | int]

target_names

items: Collection[Any]

Items to be searched.

keys: Callable[[Any], dict[str, str | int]]

key

th: float

Similarity judgment threshold. A candidate is mentioned only if it is higher than the threshold.

Returns

Any

conditions matched single item.

Raises

ItemNotFoundError

Failed to find an item that matches the conditions.

static flatten(x: Iterable[Iterable[Any]]) list[Any]

Expand double nested Iterable to List.

Parameters

xIterable[Iterable[Any]]

Target to flatten.

Returns

list[Any]

Flattened list.

static get_ext(path: str) str

Get extension from path.

Parameters

pathstr

path name to get extension.

Returns

str

extension.

Note

This function is duplicated. see: ext in Util.

static ns_to_ms(x: float) float

Convert nanosecond to millisecond.

Parameters

xfloat

time in nano-second.

Returns

float

time in millisecond.

static num_digit(i: int) int

Get number of digits in decimal.

Parameters

iint

number.

Returns

int

digits.

static to_ns_and_name(nodename: str) tuple[str, str]

Convert fully qualified node name.

Parameters

nodenamestr

fully qualified node name.

Returns

tuple[str, str]

name space, node name.