Common
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.
ClockConverter
#
Class for time conversion. Converts a time given in linear form (y=ax+b) to another time.
TODO(hsgwa): Migrate into record.
__init__(a, b)
#
Construct an instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a |
float
|
Slope. |
required |
b |
float
|
Offset. |
required |
convert(time)
#
Convert input time.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time |
float
|
Time to convert. |
required |
Returns:
Type | Description |
---|---|
float
|
Time after conversion. Conversion are done with y=ax+b. |
create_from_series(times_from, times_to)
staticmethod
#
Construct an instance from time series data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
times_from |
Sequence[float]
|
Time before conversion. |
required |
times_to |
Sequence[float]
|
Time after conversion. |
required |
Returns:
Type | Description |
---|---|
ClockConverter
|
converter instance. |
Raises:
Type | Description |
---|---|
InvalidArgumentError
|
Occurs when calculation failed by the least-squares method. |
Progress
#
Class that manages the progress bar.
Set Progress.enable = True if to display progress bar.
tqdm(it, *args)
classmethod
#
Progress bar for python iterators.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
it |
_type_
|
iterator |
required |
Returns:
Type | Description |
---|---|
Iterable[Any]
|
iterator. progress bar is enabled if Progress.enable == True, disabled otherwise. |
Singleton
#
Bases: object
Singleton class.
Inherited classes become singleton.
Note:
Basically, implementation should avoid the use of Singleton.
Summarizable
#
Summary
#
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.
UniqueList
#
Bases: UserList
An ordered list without duplicate values.
__add__(other)
#
Add other data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
Iterable[Any]
|
Data to add. |
required |
Returns:
Type | Description |
---|---|
UniqueList
|
Updated list with added data. |
__iadd__(other)
#
Add other data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
Iterable[Any]
|
Data to add. |
required |
Returns:
Type | Description |
---|---|
UniqueList
|
Updated list with added data. |
__init__(init=None)
#
Construct an instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
init |
Iterable[Any] | None
|
initial value, by default None. If there are duplicate values, only the first value is inserted. |
None
|
append(i)
#
Append new data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
i |
Any
|
Data to append. If there are duplicate values, only the first value is inserted. |
required |
as_list()
#
Get data as Python list.
Returns:
Type | Description |
---|---|
list[Any]
|
data |
Util
#
ext(path)
staticmethod
#
Get extension from path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
path name to get extension. |
required |
Returns:
Type | Description |
---|---|
str
|
extension. |
Note
This function is duplicated. see: get_ext in Util.
filter_items(f, x)
staticmethod
#
Filter iterable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f |
Callable[[Any], bool]
|
Filtering condition. Items that return True remain. |
required |
x |
Iterable[Any] | None
|
Filtering target. |
required |
Returns:
Type | Description |
---|---|
list[Any]
|
Filtered list. |
find_one(condition, items)
staticmethod
#
Get a single item that matches the condition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
condition |
Callable[[Any], bool]
|
condition |
required |
items |
Iterable[Any] | None
|
Items to be searched. |
required |
Returns:
Type | Description |
---|---|
Any
|
condition matched single item. |
Raises:
Type | Description |
---|---|
ItemNotFoundError
|
Failed to find an item that matches the condition. |
MultipleItemFoundError
|
Failed to identify an item that matches the condition. |
find_similar_one(target_name, items, key=lambda x: x, th=0.6)
staticmethod
#
Get a single item that matches the condition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_name |
str
|
target_name |
required |
items |
Collection[Any]
|
Items to be searched. |
required |
key |
Callable[[Any], str]
|
key |
lambda x: x
|
th |
float
|
Similarity judgment threshold. A candidate is mentioned only if it is higher than the threshold. |
0.6
|
Returns:
Type | Description |
---|---|
Any
|
condition matched single item. |
Raises:
Type | Description |
---|---|
ItemNotFoundError
|
Failed to find an item that matches the condition. |
find_similar_one_multi_keys(target_names, items, keys=lambda x: x, th=0.6)
staticmethod
#
Get a single item that matches the multi conditions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_names |
dict[str, str | int]
|
target_names |
required |
items |
Collection[Any]
|
Items to be searched. |
required |
keys |
Callable[[Any], dict[str, str | int]]
|
key |
lambda x: x
|
th |
float
|
Similarity judgment threshold. A candidate is mentioned only if it is higher than the threshold. |
0.6
|
Returns:
Type | Description |
---|---|
Any
|
conditions matched single item. |
Raises:
Type | Description |
---|---|
ItemNotFoundError
|
Failed to find an item that matches the conditions. |
flatten(x)
staticmethod
#
Expand double nested Iterable to List.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Iterable[Iterable[Any]]
|
Target to flatten. |
required |
Returns:
Type | Description |
---|---|
list[Any]
|
Flattened list. |
get_ext(path)
staticmethod
#
Get extension from path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
path name to get extension. |
required |
Returns:
Type | Description |
---|---|
str
|
extension. |
Note
This function is duplicated. see: ext in Util.
ns_to_ms(x)
staticmethod
#
Convert nanosecond to millisecond.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
float
|
time in nano-second. |
required |
Returns:
Type | Description |
---|---|
float
|
time in millisecond. |
num_digit(i)
staticmethod
#
Get number of digits in decimal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
i |
int
|
number. |
required |
Returns:
Type | Description |
---|---|
int
|
digits. |
to_ns_and_name(nodename)
staticmethod
#
Convert fully qualified node name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nodename |
str
|
fully qualified node name. |
required |
Returns:
Type | Description |
---|---|
tuple[str, str]
|
name space, node name. |