Exemplo n.º 1
0
    def get_launchable_algorithms(self, datatype_gid):
        """
        :param datatype_gid: Filter only algorithms compatible with this GUID
        :return: dict(category_name: List AlgorithmTransientGroup)
        """
        categories = dao.get_launchable_categories()
        datatype_instance, filtered_adapters, has_operations_warning = self._get_launchable_algorithms(
            datatype_gid, categories)

        if isinstance(datatype_instance, DataTypeGroup):
            # If part of a group, update also with specific analyzers of the child datatype
            dt_group = dao.get_datatype_group_by_gid(datatype_gid)
            datatypes = dao.get_datatypes_from_datatype_group(dt_group.id)
            if len(datatypes):
                datatype = datatypes[-1]
                analyze_category = dao.get_launchable_categories(True)
                _, inner_analyzers, _ = self._get_launchable_algorithms(
                    datatype.gid, analyze_category)
                filtered_adapters.extend(inner_analyzers)

        categories_dict = dict()
        for c in categories:
            categories_dict[c.id] = c.displayname

        return self._group_adapters_by_category(
            filtered_adapters, categories_dict), has_operations_warning
Exemplo n.º 2
0
 def get(self, datatype_gid):
     """
     :return the available operations for that datatype, as a list of Algorithm instances
     """
     categories = dao.get_launchable_categories()
     datatype = dao.get_datatype_by_gid(datatype_gid)
     if datatype is None:
         raise InvalidIdentifierException(INVALID_DATATYPE_GID_MESSAGE.format(datatype_gid))
     _, filtered_adapters, _ = self.flow_service.get_launchable_algorithms_for_datatype(datatype, categories)
     return [AlgorithmDto(algorithm) for algorithm in filtered_adapters]
    def get_launchable_algorithms(self, datatype_gid):
        """
        :param datatype_gid: Filter only algorithms compatible with this GUID
        :return: dict(category_name: List AlgorithmTransientGroup)
        """
        categories = dao.get_launchable_categories()
        datatype_instance, filtered_adapters = self._get_launchable_algorithms(datatype_gid, categories)

        if isinstance(datatype_instance, model.DataTypeGroup):
            # If part of a group, update also with specific analyzers of the child datatype
            dt_group = dao.get_datatype_group_by_gid(datatype_gid)
            datatypes = dao.get_datatypes_from_datatype_group(dt_group.id)
            if len(datatypes):
                datatype = datatypes[-1]
                analyze_category = dao.get_launchable_categories(True)
                _, inner_analyzers = self._get_launchable_algorithms(datatype.gid, analyze_category)
                filtered_adapters.extend(inner_analyzers)

        categories_dict = dict()
        for c in categories:
            categories_dict[c.id] = c.displayname

        return self._group_adapters_by_category(filtered_adapters, categories_dict)
Exemplo n.º 4
0
    def get_launchable_algorithms(self, datatype_gid):
        """
        :param datatype_gid: Filter only algorithms compatible with this GUID
        :return: dict(category_name: List AlgorithmTransientGroup)
        """
        categories = dao.get_launchable_categories()
        datatype_instance, filtered_adapters, has_operations_warning = self._get_launchable_algorithms(
            datatype_gid, categories)

        categories_dict = dict()
        for c in categories:
            categories_dict[c.id] = c.displayname

        return self._group_adapters_by_category(
            filtered_adapters, categories_dict), has_operations_warning
    def get_analyze_groups(self):
        """
        :return: list of AlgorithmTransientGroup entities
        """
        categories = dao.get_launchable_categories(elimin_viewers=True)
        categories_ids = [categ.id for categ in categories]
        stored_adapters = dao.get_adapters_from_categories(categories_ids)

        groups_list = []
        for adapter in stored_adapters:
            # For empty groups, this time, we fill the actual adapter
            group = AlgorithmTransientGroup(adapter.group_name or adapter.displayname,
                                            adapter.group_description or adapter.description)
            group = self._find_group(groups_list, group)
            group.children.append(adapter)
        return categories[0], groups_list
