Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterables #7

Merged
merged 50 commits into from
Apr 5, 2023
Merged
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
78e9ab3
Removed unecessary platform specific decorations
luis-camero Mar 28, 2023
f4e0dee
Added base decorations config
luis-camero Mar 28, 2023
c0d1346
Removed PACS specific configs
luis-camero Mar 28, 2023
d9d1fad
Added get and set functions to ListConfig
luis-camero Mar 28, 2023
99698ec
Fixed assertion indenting
luis-camero Mar 28, 2023
e530093
Removed unused imports
luis-camero Mar 28, 2023
5d5b36c
Fixed assertion indenting
luis-camero Mar 28, 2023
5902e23
Updated A200 to iterable decorations
luis-camero Mar 28, 2023
e54062c
Updated J100 to iterable decorations
luis-camero Mar 28, 2023
9e1f353
Updated path to config in Platform
luis-camero Mar 28, 2023
240487b
Updated path to base decorations config
luis-camero Mar 28, 2023
f2b5984
Switched parser to new decorations config
luis-camero Mar 28, 2023
6ccddb5
Removed PACS Config testers
luis-camero Mar 29, 2023
3f88d69
Fixed lint errors in clearpath_config
luis-camero Mar 16, 2023
3012a17
Fixed lint errors in mounts
luis-camero Mar 16, 2023
5c6aaa3
Moved ListConfig
luis-camero Mar 30, 2023
5422062
Updated remove function
luis-camero Mar 30, 2023
05ad4ec
Removed mount pseudo namespace
luis-camero Mar 30, 2023
75772fa
Small lint fixes in common
luis-camero Mar 30, 2023
1dda483
Added get and set methods for individual mounts
luis-camero Mar 30, 2023
fdd47da
Split up mounts
luis-camero Mar 30, 2023
21b9305
Added uid checks to ListConfig
luis-camero Apr 3, 2023
feb651e
Removed mounting link and model
luis-camero Apr 3, 2023
d04cab7
Removed mounting link from fath and flir moutns
luis-camero Apr 3, 2023
d6d69ef
Added OrderedListConfig
luis-camero Apr 3, 2023
830b7e9
Added name from id to BaseMount
luis-camero Apr 3, 2023
fd346fe
Removed name as a default parameter
luis-camero Apr 3, 2023
9098936
Removed PACS from platform
luis-camero Apr 3, 2023
7e07db6
Moved ListConfig and all PACS from the Platform base
luis-camero Apr 3, 2023
580e2f1
Added mounts as individual ordered lists
luis-camero Apr 3, 2023
d965a62
Updated sample to new mount iterables
luis-camero Apr 4, 2023
6c0428b
Clear OrderedConfigList if empty list is set
luis-camero Apr 4, 2023
e8224e8
BaseMount no longer requires a name, default to index
luis-camero Apr 4, 2023
d11336d
Removed 'pacs_' prefix from brackets and risers
luis-camero Apr 4, 2023
dd1141a
Completely disabled all PACS testing
luis-camero Apr 4, 2023
bd9f6ef
Removed name as required argument
luis-camero Apr 4, 2023
016d294
Upgraded parser to match new mounts
luis-camero Apr 4, 2023
03594b9
Fixed key error print statement
luis-camero Apr 4, 2023
1f3f85f
Removed and
luis-camero Apr 4, 2023
729ea1f
Updated Husky sampl
luis-camero Apr 4, 2023
a2e128f
Added __init__ to mounts
luis-camero Apr 4, 2023
7f8cf03
Added BaseDecoration; by default disabled
luis-camero Apr 4, 2023
b3c07c4
Fixed top plate in parser
luis-camero Apr 4, 2023
ec952d2
Set decorations to enabled if not specified but exist
luis-camero Apr 4, 2023
a42ed01
Added method to retrieve all mounts
luis-camero Apr 4, 2023
d3bb6bc
Added Decoration.NEW class
luis-camero Apr 4, 2023
31a75d7
Added method to retrieve all decorations
luis-camero Apr 4, 2023
de1600e
Added get_enabled
luis-camero Apr 4, 2023
f297ffc
Updated A200 sample
luis-camero Apr 4, 2023
2fdc66b
Removed height from Husky sample
luis-camero Apr 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added OrderedListConfig
luis-camero committed Apr 3, 2023

Verified

This commit was signed with the committer’s verified signature.
mifi Mikael Finstad
commit d6d69ef642404c006af77d0705afbd057663fd5b
120 changes: 120 additions & 0 deletions clearpath_config/common.py
Original file line number Diff line number Diff line change
@@ -427,3 +427,123 @@ def uid_level(T) -> int:
@staticmethod
def uid_level_row(T) -> tuple:
return (T.get_level(), T.get_row())


# OrderedListConfig
# - uid is an integer
# - index will be enforced to match uid
# - obj_to_idx
# - idx_to_obj
class OrderedListConfig(Generic[T]):

def __init__(
self,
# Unique identifier to index
obj_to_idx: Callable,
idx_to_obj: Callable
) -> None:
self.__list: List[T] = []
self.__obj_to_idx: Callable = obj_to_idx
self.__idx_to_obj: Callable = idx_to_obj

def find(
self,
obj: T | int
) -> int:
if isinstance(obj, self.__orig_class__.__args__[0]):
idx = self.__obj_to_idx(obj)
elif isinstance(obj, int):
idx = obj
else:
raise AssertionError(
"Object must of type %s or %s" % (
self.__orig_class__.__args__[0], int
)
)
if idx < len(self.__list):
return idx
else:
return None

def update(self):
for idx, obj in enumerate(self.__list):
if self.__obj_to_idx(obj) != idx:
self.__list[idx] = self.__idx_to_obj(obj, idx)

def add(
self,
obj: T
) -> None:
assert isinstance(obj, self.__orig_class__.__args__[0]), (
"Object must be of type %s" % T
)
self.__list.append(obj)
self.update()

def replace(
self,
obj: T,
) -> None:
idx = self.find(obj)
assert idx is not None, (
"Object not found. Cannot be replaced"
)
self.__list[idx] = obj
self.update()

def remove(
self,
obj: T | int
) -> None:
idx = self.find(obj)
if idx is not None:
self.__list.remove(self.__list[idx])
self.update()

def get(
self,
obj: T | int,
) -> T:
idx = self.find(obj)
return None if idx is None else self.__list[idx]

def get_all(
self
) -> List[T]:
return self.__list

def set(
self,
obj: T
) -> None:
if self.find(obj) is None:
self.add(obj)
else:
self.replace(obj)

def set_all(
self,
_list: List[T],
) -> None:
# Copy and Clear
tmp_list = deepcopy(self.__list)
self.__list.clear()
# Add One-by-One
try:
for obj in _list:
self.add(obj)
# Restore Save if Failure
except AssertionError:
self.__list = tmp_list

# Name as Unique ID to Index
@staticmethod
def name_obj_to_idx(obj: T):
name = obj.get_name()
str_idx = name.split("_")[-1]
return int(str_idx)

@staticmethod
def name_idx_to_obj(obj: T, idx: int):
obj.set_name(obj.get_name_from_idx(idx))
return obj