# coding=utf-8 class Diagnostic(object): """ Base class for the diagnostics. Provides a common interface for them and also has a mechanism that allows diagnostic retrieval by name. :param data_manager: data manager that will be used to store and retrieve the necessary data :type data_manager: DataManager """ def __init__(self, data_manager): self.data_manager = data_manager self.required_vars = [] self.generated_vars = [] self.can_run_multiple_instances = True @staticmethod def register(cls, alias): """ Register a new diagnostic using the given alias. It must be call using the derived class. :param cls: diagnostic class to register :type cls: Diagnostic :param alias: alias for the diagnostic :type alias: str """ try: Diagnostic._diag_list[alias] = cls except AttributeError: Diagnostic._diag_list = dict() Diagnostic._diag_list[alias] = cls # noinspection PyProtectedMember @staticmethod def get_diagnostic(name): """ Return the class for a diagnostic given its name :param name: diagnostic alias :type name: str :return: the selected Diagnostic class, None if name can not be found :rtype: Diagnostic """ try: if name in Diagnostic._diag_list.keys(): return Diagnostic._diag_list[name] except AttributeError: pass return None def compute(self): """ Calculates the diagnostic and stores the output Must be implemented by derived classes """ raise NotImplementedError("Class must override compute method") @classmethod def generate_jobs(cls, diags, options): """ Generate the instances of the diagnostics that will be run by the manager Must be implemented by derived classes. :param diags: diagnostics manager :type diags: Diags :param options: list of strings containing the options passed to the diagnostic :type options: list[str] :return: """ raise NotImplementedError("Class must override generate_jobs class method") def __str__(self): """ Must be implemented by derived classes :return: """ return 'Developer must override base class __str__ method'