Exemplo n.º 6
0
    def get_analyze_groups(self):
        """
        :return: list of AlgorithmTransientGroup entities
        """
        categories = dao.get_launchable_categories(elimin_viewers=True)
        categories_ids = [categ.id for categ in categories]
        stored_adapters = dao.get_adapters_from_categories(categories_ids)

        groups_list = []
        for adapter in stored_adapters:
            # For empty groups, this time, we fill the actual adapter
            group = AlgorithmTransientGroup(adapter.group_name or adapter.displayname,
                                            adapter.group_description or adapter.description)
            group = self._find_group(groups_list, group)
            group.children.append(adapter)
        return categories[0], groups_list
Exemplo n.º 7
0
 def get_launchable_non_viewers():
     """Retrieve all Algorithm categories, with display capability"""
     result = dao.get_launchable_categories(elimin_viewers=True)
     if result is None or len(result) < 1:
         raise Exception("Analyze Category not found!!!")
     return result[0]
Exemplo n.º 8
0
    def retrieve_launchers(self, datatype_gid, inspect_group=False, include_categories=None):
        """
        Returns all the available launch-able algorithms from the database.
        Filter the ones accepting as required input a specific DataType.

        :param datatype_gid: GID, to filter algorithms for this particular entity.
        :param inspect_group: TRUE if we are now in the inspection of sub-entities in a DataTypeGroup
        :param include_categories: List of categories to be included in the result.
                When None, all lanchable categories are included
        """
        try:
            all_launch_categ = dao.get_launchable_categories()
            launch_categ = dict((categ.id, categ.displayname) for categ in all_launch_categ
                                if include_categories is None or categ.id in include_categories)

            datatype_instance = dao.get_datatype_by_gid(datatype_gid)
            data_class = datatype_instance.__class__
            all_compatible_classes = [data_class.__name__]
            for one_class in getmro(data_class):
                if issubclass(one_class, MappedType) and one_class.__name__ not in all_compatible_classes:
                    all_compatible_classes.append(one_class.__name__)

            self.logger.debug("Searching in categories: " + str(len(launch_categ)) + " - " +
                              str(launch_categ.keys()) + "-" + str(include_categories))
            launchable_groups = dao.get_apliable_algo_groups(all_compatible_classes, launch_categ.keys())

            to_remove = []
            for one_group in launchable_groups:
                compatible_algorithms = []
                for one_algo in one_group.children:
                    filter_chain = FilterChain.from_json(one_algo.datatype_filter)
                    if not filter_chain or filter_chain.get_python_filter_equivalent(datatype_instance):
                        compatible_algorithms.append(one_algo)
                if len(compatible_algorithms) > 0:
                    one_group.children = copy.deepcopy(compatible_algorithms)
                else:
                    to_remove.append(one_group)

            for one_group in to_remove:
                launchable_groups.remove(one_group)
                del one_group

            launchers = ProjectService.__prepare_group_result(launchable_groups, launch_categ, inspect_group)

            if data_class.__name__ == model.DataTypeGroup.__name__:
                # If part of a group, update also with specific launchers of the child datatype
                dt_group = dao.get_datatype_group_by_gid(datatype_gid)
                datatypes = dao.get_datatypes_from_datatype_group(dt_group.id)
                if len(datatypes):
                    datatype = datatypes[-1]
                    datatype = dao.get_datatype_by_gid(datatype.gid)

                    views_categ_id = dao.get_visualisers_categories()[0].id
                    categories_for_small_type = [categ.id for categ in all_launch_categ
                                                 if categ.id != views_categ_id and (include_categories is None or
                                                                                    categ.id in include_categories)]
                    if categories_for_small_type:
                        specific_launchers = self.retrieve_launchers(datatype.gid, True, categories_for_small_type)
                        for key in specific_launchers:
                            if key in launchers:
                                launchers[key].update(specific_launchers[key])
                            else:
                                launchers[key] = specific_launchers[key]
            return launchers

        except Exception, excep:
            ProjectService().logger.exception(excep)
            ProjectService().logger.warning("Attempting to filter launcher for group despite exception!")
            return ProjectService.__prepare_group_result([], [], inspect_group)
