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

Changed name to id

parent 8479e52d
No related branches found
No related tags found
1 merge request!20Use ids instead of names in bundles.
Showing
with 67 additions and 37 deletions
......@@ -37,27 +37,27 @@ class BaseCoreDriver(Plugin):
List(IKPICalculatorBundle),
id='force.bdss.kpi_calculators.bundles')
def _data_source_bundle_by_name(self, name):
def _data_source_bundle_by_id(self, id):
for ds in self.data_source_bundles:
if ds.name == name:
if ds.id == id:
return ds
raise Exception("Requested data source {} but don't know "
"to find it.".format(name))
"to find it.".format(id))
def _kpi_calculator_bundle_by_name(self, name):
def _kpi_calculator_bundle_by_id(self, id):
for kpic in self.kpi_calculator_bundles:
if kpic.name == name:
if kpic.id == id:
return kpic
raise Exception(
"Requested kpi calculator {} but don't know "
"to find it.".format(name))
"to find it.".format(id))
def _mco_bundle_by_name(self, name):
def _mco_bundle_by_id(self, id):
for mco in self.mco_bundles:
if mco.name == name:
if mco.id == id:
return mco
raise Exception("Requested MCO {} but it's not available"
"to compute it.".format(name))
"to compute it.".format(id))
import click
from ..bdss_application import BDSSApplication
from traits.api import push_exception_handler
push_exception_handler(reraise_exceptions=True)
@click.command()
@click.option("--evaluate", is_flag=True)
......
File moved
{
"multi_criteria_optimizer": {
"name": "dakota",
"id": "enthought.dakota",
"model_data": {
"value_types": ["DUMMY"]
}
},
"data_sources": [
{
"name": "csv_extractor",
"id": "enthought.csv_extractor",
"model_data": {
"filename": "foo.csv",
"row": 3,
......@@ -16,7 +16,7 @@
}
},
{
"name": "csv_extractor",
"id": "enthought.csv_extractor",
"model_data": {
"filename": "foo.csv",
"row": 3,
......@@ -27,7 +27,7 @@
],
"kpi_calculators": [
{
"name": "kpi_adder",
"id": "enthought.kpi_adder",
"model_data": {
"cuba_type_in": "PRESSURE",
"cuba_type_out": "TOTAL_PRESSURE"
......
import unittest
import subprocess
import os
from contextlib import contextmanager
@contextmanager
def cd(dir):
cwd = os.curdir
os.chdir(dir)
try:
yield
finally:
os.chdir(cwd)
def fixture_dir():
return os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"fixtures")
class TestExecution(unittest.TestCase):
def test_plain_invocation_mco(self):
with cd(fixture_dir()):
out = subprocess.check_call(["force_bdss", "test_csv.json"])
self.assertEqual(out, 0)
if __name__ == '__main__':
unittest.main()
......@@ -13,7 +13,7 @@ class CoreEvaluationDriver(BaseCoreDriver):
workflow = self.application.workflow
mco_data = workflow.multi_criteria_optimizer
mco_bundle = self._mco_bundle_by_name(mco_data.name)
mco_bundle = self._mco_bundle_by_id(mco_data.id)
mco_model = mco_bundle.create_model(mco_data.model_data)
mco_communicator = mco_bundle.create_communicator(
self.application,
......@@ -23,8 +23,8 @@ class CoreEvaluationDriver(BaseCoreDriver):
ds_results = []
for requested_ds in workflow.data_sources:
ds_bundle = self._data_source_bundle_by_name(
requested_ds.name)
ds_bundle = self._data_source_bundle_by_id(
requested_ds.id)
ds_model = ds_bundle.create_model(requested_ds.model_data)
data_source = ds_bundle.create_data_source(
self.application, ds_model)
......@@ -32,8 +32,8 @@ class CoreEvaluationDriver(BaseCoreDriver):
kpi_results = []
for requested_kpic in workflow.kpi_calculators:
kpic_bundle = self._kpi_calculator_bundle_by_name(
requested_kpic.name)
kpic_bundle = self._kpi_calculator_bundle_by_id(
requested_kpic.id)
ds_model = kpic_bundle.create_model(
requested_kpic.model_data)
kpi_calculator = kpic_bundle.create_data_source(
......
......@@ -13,7 +13,7 @@ class CoreMCODriver(BaseCoreDriver):
workflow = self.application.workflow
mco_data = workflow.multi_criteria_optimizer
mco_bundle = self._mco_bundle_by_name(mco_data.name)
mco_bundle = self._mco_bundle_by_id(mco_data.id)
mco_model = mco_bundle.create_model(mco_data.model_data)
mco = mco_bundle.create_optimizer(self.application, mco_model)
......
......@@ -9,7 +9,7 @@ from .csv_extractor_data_source import CSVExtractorDataSource
@provides(IDataSourceBundle)
class CSVExtractorBundle(HasStrictTraits):
name = String("csv_extractor")
id = String("enthought.csv_extractor")
def create_model(self, model_data=None):
if model_data is None:
......
......@@ -7,7 +7,7 @@ from .csv_extractor.csv_extractor_bundle import CSVExtractorBundle
class CSVExtractorPlugin(Plugin):
id = "force.bdss.data_sources.csv_extractor"
id = "force.bdss.plugins.enthought.csv_extractor"
data_sources = List(
IDataSourceBundle,
......
......@@ -9,7 +9,7 @@ from .kpi_adder_calculator import KPIAdderCalculator
@provides(IKPICalculatorBundle)
class KPIAdderBundle(HasStrictTraits):
name = String("kpi_adder")
id = String("enthought.kpi_adder")
def create_model(self, model_data=None):
if model_data is None:
......
......@@ -8,7 +8,7 @@ from .kpi_adder.kpi_adder_bundle import KPIAdderBundle
class TestKPICalculatorPlugin(Plugin):
id = "force.bdss.kpi_calculators.test_kpi_calculator_plugin"
id = "force.bdss.plugins.enthought.test_kpi_calculator_plugin"
kpi_calculators = List(
IKPICalculatorBundle,
......
......@@ -12,7 +12,7 @@ from .dakota_optimizer import DakotaOptimizer
@provides(IMultiCriteriaOptimizerBundle)
class DakotaBundle(HasStrictTraits):
name = String("dakota")
id = String("enthought.dakota")
def create_model(self, model_data=None):
if model_data is None:
......
......@@ -8,7 +8,7 @@ from .dakota.dakota_bundle import DakotaBundle
class MultiCriteriaOptimizersPlugin(Plugin):
id = "force.bdss.mco.plugins.multi_criteria_optimizers_plugin"
id = "force.bdss.plugins.enthought.multi_criteria_optimizers_plugin"
multi_criteria_optimizers = List(
IMultiCriteriaOptimizerBundle,
......
......@@ -2,7 +2,7 @@ from traits.api import Interface, String
class IDataSourceBundle(Interface):
name = String()
id = String()
def create_data_source(self, application, model):
pass
......
......@@ -2,7 +2,7 @@ from traits.api import Interface, String
class IKPICalculatorBundle(Interface):
name = String()
id = String()
def create_kpi_calculator(self, application, model):
pass
......
......@@ -2,7 +2,7 @@ from traits.api import Interface, String
class IMultiCriteriaOptimizerBundle(Interface):
name = String()
id = String()
def create_optimizer(self, application, model):
pass
......
from traits.has_traits import HasStrictTraits
from traits.trait_types import String, Dict
from traits.api import HasStrictTraits, String, Dict
class DataSource(HasStrictTraits):
name = String()
id = String()
model_data = Dict()
@classmethod
def from_json(cls, json_data):
self = cls(
name=json_data["name"],
id=json_data["id"],
model_data=json_data["model_data"]
)
......
from traits.has_traits import HasStrictTraits
from traits.trait_types import String, Dict
from traits.api import HasStrictTraits, String, Dict
class KPICalculator(HasStrictTraits):
name = String()
id = String()
model_data = Dict()
@classmethod
def from_json(cls, json_data):
self = cls(
name=json_data["name"],
id=json_data["id"],
model_data=json_data["model_data"]
)
......
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