caret_analyze.common package

Submodules

Module contents

Common package.

This package defines common, generic functions and classes used by other packages. Common functions should be placed under the Util class.

Note: Consider using ValueObject to avoid excessive size of the Util class.

class caret_analyze.common.ClockConverter(a: float, b: float)

Bases: object

Class for time conversion. Converts a time given in linear form (y=ax+b) to another time.

TODO(hsgwa): Migrate into record.

convert(time: float) float

Convert input time.

Parameters

timefloat

Time to convert.

Returns

float

Time after conversion. Conversion are done with y=ax+b.

static create_from_series(times_from: Sequence[float], times_to: Sequence[float]) ClockConverter

Construct an instance from time series data.

Parameters

times_fromSequence[float]

Time before conversion.

times_toSequence[float]

Time after conversion.

Returns

ClockConverter

converter instance.

Raises

InvalidArgumentError

Occurs when calculation failed by the least-squares method.

class caret_analyze.common.Progress

Bases: object

Class that manages the progress bar.

Set Progress.enable = True if to display progress bar.

enable = False
classmethod tqdm(it, *args) Iterable[Any]

Progress bar for python iterators.

Parameters

it_type_

iterator

Returns

Iterable[Any]

iterator. progress bar is enabled if Progress.enable == True, disabled otherwise.

class caret_analyze.common.Singleton(*args, **kwargs)

Bases: object

Singleton class.

Inherited classes become singleton.

Note:

Basically, implementation should avoid the use of Singleton.

class caret_analyze.common.Summarizable

Bases: object

Abstract base class that have summary property.

abstract property summary: Summary

Get summary.

Returns

Summary

summary info.

class caret_analyze.common.Summary(dict=None, /, **kwargs)

Bases: UserDict

Summary about value objects and runtime data objects.

Note:

The class is used to get an overview of the instance without any effect to __eq__ and __hash__. Users can get an overview in dictionary form or check the overview in the standard output.

pprint()
class caret_analyze.common.UniqueList(init: Iterable[Any] | None = None)

Bases: UserList

An ordered list without duplicate values.

append(i: Any)

Append new data.

Parameters

iAny

Data to append. If there are duplicate values, only the first value is inserted.

as_list() list[Any]

Get data as Python list.

Returns

list[Any]

data

class caret_analyze.common.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.

caret_analyze.common.init_logger(cfg_path: str)
caret_analyze.common.type_check_decorator(func)