from ScEpTIC.config.base_config import ScEpTICBaseConfig from ScEpTIC.exceptions import ConfigurationException class CustomMetricsConfig(ScEpTICBaseConfig): """ Configuration for Custom Metrics """ _config_domain = { 'metric_id': {'class': int, 'mode': 'add'}, 'metric_name': {'class': str, 'mode': 'add'}, 'collect_energy': {'class': bool, 'mode': 'add'}, 'collect_time': {'class': bool, 'mode': 'add'}, 'collect_cc': {'class': bool, 'mode': 'add'}, 'data_diffs': {'class': bool, 'mode': 'add'}, 'print_data': {'class': bool, 'mode': 'add'}, } def __init__(self, main_config): super().__init__(main_config) self.metrics = {} self.names = [] def add_custom_metric(self, metric_id, metric_name, collect_energy=False, collect_time=False, collect_cc=False, data_diffs=False, print_data=False): self._check('metric_id', metric_id, 'add') self._check('metric_name', metric_name, 'add') self._check('collect_energy', collect_energy, 'add') self._check('collect_time', collect_time, 'add') self._check('collect_cc', collect_cc, 'add') self._check('data_diffs', data_diffs, 'add') self._check('print_data', print_data, 'add') if metric_id in self.metrics: raise ConfigurationException(f"[{self.__class__.__name__}] Custom metric with id #{metric_id} already registered!") if metric_name in self.names: raise ConfigurationException(f"[{self.__class__.__name__}] Custom metric {metric_name} already registered!") self.names.append(metric_name) self.metrics[metric_id] = { 'metric_name': metric_name, 'collect_energy': collect_energy, 'collect_time': collect_time, 'collect_cc': collect_cc, 'data_diffs': data_diffs, 'print_data': print_data, } def set_config(self, config_name, config_value): raise ConfigurationException(f"[{self.__class__.__name__}] Method set_config() not supported for custom metrics!") def add_config(self, config_name, config_value): raise ConfigurationException(f"[{self.__class__.__name__}] Method add_config() not supported for custom metrics!")