Exemplo n.º 9
0
 def get_launchable_non_viewers():
     """Retrieve all Algorithm categories, with display capability"""
     result = dao.get_launchable_categories(elimin_viewers=True)
     if result is None or len(result) < 1:
         raise Exception("Analyze Category not found!!!")
     return result[0]
Exemplo n.º 10
0
 def get_datatype_operations(self, datatype_gid):
     categories = dao.get_launchable_categories(elimin_viewers=True)
     datatype = dao.get_datatype_by_gid(datatype_gid)
     _, filtered_adapters, _ = self.algorithm_service.get_launchable_algorithms_for_datatype(
         datatype, categories)
     return [AlgorithmDto(algorithm) for algorithm in filtered_adapters]
Exemplo n.º 11
0
 def get_launchable_non_viewers():
     """Retrieve the Analyze Algorithm Category, (first category with launch capability which is not Viewers)"""
     result = dao.get_launchable_categories(elimin_viewers=True)
     if result is None or len(result) < 1:
         raise Exception("Analyze Category not found!!!")
     return result[0]
    def retrieve_launchers(self, dataname, datatype_gid=None, inspect_group=False, exclude_categories=None):
        """
        Returns all the available launch-able algorithms from the database.
        Filter the ones accepting as required input a specific DataType.

        :param dataname: String or class representing DataType to retrieve filters for it.
        :param datatype_gid: Optional GID, to filter algorithms for this particular entity.
        :param inspect_group: TRUE if we are now in the inspection of sub-entities in a DataTypeGroup
        :param exclude_categories: List of categories to be excluded from the result.
        """
        if exclude_categories is None:
            exclude_categories = []
        launch_categ = dao.get_launchable_categories()
        launch_categ = dict((categ.id, categ.displayname) for categ in launch_categ
                            if categ.id not in exclude_categories)
        launch_groups = dao.get_apliable_algo_groups(dataname, launch_categ.keys())

        if datatype_gid is None:
            return ProjectService.__prepare_group_result(launch_groups, launch_categ, inspect_group)

        try:
            datatype_instance = dao.get_datatype_by_gid(datatype_gid)
            data_class = datatype_instance.__class__
            for one_class in data_class.__bases__:
                launch_groups.extend(dao.get_apliable_algo_groups(one_class.__name__, launch_categ.keys()))
            specific_datatype = dao.get_generic_entity(data_class, datatype_gid, "gid")
            to_remove = []
            for one_group in launch_groups:
                valid_algorithms = []
                for one_algo in one_group.children:
                    filter_chain = FilterChain.from_json(one_algo.datatype_filter)
                    if not filter_chain or filter_chain.get_python_filter_equivalent(specific_datatype[0]):
                        valid_algorithms.append(one_algo)
                if len(valid_algorithms) > 0:
                    one_group.children = copy.deepcopy(valid_algorithms)
                else:
                    to_remove.append(one_group)
            for one_group in to_remove:
                launch_groups.remove(one_group)
                del one_group
            launchers = ProjectService.__prepare_group_result(launch_groups, launch_categ, inspect_group)

            if dataname == model.DataTypeGroup.__name__:
                # If part of a group, update also with specific launchers of that datatype
                dt_group = dao.get_datatype_group_by_gid(datatype_gid)
                datatypes = dao.get_datatypes_from_datatype_group(dt_group.id)
                if len(datatypes):
                    datatype = datatypes[-1]
                    datatype = dao.get_datatype_by_gid(datatype.gid)
                    views_categ_id = dao.get_visualisers_categories()[0].id
                    specific_launchers = self.retrieve_launchers(datatype.__class__.__name__, datatype.gid,
                                                                 True, [views_categ_id] + exclude_categories)
                    for key in specific_launchers:
                        if key in launchers:
                            launchers[key].update(specific_launchers[key])
                        else:
                            launchers[key] = specific_launchers[key]
            return launchers
        except Exception, excep:
            ProjectService().logger.exception(excep)
            ProjectService().logger.warning("Attempting to filter launcher  for group despite exception!")
            return ProjectService.__prepare_group_result(launch_groups, launch_categ, inspect_group)
