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

Merge pull request #71 from force-h2020/rename-bundle-to-factory

Rename bundle to factory
parents 26ee582a fd5bdee0
No related branches found
No related tags found
No related merge requests found
Showing
with 130 additions and 102 deletions
......@@ -28,10 +28,10 @@ class WorkflowWriter(HasStrictTraits):
workflow_data = {
"mco": self._mco_data(workflow.mco),
"kpi_calculators": [
self._bundle_model_data(kpic)
self._model_data(kpic)
for kpic in workflow.kpi_calculators],
"data_sources": [
self._bundle_model_data(ds)
self._model_data(ds)
for ds in workflow.data_sources]
}
......@@ -43,7 +43,7 @@ class WorkflowWriter(HasStrictTraits):
if mco is None:
return None
data = self._bundle_model_data(mco)
data = self._model_data(mco)
parameters_data = []
for param in data["model_data"]["parameters"]:
......@@ -57,11 +57,11 @@ class WorkflowWriter(HasStrictTraits):
data["model_data"]["parameters"] = parameters_data
return data
def _bundle_model_data(self, bundle_model):
def _model_data(self, model):
"""
Extracts the data from a bundle model and returns its dictionary
Extracts the data from an external model and returns its dictionary
"""
return {
"id": bundle_model.bundle.id,
"model_data": bundle_model.__getstate__()
"id": model.factory.id,
"model_data": model.__getstate__()
}
......@@ -2,7 +2,7 @@ import abc
from traits.api import ABCHasStrictTraits, Instance
from .i_kpi_calculator_bundle import IKPICalculatorBundle
from .i_kpi_calculator_factory import IKPICalculatorFactory
class BaseKPICalculator(ABCHasStrictTraits):
......@@ -10,11 +10,11 @@ class BaseKPICalculator(ABCHasStrictTraits):
Inherit this class for your KPI calculator.
"""
#: A reference to the bundle
bundle = Instance(IKPICalculatorBundle)
#: A reference to the factory
factory = Instance(IKPICalculatorFactory)
def __init__(self, bundle, *args, **kwargs):
self.bundle = bundle
def __init__(self, factory, *args, **kwargs):
self.factory = factory
super(BaseKPICalculator, self).__init__(*args, **kwargs)
@abc.abstractmethod
......
......@@ -2,25 +2,25 @@ import abc
from envisage.plugin import Plugin
from traits.api import ABCHasStrictTraits, provides, String, Instance
from .i_kpi_calculator_bundle import IKPICalculatorBundle
from .i_kpi_calculator_factory import IKPICalculatorFactory
@provides(IKPICalculatorBundle)
class BaseKPICalculatorBundle(ABCHasStrictTraits):
"""Base class for the Key Performance Indicator calculator bundles.
Inherit from this class to create a bundle, and reimplement the abstract
@provides(IKPICalculatorFactory)
class BaseKPICalculatorFactory(ABCHasStrictTraits):
"""Base class for the Key Performance Indicator calculator factories.
Inherit from this class to create a factory, and reimplement the abstract
methods.
"""
# NOTE: any changes in this interface must be ported to
# IKPICalculatorBundle
# IKPICalculatorFactory
#: A unique ID generated with bundle_id() routine
#: A unique ID generated with factory_id() routine
id = String()
#: A UI friendly name for the bundle. Can contain spaces.
#: A UI friendly name for the factory. Can contain spaces.
name = String()
#: A reference to the plugin that holds this bundle.
#: A reference to the plugin that holds this factory.
plugin = Instance(Plugin)
def __init__(self, plugin, *args, **kwargs):
......@@ -29,10 +29,10 @@ class BaseKPICalculatorBundle(ABCHasStrictTraits):
Parameters
----------
plugin: Plugin
The plugin that holds this bundle.
The plugin that holds this factory.
"""
self.plugin = plugin
super(BaseKPICalculatorBundle, self).__init__(*args, **kwargs)
super(BaseKPICalculatorFactory, self).__init__(*args, **kwargs)
@abc.abstractmethod
def create_kpi_calculator(self):
......
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_factory import IKPICalculatorFactory
class BaseKPICalculatorModel(ABCHasStrictTraits):
"""Base class for the bundle specific KPI calculator models.
"""Base class for the factory specific KPI calculator models.
This model will also provide, through traits/traitsui magic the View
that will appear in the workflow manager UI.
In your bundle definition, your bundle-specific model must reimplement
In your factory definition, your factory-specific model must reimplement
this class.
"""
#: A reference to the creating bundle, so that we can
#: A reference to the creating factory, so that we can
#: retrieve it as the originating factory.
bundle = Instance(IKPICalculatorBundle, visible=False, transient=True)
factory = Instance(IKPICalculatorFactory, visible=False, transient=True)
#: Specifies binding between input slots and source for that value.
#: Each InputSlotMap instance specifies this information for each of the
......@@ -25,8 +25,8 @@ class BaseKPICalculatorModel(ABCHasStrictTraits):
#: referenced somewhere else (e.g. the KPICalculators).
output_slot_names = List(String())
def __init__(self, bundle, *args, **kwargs):
self.bundle = bundle
def __init__(self, factory, *args, **kwargs):
self.factory = factory
super(BaseKPICalculatorModel, self).__init__(*args, **kwargs)
def __getstate__(self):
......
......@@ -2,11 +2,11 @@ from traits.api import Interface, String, Instance
from envisage.plugin import Plugin
class IKPICalculatorBundle(Interface):
"""Envisage required interface for the BaseKPICalculatorBundle.
class IKPICalculatorFactory(Interface):
"""Envisage required interface for the BaseKPICalculatorFactory.
You should not need to use this directly.
Refer to the BaseKPICalculatorBundle for documentation.
Refer to the BaseKPICalculatorFactory for documentation.
"""
id = String()
......
......@@ -5,7 +5,7 @@ except ImportError:
from unittest import mock
from force_bdss.kpi.base_kpi_calculator import BaseKPICalculator
from force_bdss.kpi.i_kpi_calculator_bundle import IKPICalculatorBundle
from force_bdss.kpi.i_kpi_calculator_factory import IKPICalculatorFactory
class DummyKPICalculator(BaseKPICalculator):
......@@ -18,7 +18,7 @@ class DummyKPICalculator(BaseKPICalculator):
class TestBaseKPICalculator(unittest.TestCase):
def test_initialization(self):
bundle = mock.Mock(spec=IKPICalculatorBundle)
kpic = DummyKPICalculator(bundle)
factory = mock.Mock(spec=IKPICalculatorFactory)
kpic = DummyKPICalculator(factory)
self.assertEqual(kpic.bundle, bundle)
self.assertEqual(kpic.factory, factory)
......@@ -6,11 +6,11 @@ try:
except ImportError:
from unittest import mock
from force_bdss.kpi.base_kpi_calculator_bundle import \
BaseKPICalculatorBundle
from force_bdss.kpi.base_kpi_calculator_factory import \
BaseKPICalculatorFactory
class DummyKPICalculatorBundle(BaseKPICalculatorBundle):
class DummyKPICalculatorFactory(BaseKPICalculatorFactory):
id = "foo"
name = "bar"
......@@ -22,8 +22,8 @@ class DummyKPICalculatorBundle(BaseKPICalculatorBundle):
pass
class TestBaseKPICalculatorBundle(unittest.TestCase):
class TestBaseKPICalculatorFactory(unittest.TestCase):
def test_initialization(self):
bundle = DummyKPICalculatorBundle(mock.Mock(spec=Plugin))
self.assertEqual(bundle.id, 'foo')
self.assertEqual(bundle.name, 'bar')
factory = DummyKPICalculatorFactory(mock.Mock(spec=Plugin))
self.assertEqual(factory.id, 'foo')
self.assertEqual(factory.name, 'bar')
import unittest
from force_bdss.core.input_slot_map import InputSlotMap
from force_bdss.kpi.base_kpi_calculator_bundle import BaseKPICalculatorBundle
from force_bdss.kpi.base_kpi_calculator_factory import BaseKPICalculatorFactory
from force_bdss.kpi.base_kpi_calculator_model import BaseKPICalculatorModel
try:
......@@ -17,7 +17,7 @@ class DummyKPICalculatorModel(BaseKPICalculatorModel):
class TestBaseKPICalculatorModel(unittest.TestCase):
def test_getstate(self):
model = DummyKPICalculatorModel(
mock.Mock(spec=BaseKPICalculatorBundle))
mock.Mock(spec=BaseKPICalculatorFactory))
self.assertEqual(
model.__getstate__(),
{
......
......@@ -2,7 +2,7 @@ import abc
from traits.api import ABCHasStrictTraits, Instance
from .i_mco_bundle import IMCOBundle
from .i_mco_factory import IMCOFactory
class BaseMCO(ABCHasStrictTraits):
......@@ -10,18 +10,18 @@ class BaseMCO(ABCHasStrictTraits):
Inherit this class for your MCO implementation
"""
#: A reference to the bundle
bundle = Instance(IMCOBundle)
#: A reference to the factory
factory = Instance(IMCOFactory)
def __init__(self, bundle, *args, **kwargs):
def __init__(self, factory, *args, **kwargs):
"""Initializes the MCO.
Parameters
----------
bundle: BaseMCOBundle
The bundle this BaseMCO belongs to
factory: BaseMCOFactory
The factory this BaseMCO belongs to
"""
self.bundle = bundle
self.factory = factory
super(BaseMCO, self).__init__(*args, **kwargs)
@abc.abstractmethod
......
......@@ -2,7 +2,7 @@ import abc
from traits.api import ABCHasStrictTraits, Instance
from .i_mco_bundle import IMCOBundle
from .i_mco_factory import IMCOFactory
class BaseMCOCommunicator(ABCHasStrictTraits):
......@@ -16,11 +16,11 @@ class BaseMCOCommunicator(ABCHasStrictTraits):
that we interpret as KPIs. These KPIs are encoded in some form, which is
again specified by the MCO.
"""
#: A reference to the bundle
bundle = Instance(IMCOBundle)
#: A reference to the factory
factory = Instance(IMCOFactory)
def __init__(self, bundle):
self.bundle = bundle
def __init__(self, factory):
self.factory = factory
@abc.abstractmethod
def receive_from_mco(self, model):
......
......@@ -3,28 +3,28 @@ import abc
from traits.api import ABCHasStrictTraits, String, provides, Instance
from envisage.plugin import Plugin
from .i_mco_bundle import IMCOBundle
from .i_mco_factory import IMCOFactory
@provides(IMCOBundle)
class BaseMCOBundle(ABCHasStrictTraits):
"""Base class for the MultiCriteria Optimizer bundle.
@provides(IMCOFactory)
class BaseMCOFactory(ABCHasStrictTraits):
"""Base class for the MultiCriteria Optimizer factory.
"""
# NOTE: any changes to the interface of this class must be replicated
# in the IMultiCriteriaOptimizerBundle interface class.
# in the IMultiCriteriaOptimizerFactory interface class.
#: A unique ID produced with the bundle_id() routine.
#: A unique ID produced with the factory_id() routine.
id = String()
#: A user friendly name of the bundle. Spaces allowed.
#: A user friendly name of the factory. Spaces allowed.
name = String()
#: A reference to the Plugin that holds this bundle.
#: A reference to the Plugin that holds this factory.
plugin = Instance(Plugin)
def __init__(self, plugin, *args, **kwargs):
self.plugin = plugin
super(BaseMCOBundle, self).__init__(*args, **kwargs)
super(BaseMCOFactory, self).__init__(*args, **kwargs)
@abc.abstractmethod
def create_optimizer(self):
......
from traits.api import ABCHasStrictTraits, Instance, List
from .parameters.base_mco_parameter import BaseMCOParameter
from .i_mco_bundle import IMCOBundle
from .i_mco_factory import IMCOFactory
class BaseMCOModel(ABCHasStrictTraits):
"""Base class for the bundle specific MCO models.
"""Base class for the specific MCO models.
This model will also provide, through traits/traitsui magic the View
that will appear in the workflow manager UI.
In your bundle definition, your bundle-specific model must reimplement
this class.
In your definition, your specific model must reimplement this class.
"""
#: A reference to the creating bundle, so that we can
#: A reference to the creating factory, so that we can
#: retrieve it as the originating factory.
bundle = Instance(IMCOBundle,
visible=False,
transient=True)
factory = Instance(IMCOFactory,
visible=False,
transient=True)
# A list of the parameters for the MCO
parameters = List(BaseMCOParameter)
def __init__(self, bundle, *args, **kwargs):
self.bundle = bundle
def __init__(self, factory, *args, **kwargs):
self.factory = factory
super(BaseMCOModel, self).__init__(*args, **kwargs)
......@@ -2,11 +2,11 @@ from traits.api import Interface, String, Instance
from envisage.plugin import Plugin
class IMCOBundle(Interface):
"""Interface for the BaseMCOBundle.
class IMCOFactory(Interface):
"""Interface for the BaseMCOFactory.
You should not need it, as its main use is for envisage support.
Refer to BaseMCOBundle for documentation
Refer to BaseMCOFactory for documentation
"""
id = String()
......
from traits.api import HasStrictTraits, String, Type, Instance
from ..base_mco_bundle import BaseMCOBundle
from ..base_mco_factory import BaseMCOFactory
class BaseMCOParameterFactory(HasStrictTraits):
......@@ -12,8 +12,8 @@ class BaseMCOParameterFactory(HasStrictTraits):
the appropriate class of the parameter.
"""
#: A reference to the bundle this parameter factory lives in.
bundle = Instance(BaseMCOBundle)
#: A reference to the MCO factory this parameter factory lives in.
mco_factory = Instance(BaseMCOFactory)
#: A unique string identifying the parameter
id = String()
......@@ -27,8 +27,8 @@ class BaseMCOParameterFactory(HasStrictTraits):
# The model class to instantiate when create_model is called.
model_class = Type('BaseMCOParameter')
def __init__(self, bundle):
self.bundle = bundle
def __init__(self, mco_factory):
self.mco_factory = mco_factory
super(BaseMCOParameterFactory, self).__init__()
def create_model(self, data_values=None):
......
import unittest
from force_bdss.mco.base_mco_bundle import BaseMCOBundle
from force_bdss.mco.base_mco_factory import BaseMCOFactory
try:
import mock
......@@ -27,7 +27,7 @@ class DummyMCOParameterFactory(BaseMCOParameterFactory):
class TestBaseMCOParameterFactory(unittest.TestCase):
def test_initialization(self):
factory = DummyMCOParameterFactory(mock.Mock(spec=BaseMCOBundle))
factory = DummyMCOParameterFactory(mock.Mock(spec=BaseMCOFactory))
model = factory.create_model({"x": 42})
self.assertIsInstance(model, DummyMCOParameter)
self.assertEqual(model.x, 42)
......
import unittest
from force_bdss.mco.base_mco import BaseMCO
from force_bdss.mco.i_mco_bundle import IMCOBundle
from force_bdss.mco.i_mco_factory import IMCOFactory
try:
import mock
......@@ -16,7 +16,7 @@ class DummyMCO(BaseMCO):
class TestBaseMultiCriteriaOptimizer(unittest.TestCase):
def test_initialization(self):
bundle = mock.Mock(spec=IMCOBundle)
mco = DummyMCO(bundle)
factory = mock.Mock(spec=IMCOFactory)
mco = DummyMCO(factory)
self.assertEqual(mco.bundle, bundle)
self.assertEqual(mco.factory, factory)
import unittest
from force_bdss.mco.base_mco_communicator import BaseMCOCommunicator
from force_bdss.mco.i_mco_bundle import IMCOBundle
from force_bdss.mco.i_mco_factory import IMCOFactory
try:
import mock
......@@ -19,7 +19,7 @@ class DummyMCOCommunicator(BaseMCOCommunicator):
class TestBaseMCOCommunicator(unittest.TestCase):
def test_initialization(self):
bundle = mock.Mock(spec=IMCOBundle)
mcocomm = DummyMCOCommunicator(bundle)
factory = mock.Mock(spec=IMCOFactory)
mcocomm = DummyMCOCommunicator(factory)
self.assertEqual(mcocomm.bundle, bundle)
self.assertEqual(mcocomm.factory, factory)
......@@ -7,10 +7,10 @@ except ImportError:
from envisage.plugin import Plugin
from force_bdss.mco.base_mco_bundle import BaseMCOBundle
from force_bdss.mco.base_mco_factory import BaseMCOFactory
class DummyMCOBundle(BaseMCOBundle):
class DummyMCOFactory(BaseMCOFactory):
id = "foo"
name = "bar"
......@@ -28,8 +28,8 @@ class DummyMCOBundle(BaseMCOBundle):
return []
class TestBaseMCOBundle(unittest.TestCase):
class TestBaseMCOFactory(unittest.TestCase):
def test_initialization(self):
bundle = DummyMCOBundle(mock.Mock(spec=Plugin))
self.assertEqual(bundle.id, 'foo')
self.assertEqual(bundle.name, 'bar')
factory = DummyMCOFactory(mock.Mock(spec=Plugin))
self.assertEqual(factory.id, 'foo')
self.assertEqual(factory.name, 'bar')
......@@ -2,11 +2,11 @@
"version": "1",
"workflow": {
"mco": {
"id": "force.bdss.enthought.bundle.dummy_dakota",
"id": "force.bdss.enthought.factory.dummy_dakota",
"model_data": {
"parameters" : [
{
"id": "force.bdss.enthought.bundle.dummy_dakota.parameter.ranged",
"id": "force.bdss.enthought.factory.dummy_dakota.parameter.ranged",
"model_data": {
"initial_value": 3,
"lower_bound": 0,
......@@ -20,7 +20,7 @@
},
"data_sources": [
{
"id": "force.bdss.enthought.bundle.csv_extractor",
"id": "force.bdss.enthought.factory.csv_extractor",
"model_data": {
"filename": "foo.csv",
"row": 3,
......@@ -34,7 +34,7 @@
}
},
{
"id": "force.bdss.enthought.bundle.csv_extractor",
"id": "force.bdss.enthought.factory.csv_extractor",
"model_data": {
"filename": "foo.csv",
"row": 3,
......@@ -50,7 +50,7 @@
],
"kpi_calculators": [
{
"id": "force.bdss.enthought.bundle.kpi_adder",
"id": "force.bdss.enthought.factory.kpi_adder",
"model_data": {
"cuba_type_in": "PRESSURE",
"cuba_type_out": "TOTAL_PRESSURE",
......
......@@ -2,7 +2,7 @@
"version": "1",
"workflow": {
"mco": {
"id": "force.bdss.enthought.bundle.null_mco",
"id": "force.bdss.enthought.factory.null_mco",
"model_data": {
"parameters" : [
]
......@@ -10,7 +10,7 @@
},
"data_sources": [
{
"id": "force.bdss.enthought.bundle.null_ds",
"id": "force.bdss.enthought.factory.null_ds",
"model_data": {
"input_slot_maps": [
],
......@@ -21,7 +21,7 @@
],
"kpi_calculators": [
{
"id": "force.bdss.enthought.bundle.null_kpic",
"id": "force.bdss.enthought.factory.null_kpic",
"model_data": {
"input_slot_maps": [
],
......
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