def test_get_inputs_for_operation(self): """ Tests method get_datatype_and_datatypegroup_inputs_for_operation. Verifies filters' influence over results is as expected """ zip_path = os.path.join(os.path.dirname(tvb_data.__file__), 'connectivity', 'connectivity_66.zip') conn = TestFactory.import_zip_connectivity(self.test_user, self.test_project, zip_path) view_model = BaseBCTModel() view_model.connectivity = conn.gid adapter = ABCAdapter.build_adapter_from_class( TransitivityBinaryDirected) result = OperationService().fire_operation(adapter, self.test_user, self.test_project.id, view_model=view_model) conn.visible = False dao.store_entity(conn) operation = dao.get_operation_by_id(result[0].id) inputs = self.project_service.get_datatype_and_datatypegroup_inputs_for_operation( operation.gid, self.relevant_filter) assert len(inputs) == 0 inputs = self.project_service.get_datatype_and_datatypegroup_inputs_for_operation( operation.gid, self.full_filter) assert len(inputs) == 1, "Incorrect number of inputs." assert conn.id == inputs[0].id, "Retrieved wrong input dataType."
def test_get_inputs_for_group(self, datatype_group_factory, test_adapter_factory): """ Tests method get_datatypes_inputs_for_operation_group. """ zip_path = os.path.join(os.path.dirname(tvb_data.__file__), 'connectivity', 'connectivity_66.zip') conn = TestFactory.import_zip_connectivity(self.test_user, self.test_project, zip_path) conn.visible = False dao.store_entity(conn) group = OperationGroup(self.test_project.id, "group", "range1[1..2]") group = dao.store_entity(group) view_model = BaseBCTModel() view_model.connectivity = conn.gid adapter = ABCAdapter.build_adapter_from_class( TransitivityBinaryDirected) algorithm = adapter.stored_adapter operation1 = Operation(self.test_user.id, self.test_project.id, algorithm.id, json.dumps({'gid': view_model.gid.hex}), op_group_id=group.id) operation2 = Operation(self.test_user.id, self.test_project.id, algorithm.id, json.dumps({'gid': view_model.gid.hex}), op_group_id=group.id) dao.store_entities([operation1, operation2]) OperationService()._store_view_model( operation1, dao.get_project_by_id(self.test_project.id), view_model) OperationService()._store_view_model( operation2, dao.get_project_by_id(self.test_project.id), view_model) inputs = self.project_service.get_datatypes_inputs_for_operation_group( group.id, self.relevant_filter) assert len(inputs) == 0 inputs = self.project_service.get_datatypes_inputs_for_operation_group( group.id, self.full_filter) assert len(inputs) == 1, "Incorrect number of dataTypes." assert group.id == inputs[0].id, "Retrieved wrong dataType." conn.visible = True dao.store_entity(conn) inputs = self.project_service.get_datatypes_inputs_for_operation_group( group.id, self.relevant_filter) assert len(inputs) == 1, "Incorrect number of dataTypes." inputs = self.project_service.get_datatypes_inputs_for_operation_group( group.id, self.full_filter) assert len(inputs) == 1, "Incorrect number of dataTypes." assert group.id == inputs[0].id, "Retrieved wrong dataType."
def test_bct_all(self): """ Iterate all BCT algorithms and execute them. """ view_model = BaseBCTModel() view_model.connectivity = self.connectivity.gid algo_category = dao.get_category_by_id( self.bct_adapters[0].stored_adapter.fk_category) for adapter_instance in self.bct_adapters: results = TestFactory.launch_synchronously(self.test_user.id, self.test_project, adapter_instance, view_model) assert len(results) > 0
def build(test_user, test_project): view_model = BaseBCTModel() view_model.connectivity = get_filtered_datatypes(test_project.id, ConnectivityIndex, page_size=1)[0][0][2] adapter = ABCAdapter.build_adapter_from_class(TransitivityBinaryDirected) op = OperationService().fire_operation(adapter, test_user, test_project.id, view_model=view_model) # wait for the operation to finish tries = 5 while not op.has_finished and tries > 0: sleep(5) tries = tries - 1 op = dao.get_operation_by_id(op.id) value_wrapper = try_get_last_datatype(test_project.id, ValueWrapperIndex) count = dao.count_datatypes(test_project.id, ValueWrapperIndex) assert 1 == count return value_wrapper
def test_bct_all(self): """ Iterate all BCT algorithms and execute them. """ service = OperationService() algo_category = dao.get_category_by_id(self.bct_adapters[0].stored_adapter.fk_category) for adapter_instance in self.bct_adapters: algorithm = adapter_instance.stored_adapter view_model = BaseBCTModel() view_model.connectivity = self.connectivity.gid # Avoid the scheduled execution, as this is asynch, thus launch it immediately operation = service.prepare_operations(self.test_user.id, self.test_project, algorithm, algo_category, {}, True, view_model=view_model)[0][0] service.initiate_prelaunch(operation, adapter_instance) operation = dao.get_operation_by_id(operation.id) # Check that operation status after execution is success. assert STATUS_FINISHED == operation.status # Make sure at least one result exists for each BCT algorithm results = dao.get_generic_entity(DataType, operation.id, 'fk_from_operation') assert len(results) > 0
def launch_operation_examples(tvb_client_instance): logger.info("Requesting projects for logged user") projects_of_user = tvb_client_instance.get_project_list() assert len(projects_of_user) > 0 logger.info("TVB has {} projects for this user".format(len(projects_of_user))) project_gid = projects_of_user[0].gid # --- Launch operations to import a Connectivity, a Surface and a RegionMapping --- logger.info("Importing a connectivity from ZIP...") zip_connectivity_importer_model = ZIPConnectivityImporterModel() zip_connectivity_importer_model.uploaded = compute_tvb_data_path('connectivity', 'connectivity_96.zip') zip_connectivity_importer_model.normalization = 'region' operation_gid = tvb_client_instance.launch_operation(project_gid, ZIPConnectivityImporter, zip_connectivity_importer_model) monitor_operation(tvb_client_instance, operation_gid) logger.info("Get the result of connectivity import...") connectivity_dto = tvb_client_instance.get_operation_results(operation_gid)[0] logger.info("Importing a surface from ZIP...") zip_surface_importer_model = ZIPSurfaceImporterModel() zip_surface_importer_model.uploaded = compute_tvb_data_path('surfaceData', 'cortex_16384.zip') zip_surface_importer_model.surface_type = CORTICAL zip_surface_importer_model.should_center = False operation_gid = tvb_client_instance.launch_operation(project_gid, ZIPSurfaceImporter, zip_surface_importer_model) monitor_operation(tvb_client_instance, operation_gid) logger.info("Get the result of surface import...") surface_dto = tvb_client_instance.get_operation_results(operation_gid)[0] logger.info("Importing a region mapping...") rm_importer_model = RegionMappingImporterModel() rm_importer_model.mapping_file = compute_tvb_data_path('regionMapping', 'regionMapping_16k_76.txt') rm_importer_model.connectivity = connectivity_dto.gid rm_importer_model.surface = surface_dto.gid operation_gid = tvb_client_instance.launch_operation(project_gid, RegionMappingImporter, rm_importer_model) monitor_operation(tvb_client_instance, operation_gid) logger.info("Get the result of region mapping import...") region_mapping_dto = tvb_client_instance.get_operation_results(operation_gid)[0] # --- Load the region mapping together with references information in 3 different ways --- logger.info("1.Download and load the region mapping with all its references...") region_mapping_complete = tvb_client_instance.load_datatype_with_full_references(region_mapping_dto.gid, tvb_client_instance.temp_folder) logger.info("1.This region mapping is linked to a connectivity with GID={} and number_of_regions={}".format( region_mapping_complete.connectivity.gid, region_mapping_complete.connectivity.number_of_regions)) logger.info("2.Download and load the region mapping with only GIDs for its references...") region_mapping_with_links = tvb_client_instance.load_datatype_with_links(region_mapping_dto.gid, tvb_client_instance.temp_folder) logger.info("2.This region mapping is linked to a connectivity with GID={}".format( region_mapping_with_links.connectivity.gid)) logger.info("3.Only download the region mapping on client machine...") region_mapping_path = tvb_client_instance.retrieve_datatype(region_mapping_dto.gid, tvb_client_instance.temp_folder) logger.info("3.Load the region mapping that was already downloaded on client machine...") local_region_mapping_with_links = tvb_client_instance.load_datatype_from_file(region_mapping_path) logger.info("3.This region mapping is linked to a connectivity with GID={}".format( local_region_mapping_with_links.connectivity.gid)) # --- Launch operation to run a Degree Analyzer over the Connectivity --- bct_model = BaseBCTModel() bct_model.connectivity = connectivity_dto.gid operation_gid = tvb_client_instance.launch_operation(project_gid, Degree, bct_model) monitor_operation(tvb_client_instance, operation_gid) logger.info("Get the result of BCT...") bct_dto = tvb_client_instance.get_operation_results(operation_gid)[0] logger.info("The resulted BCT has GID={}".format(bct_dto.gid))