From 5b32a0566aa8b92edd534bbc53db4d6de421f6e7 Mon Sep 17 00:00:00 2001
From: Stefano Borini <sborini@enthought.com>
Date: Tue, 1 Aug 2017 11:10:04 +0100
Subject: [PATCH] Restructuring base classes against the DataValue concept

---
 force_bdss/core/data_value.py                 | 18 +++--
 force_bdss/data_sources/base_data_source.py   | 14 ++--
 .../data_sources/data_source_parameters.py    | 26 --------
 force_bdss/data_sources/data_source_result.py | 66 -------------------
 force_bdss/kpi/base_kpi_calculator.py         | 13 ++--
 force_bdss/kpi/kpi_calculator_result.py       | 54 ---------------
 force_bdss/mco/base_mco_communicator.py       |  2 +-
 7 files changed, 27 insertions(+), 166 deletions(-)
 delete mode 100644 force_bdss/data_sources/data_source_parameters.py
 delete mode 100644 force_bdss/data_sources/data_source_result.py
 delete mode 100644 force_bdss/kpi/kpi_calculator_result.py

diff --git a/force_bdss/core/data_value.py b/force_bdss/core/data_value.py
index f03aca3..fc20a49 100644
--- a/force_bdss/core/data_value.py
+++ b/force_bdss/core/data_value.py
@@ -1,17 +1,25 @@
-from traits.api import HasStrictTraits, Any, String
+from traits.api import HasStrictTraits, Any, String, Int
 
 
 class DataValue(HasStrictTraits):
-    """Contains the parameters as passed from the MCO."""
-    #: The CUBA types associated to the values
+    """Contains in-transit data between the various components (MCO/DS/KPI).
+    Each DataValue instance holds information about the CUBA type it
+    contains, the name as assigned by the user, and the value (which can be
+    anything.
+    """
+    #: The CUBA type associated to the value.
     type = String()
 
-    #: The user-defined names associated to the values.
+    #: The user-defined name associated to the value.
     name = String()
 
-    #: The values as a single array.
+    #: The value.
     value = Any()
 
+    accuracy = Any()
+
+    quality = Int()
+
     def __str__(self):
         return """
         {} {} : {}
diff --git a/force_bdss/data_sources/base_data_source.py b/force_bdss/data_sources/base_data_source.py
index 3a9fedb..6c6f5da 100644
--- a/force_bdss/data_sources/base_data_source.py
+++ b/force_bdss/data_sources/base_data_source.py
@@ -20,20 +20,20 @@ class BaseDataSource(ABCHasStrictTraits):
     @abc.abstractmethod
     def run(self, model, parameters):
         """
-        Executes the KPI evaluation and returns the results it computes.
-        Reimplement this method in your specific KPI calculator.
+        Executes the Data Source evaluation and returns the results it
+        computes. Reimplement this method in your specific DataSource.
 
         Parameters
         ----------
         model: BaseDataSourceModel
             The model of the DataSource, instantiated through create_model()
 
-        parameters: DataSourceParameters
-            a DataResultParameters instance containing the information coming
-            from the MCO
+        parameters: List(DataValue)
+            a list of DataValue objects containing the information needed
+            for the execution of the DataSource.
 
         Returns
         -------
