Skip to content
Snippets Groups Projects
Commit cfb4cfd4 authored by Stefano Borini's avatar Stefano Borini
Browse files

defined input slot maps and its input output as part of the model

parent f3900735
No related branches found
No related tags found
1 merge request!69Introduce slots and resolution of named variables
from traits.api import HasStrictTraits, Enum, String
class InputSlotMap(HasStrictTraits):
"""Class that specifies the origin of data for the slots of a data source.
"""
#: If MCO, the source is the MCO parameter with name specified at
#: value_name. If Fixed, the value specified in "value" will be used
#: instead.
source = Enum('MCO', 'Fixed')
name = String()
value = String()
from traits.api import ABCHasStrictTraits, Instance from traits.api import ABCHasStrictTraits, Instance, List, String
from force_bdss.core.input_slot_map import InputSlotMap
from .i_data_source_bundle import IDataSourceBundle from .i_data_source_bundle import IDataSourceBundle
...@@ -15,6 +16,21 @@ class BaseDataSourceModel(ABCHasStrictTraits): ...@@ -15,6 +16,21 @@ class BaseDataSourceModel(ABCHasStrictTraits):
#: retrieve it as the originating factory. #: retrieve it as the originating factory.
bundle = Instance(IDataSourceBundle, visible=False, transient=True) bundle = Instance(IDataSourceBundle, visible=False, transient=True)
#: Specifies binding between input slots and source for that value.
#: Each InputSlotMap instance specifies this information for each of the
#: slots.
input_slot_maps = List(Instance(InputSlotMap))
#: Allows to assign names to the output slots, so that they can be
#: referenced somewhere else (e.g. the KPICalculators).
output_slot_names = List(String())
def __init__(self, bundle, *args, **kwargs): def __init__(self, bundle, *args, **kwargs):
self.bundle = bundle self.bundle = bundle
super(BaseDataSourceModel, self).__init__(*args, **kwargs) super(BaseDataSourceModel, self).__init__(*args, **kwargs)
def __getstate__(self):
state = super(BaseDataSourceModel, self).__getstate__()
state["input_slot_maps"] = [
x.__getstate__() for x in self.input_slot_maps
]
...@@ -3,6 +3,7 @@ import logging ...@@ -3,6 +3,7 @@ import logging
from traits.api import HasStrictTraits, Instance from traits.api import HasStrictTraits, Instance
from force_bdss.core.input_slot_map import InputSlotMap
from ..bundle_registry_plugin import BundleRegistryPlugin from ..bundle_registry_plugin import BundleRegistryPlugin
from ..workspecs.workflow import Workflow from ..workspecs.workflow import Workflow
...@@ -145,7 +146,11 @@ class WorkflowReader(HasStrictTraits): ...@@ -145,7 +146,11 @@ class WorkflowReader(HasStrictTraits):
for ds_entry in wf_data["data_sources"]: for ds_entry in wf_data["data_sources"]:
ds_id = ds_entry["id"] ds_id = ds_entry["id"]
ds_bundle = registry.data_source_bundle_by_id(ds_id) ds_bundle = registry.data_source_bundle_by_id(ds_id)
data_sources.append(ds_bundle.create_model(ds_entry["model_data"])) model_data = ds_entry["model_data"]
model_data["input_slot_maps"] = self._extract_input_slot_maps(
model_data["input_slot_maps"]
)
data_sources.append(ds_bundle.create_model(model_data))
return data_sources return data_sources
...@@ -169,9 +174,14 @@ class WorkflowReader(HasStrictTraits): ...@@ -169,9 +174,14 @@ class WorkflowReader(HasStrictTraits):
for kpic_entry in wf_data["kpi_calculators"]: for kpic_entry in wf_data["kpi_calculators"]:
kpic_id = kpic_entry["id"] kpic_id = kpic_entry["id"]
kpic_bundle = registry.kpi_calculator_bundle_by_id(kpic_id) kpic_bundle = registry.kpi_calculator_bundle_by_id(kpic_id)
model_data = kpic_entry["model_data"]
model_data["input_slot_maps"] = self._extract_input_slot_maps(
model_data["input_slot_maps"]
)
kpi_calculators.append( kpi_calculators.append(
kpic_bundle.create_model(kpic_entry["model_data"])) kpic_bundle.create_model(model_data)
)
return kpi_calculators return kpi_calculators
...@@ -198,3 +208,6 @@ class WorkflowReader(HasStrictTraits): ...@@ -198,3 +208,6 @@ class WorkflowReader(HasStrictTraits):
parameters.append(model) parameters.append(model)
return parameters return parameters
def _extract_input_slot_maps(self, maps_data):
return [InputSlotMap(**d) for d in maps_data]
from traits.api import ABCHasStrictTraits, Instance from traits.api import ABCHasStrictTraits, Instance, List, String
from ..core.input_slot_map import InputSlotMap
from .i_kpi_calculator_bundle import IKPICalculatorBundle from .i_kpi_calculator_bundle import IKPICalculatorBundle
...@@ -15,6 +16,21 @@ class BaseKPICalculatorModel(ABCHasStrictTraits): ...@@ -15,6 +16,21 @@ class BaseKPICalculatorModel(ABCHasStrictTraits):
#: retrieve it as the originating factory. #: retrieve it as the originating factory.
bundle = Instance(IKPICalculatorBundle, visible=False, transient=True) bundle = Instance(IKPICalculatorBundle, visible=False, transient=True)
#: Specifies binding between input slots and source for that value.
#: Each InputSlotMap instance specifies this information for each of the
#: slots.
input_slot_maps = List(Instance(InputSlotMap))
#: Allows to assign names to the output slots, so that they can be
#: referenced somewhere else (e.g. the KPICalculators).
output_slot_names = List(String())
def __init__(self, bundle, *args, **kwargs): def __init__(self, bundle, *args, **kwargs):
self.bundle = bundle self.bundle = bundle
super(BaseKPICalculatorModel, self).__init__(*args, **kwargs) super(BaseKPICalculatorModel, self).__init__(*args, **kwargs)
def __getstate__(self):
state = super(BaseKPICalculatorModel, self).__getstate__()
state["input_slot_maps"] = [
x.__getstate__() for x in self.input_slot_maps
]
...@@ -23,7 +23,12 @@ ...@@ -23,7 +23,12 @@
"filename": "foo.csv", "filename": "foo.csv",
"row": 3, "row": 3,
"column": 5, "column": 5,
"cuba_type": "PRESSURE" "cuba_type": "PRESSURE",
"input_slot_maps": [
],
"output_slot_names": [
"p1"
]
} }
}, },
{ {
...@@ -32,7 +37,12 @@ ...@@ -32,7 +37,12 @@
"filename": "foo.csv", "filename": "foo.csv",
"row": 3, "row": 3,
"column": 5, "column": 5,
"cuba_type": "PRESSURE" "cuba_type": "PRESSURE",
"input_slot_maps": [
],
"output_slot_names": [
"p2"
]
} }
} }
], ],
...@@ -41,7 +51,18 @@ ...@@ -41,7 +51,18 @@
"id": "force.bdss.enthought.bundle.kpi_adder", "id": "force.bdss.enthought.bundle.kpi_adder",
"model_data": { "model_data": {
"cuba_type_in": "PRESSURE", "cuba_type_in": "PRESSURE",
"cuba_type_out": "TOTAL_PRESSURE" "cuba_type_out": "TOTAL_PRESSURE",
"input_slot_maps": [
{
"name": "p1"
},
{
"name": "p2"
}
],
"output_slot_names": [
"ptot"
]
} }
} }
] ]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment