def _get_launchable_algorithms(self, datatype_gid, 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(categories) + " for classes " + str(all_compatible_classes)) categories_ids = [categ.id for categ in categories] launchable_adapters = dao.get_applicable_adapters( all_compatible_classes, categories_ids) filtered_adapters = [] for stored_adapter in launchable_adapters: filter_chain = FilterChain.from_json( stored_adapter.datatype_filter) if not filter_chain or filter_chain.get_python_filter_equivalent( datatype_instance): filtered_adapters.append(stored_adapter) return datatype_instance, filtered_adapters
def _get_launchable_algorithms(self, datatype_gid, 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(categories) + " for classes " + str(all_compatible_classes)) categories_ids = [categ.id for categ in categories] launchable_adapters = dao.get_applicable_adapters(all_compatible_classes, categories_ids) filtered_adapters = [] for stored_adapter in launchable_adapters: filter_chain = FilterChain.from_json(stored_adapter.datatype_filter) if not filter_chain or filter_chain.get_python_filter_equivalent(datatype_instance): filtered_adapters.append(stored_adapter) return datatype_instance, filtered_adapters
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)
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)
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)