-        DataSourceResult
-            Instance that holds the results computed by this DataSource.
+        List(DataValue)
+            A list containing the computed Data Values.
         """
diff --git a/force_bdss/data_sources/data_source_parameters.py b/force_bdss/data_sources/data_source_parameters.py
deleted file mode 100644
index 378ad26..0000000
--- a/force_bdss/data_sources/data_source_parameters.py
+++ /dev/null
@@ -1,26 +0,0 @@
-from traits.api import HasStrictTraits, Array, List, String
-
-
-class DataSourceParameters(HasStrictTraits):
-    """Contains the parameters as passed from the MCO."""
-    #: The user-defined names associated to the values.
-    value_names = List(String)
-
-    #: The CUBA types associated to the values
-    value_types = List(String)
-
-    #: The values as a single array.
-    values = Array(shape=(None,))
-
-    def __str__(self):
-        return """
-        DataSourceParameters
-        value_names:
-        {}
-        value_types:
-        {}
-        values:
-        {}
-        """.format(str(self.value_names),
-                   str(self.value_types),
-                   str(self.values))
diff --git a/force_bdss/data_sources/data_source_result.py b/force_bdss/data_sources/data_source_result.py
deleted file mode 100644
index d19c16b..0000000
--- a/force_bdss/data_sources/data_source_result.py
+++ /dev/null
@@ -1,66 +0,0 @@
-from traits.api import HasTraits, Array, ArrayOrNone, List, String, Instance
-
-from .base_data_source import BaseDataSource
-
-
-class DataSourceResult(HasTraits):
-    """Represents the result of a DataSource evaluation.
-
-    Note
-    ----
-    Difference between accuracy and quality:
-      - uncertainty is a numerical quantity defining the accuracy of the value.
-        For example, a pressure can be 10.4 +/- 0.1, with 0.1 being the
-        accuracy
-      - quality is the level of importance and reliability of that value.
-        It should be considered as a weight of how much trust one should hold
-        on this information.
-    """
-
-    #: A reference to the DataSource that computed this result.
-    originator = Instance(BaseDataSource)
-
-    #: The user-defined names associated to each result.
-    value_names = List(String)
-
-    #: The CUBA types of each value.
-    value_types = List(String)
-
-    #: The values for each entry. Note that this is a NxM array, allowing
-    #: to propagate more than single scalar values associated to a given value.
-    values = Array(shape=(None, None))
-
-    #: If present, the numerical accuracy of the above values.
-    accuracy = ArrayOrNone(shape=(None, None))
-
-    #: If present, the assessed quality of the above values.
-    quality = ArrayOrNone(shape=(None, None))
-
-    def __str__(self):
-        return """
-        DataSourceResults
-
-        originator:
-        {}
-
-        value_names:
-        {}
-
-        value_types:
-        {}
-
-        values:
-        {}
-
-        Accuracy:
-        {}
-
-        Quality:
-        {}
-        """.format(
-            self.originator,
-            self.value_names,
-            self.value_types,
-            self.values,
-            self.accuracy,
-            self.quality)
diff --git a/force_bdss/kpi/base_kpi_calculator.py b/force_bdss/kpi/base_kpi_calculator.py
index 0d86647..1bb1bf4 100644
--- a/force_bdss/kpi/base_kpi_calculator.py
+++ b/force_bdss/kpi/base_kpi_calculator.py
@@ -18,7 +18,7 @@ class BaseKPICalculator(ABCHasStrictTraits):
         super(BaseKPICalculator, self).__init__(*args, **kwargs)
 
     @abc.abstractmethod
-    def run(self, model, data_source_results):
+    def run(self, model, data_values):
         """
         Executes the KPI evaluation and returns the results it computes.
         Reimplement this method in your specific KPI calculator.
@@ -29,13 +29,12 @@ class BaseKPICalculator(ABCHasStrictTraits):
             The model of the KPI Calculator, instantiated through
             create_model()
 
-        data_source_results:
-            a list of DataSourceResult instances containing the results of the
-            evaluation. Each DataSourceResult contains the results from one
-            specific DataSource.
+        data_values:
+            a list of DataValue instances containing data from the
+            MCO and DataSources.
 
         Returns
         -------
-        KPICalculatorResult
-            Instance that holds the results computed by this KPICalculator.
+        List[DataValue]:
+            The result of this KPI evaluation, as a list of DataValues.
         """
diff --git a/force_bdss/kpi/kpi_calculator_result.py b/force_bdss/kpi/kpi_calculator_result.py
deleted file mode 100644
index dce0df9..0000000
--- a/force_bdss/kpi/kpi_calculator_result.py
+++ /dev/null
@@ -1,54 +0,0 @@
-from traits.api import HasTraits, List, Array, ArrayOrNone, String, Instance
-
-from .base_kpi_calculator import BaseKPICalculator
-
-
-class KPICalculatorResult(HasTraits):
-    """Contains the results from a single KPICalculator evaluation"""
-
-    #: The originating KPI calculator
-    originator = Instance(BaseKPICalculator)
-
-    #: The user-attributed names of each computed value
-    value_names = List(String)
-
-    #: The CUBA types of each of the computed values
-    value_types = List(String)
-
-    #: The values, as a single array of values
-    values = Array(shape=(None, ))
-
-    #: If present, the numerical accuracy of the above values.
-    accuracy = ArrayOrNone(shape=(None, ))
-
-    #: If present, the quality of the above values.
-    quality = ArrayOrNone(shape=(None, ))
-
-    def __str__(self):
-        return """
-        DataSourceResults
-
-        originator:
-        {}
-
-        value_names:
-        {}
-
-        value_types:
-        {}
-
-        values:
-        {}
-
-        Accuracy:
-        {}
-
-        Quality:
-        {}
-        """.format(
-                self.originator,
-                self.value_names,
-                self.value_types,
-                self.values,
-                self.accuracy,
-                self.quality)
diff --git a/force_bdss/mco/base_mco_communicator.py b/force_bdss/mco/base_mco_communicator.py
index 073b16c..cad5ef3 100644
--- a/force_bdss/mco/base_mco_communicator.py
+++ b/force_bdss/mco/base_mco_communicator.py
@@ -55,6 +55,6 @@ class BaseMCOCommunicator(ABCHasStrictTraits):
         model: BaseMCOModel
             The model of the optimizer, instantiated through create_model()
 
-        kpi_results: List(KPICalculatorResult)
+        kpi_results: List(DataValue)
             A list of KPI calculator results, one per each KPI calculator.
         """
-- 
GitLab