Skip to content
Snippets Groups Projects

Kpi calculators

Merged Adham Hashibon requested to merge kpi-calculators into master
1 file
+ 2
2
Compare changes
  • Side-by-side
  • Inline
@@ -5,6 +5,7 @@ from traits.trait_types import List
from force_bdss.data_sources.i_data_source_bundle import (
IDataSourceBundle)
from force_bdss.kpi.i_kpi_calculator_bundle import IKPICalculatorBundle
from force_bdss.mco.i_multi_criteria_optimizer_bundle import (
IMultiCriteriaOptimizerBundle)
@@ -25,12 +26,18 @@ class CoreMCODriver(Plugin):
List(IMultiCriteriaOptimizerBundle),
id='force.bdss.mco.bundles')
#: A list of the available Key Performance Indicator calculators.
#: A list of the available Data Sources.
#: It will be populated by plugins.
data_source_bundles = ExtensionPoint(
List(IDataSourceBundle),
id='force.bdss.data_sources.bundles')
#: A list of the available Key Performance Indicator calculators.
#: It will be populated by plugins.
kpi_calculator_bundles = ExtensionPoint(
List(IKPICalculatorBundle),
id='force.bdss.kpi_calculators.bundles')
@on_trait_change("application:started")
def application_started(self):
workflow = self.application.workflow
@@ -47,6 +54,27 @@ class CoreMCODriver(Plugin):
else:
raise Exception("Requested data source {} but don't know "
"to find it.".format(requested_ds.name))
kpi_results = []
for requested_kpic in workflow.kpi_calculators:
kpic_bundle = self._find_kpi_calculator_bundle_by_name(
requested_kpic.name)
if kpic_bundle:
kpic_model = kpic_bundle.create_model(
requested_kpic.model_data)
kpi_calculator = kpic_bundle.create_data_source(
self.application, kpic_model)
kpi_results.append(kpi_calculator.run(ds_results))
else:
raise Exception(
"Requested kpi calculator {} but don't know "
"to find it.".format(requested_kpic.name))
print(
kpi_results[0].value_types,
kpi_results[0].values
)
else:
mco_data = workflow.multi_criteria_optimizer
mco_bundle = self._find_mco_bundle_by_name(mco_data.name)
@@ -65,6 +93,13 @@ class CoreMCODriver(Plugin):
return None
def _find_kpi_calculator_bundle_by_name(self, name):
for kpic in self.kpi_calculator_bundles:
if kpic.name == name:
return kpic
return None
def _find_mco_bundle_by_name(self, name):
for mco in self.mco_bundles:
if mco.name == name:
Loading