Exemplo n.º 13
0
 def get_launchable_non_viewers():
     """Retrieve the Analyze Algorithm Category, (first category with launch capability which is not Viewers)"""
     result = dao.get_launchable_categories(elimin_viewers=True)
     if result is None or len(result) < 1:
         raise Exception("Analyze Category not found!!!")
     return result[0]
Exemplo n.º 14
0
    def retrieve_launchers(self, datatype_gid, inspect_group=False, include_categories=None):
        """
        Returns all the available launch-able algorithms from the database.
        Filter the ones accepting as required input a specific DataType.

        :param datatype_gid: GID, to filter algorithms for this particular entity.
        :param inspect_group: TRUE if we are now in the inspection of sub-entities in a DataTypeGroup
        :param include_categories: List of categories to be included in the result.
                When None, all lanchable categories are included
        """
        try:
            all_launch_categ = dao.get_launchable_categories()
            launch_categ = dict((categ.id, categ.displayname) for categ in all_launch_categ
                                if include_categories is None or categ.id in include_categories)

            datatype_instance = dao.get_datatype_by_gid(datatype_gid)
            data_class = datatype_instance.__class__
            all_compatible_classes = [data_class.__name__]
            for one_class in getmro(data_class):
                if issubclass(one_class, MappedType) and one_class.__name__ not in all_compatible_classes:
                    all_compatible_classes.append(one_class.__name__)

            self.logger.debug("Searching in categories: " + str(len(launch_categ)) + " - " +
                              str(launch_categ.keys()) + "-" + str(include_categories))
            launchable_groups = dao.get_apliable_algo_groups(all_compatible_classes, launch_categ.keys())

            to_remove = []
            for one_group in launchable_groups:
                compatible_algorithms = []
                for one_algo in one_group.children:
                    filter_chain = FilterChain.from_json(one_algo.datatype_filter)
                    if not filter_chain or filter_chain.get_python_filter_equivalent(datatype_instance):
                        compatible_algorithms.append(one_algo)
                if len(compatible_algorithms) > 0:
                    one_group.children = copy.deepcopy(compatible_algorithms)
                else:
                    to_remove.append(one_group)

            for one_group in to_remove:
                launchable_groups.remove(one_group)
                del one_group

            launchers = ProjectService.__prepare_group_result(launchable_groups, launch_categ, inspect_group)

            if data_class.__name__ == model.DataTypeGroup.__name__:
                # If part of a group, update also with specific launchers of the child datatype
                dt_group = dao.get_datatype_group_by_gid(datatype_gid)
                datatypes = dao.get_datatypes_from_datatype_group(dt_group.id)
                if len(datatypes):
                    datatype = datatypes[-1]
                    datatype = dao.get_datatype_by_gid(datatype.gid)

                    views_categ_id = dao.get_visualisers_categories()[0].id
                    categories_for_small_type = [categ.id for categ in all_launch_categ
                                                 if categ.id != views_categ_id and (include_categories is None or
                                                                                    categ.id in include_categories)]
                    if categories_for_small_type:
                        specific_launchers = self.retrieve_launchers(datatype.gid, True, categories_for_small_type)
                        for key in specific_launchers:
                            if key in launchers:
                                launchers[key].update(specific_launchers[key])
                            else:
                                launchers[key] = specific_launchers[key]
            return launchers

        except Exception, excep:
            ProjectService().logger.exception(excep)
            ProjectService().logger.warning("Attempting to filter launcher for group despite exception!")
            return ProjectService.__prepare_group_result([], [], inspect_group)