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

Create DS subcontroller for fp dataset parameters #37

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 24 additions & 0 deletions src/odin_fastcs/odin_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,36 @@ class FrameProcessorAdapterController(OdinDataAdapterController):
class FrameProcessorPluginController(OdinAdapterController):
"""SubController for a plugin in a frameProcessor application."""

async def initialise(self):
if any("dataset" in p.path for p in self._parameters):

def __dataset_parameter(param: OdinParameter):
return "dataset" in param.path

dataset_parameters, self._parameters = partition(
self._parameters, __dataset_parameter
)
if dataset_parameters:
dataset_controller = FrameProcessorDatasetController(
self._connection, dataset_parameters, f"{self._api_prefix}"
)
self.register_sub_controller("DS", dataset_controller)
await dataset_controller.initialise()

return await super().initialise()

def _process_parameters(self):
for parameter in self._parameters:
# Remove plugin name included in controller base path
parameter.set_path(parameter.path[1:])


class FrameProcessorDatasetController(OdinAdapterController):
def _process_parameters(self):
for parameter in self._parameters:
parameter.set_path(parameter.uri[3:])


def get_all_sub_controllers(
controller: "OdinAdapterController",
) -> list["OdinAdapterController"]:
Expand Down
18 changes: 16 additions & 2 deletions tests/test_controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ async def test_fp_create_plugin_sub_controllers():
_path=["hdf", "frames_written"],
metadata={"type": "int"},
),
OdinParameter(
uri=["status", "hdf", "dataset", "compressed_size", "compression"],
_path=["hdf", "dataset", "compressed_size", "compression"],
metadata={"type": "str"},
),
]

fpc = FrameProcessorController(HTTPConnection("", 0), parameters, "api/0.1")
Expand All @@ -93,7 +98,8 @@ async def test_fp_create_plugin_sub_controllers():
metadata={"type": "str"},
)
]
match fpc.get_sub_controllers():
controllers = fpc.get_sub_controllers()
match controllers:
case {
"HDF": FrameProcessorPluginController(
_parameters=[
Expand All @@ -104,7 +110,15 @@ async def test_fp_create_plugin_sub_controllers():
]
)
}:
pass
sub_controllers = controllers["HDF"].get_sub_controllers()
assert "DS" in sub_controllers
assert sub_controllers["DS"]._parameters == [
OdinParameter(
uri=["status", "hdf", "dataset", "compressed_size", "compression"],
_path=["compressed_size", "compression"],
metadata={"type": "str"},
)
]
case _:
pytest.fail("Sub controllers not as expected")

Expand Down
Loading