-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move dataset reporting out of HDF writer into DatasetReportingPart
- Loading branch information
Showing
4 changed files
with
109 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from collections import OrderedDict, namedtuple | ||
|
||
from malcolm.core import Part, Table | ||
from malcolm.core.vmetas import StringArrayMeta, ChoiceArrayMeta, TableMeta | ||
from malcolm.controllers.runnablecontroller import RunnableController | ||
|
||
# Make a table for the dataset info we produce | ||
columns = OrderedDict() | ||
columns["name"] = StringArrayMeta("Dataset name") | ||
columns["filename"] = StringArrayMeta("Filename of HDF file") | ||
columns["type"] = ChoiceArrayMeta("Type of dataset", ["primary", "additional"]) | ||
columns["path"] = StringArrayMeta("Dataset path within HDF file") | ||
columns["uniqueid"] = StringArrayMeta("UniqueID array path within HDF file") | ||
dataset_table_meta = TableMeta("Datsets produced in HDF file", columns=columns) | ||
|
||
# Produced by plugins in part_info | ||
DatasetProducedInfo = namedtuple("DatasetProducedInfo", columns) | ||
|
||
|
||
class DatasetReportingPart(Part): | ||
# Created attributes | ||
datasets = None | ||
|
||
def create_attributes(self): | ||
for data in super(DatasetReportingPart, self).create_attributes(): | ||
yield data | ||
self.datasets = dataset_table_meta.make_attribute() | ||
yield "datasets", self.datasets, None | ||
|
||
@RunnableController.PostConfigure | ||
def update_datasets_table(self, _, part_info): | ||
# Update the dataset table | ||
datasets_table = Table(dataset_table_meta) | ||
for dataset_infos in part_info.values(): | ||
for dataset_info in dataset_infos: | ||
row = list(dataset_info) | ||
datasets_table.append(row) | ||
self.datasets.set_value(datasets_table) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import os | ||
import sys | ||
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..")) | ||
import setup_malcolm_paths | ||
|
||
import unittest | ||
from mock import MagicMock | ||
|
||
from malcolm.parts.ADCore.datasetreportingpart import DatasetReportingPart, \ | ||
DatasetProducedInfo | ||
|
||
|
||
class TestDatasetReportingPart(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.process = MagicMock() | ||
self.child = MagicMock() | ||
self.params = MagicMock() | ||
self.o = DatasetReportingPart(self.process, self.params) | ||
list(self.o.create_attributes()) | ||
|
||
def test_init(self): | ||
self.assertEqual(self.o.datasets.meta.elements.endpoints, | ||
["name", "filename", "type", "path", "uniqueid"]) | ||
|
||
def test_post_configure(self): | ||
task = MagicMock() | ||
part_info = dict( | ||
HDF=[ | ||
DatasetProducedInfo( | ||
"det", "fn1", "primary", "/p/det", "/p/uid"), | ||
DatasetProducedInfo( | ||
"stat", "fn1", "additional", "/p/s1", "/p/uid"), | ||
DatasetProducedInfo( | ||
"stat", "fn1", "additional", "/p/s2", "/p/uid"), | ||
] | ||
) | ||
self.o.update_datasets_table(task, part_info) | ||
v = self.o.datasets.value | ||
self.assertEqual(v.name, ["det", "stat", "stat"]) | ||
self.assertEqual(v.filename, ["fn1", "fn1", "fn1"]) | ||
self.assertEqual(v.type, ["primary", "additional", "additional"]) | ||
self.assertEqual(v.path, ["/p/det", "/p/s1", "/p/s2"]) | ||
self.assertEqual(v.uniqueid, ["/p/uid", "/p/uid", "/p/uid"]) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main(verbosity=2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters