def test_update_cell_dataset(self): store.dropAll() cds = CellDataSet("id") cells = ['P0', 'P1', 'P2', 'P3', 'P4', 'P5'] for cell in cells: cds.add(CellID(cell), Data("")) store.insert(cds) cds2 = CellDataSet("id") cells2 = ['O0', 'O1', 'O2', 'O3', 'O4'] for cell in cells2: cds2.add(CellID(cell), Data("")) store.update_cell_dataset(cds2) stored_cds = store.query_by_cell_dataset_id("id") num_cds = 0 num_cells = 0 for cds in stored_cds: for cell in cds.get_cells(): assert cells2.__contains__(cell.value) num_cells = num_cells + 1 num_cds = num_cds + 1 self.assertEqual(num_cds, 1) self.assertEqual(num_cells, len(cells2)) store.dropAll()
def to_internal_value(self, data): cds = CellDataSet(id='') for item in data: if not re.match(r'^[A-Za-z0-9]+$', item['cellID']): raise ValidationError('Incorrect format: ' + item['cellID']) cds.add(CellID(item['cellID']), Data(item['data'])) return cds.cell_data_set
def all_cell_datasets(self): """ :return: List of all stored CellDatasets """ cell_data_sets = [] cell_datasets_founded = self.db.c_data_sets.find() for cell_dataset in cell_datasets_founded: cds = CellDataSet(id=cell_dataset["_id"]) cells_in_cds_founded = self.db.cells.find({"cell_dataset_id": cell_dataset["_id"]}) for cell in cells_in_cds_founded: cds.add(CellID(cell['cellID']), Data(cell["data"])) cell_data_sets.append(cds) return cell_data_sets
def test_cell_dataset_add(self): cells = [CellID('N01'), CellID('N02'), CellID('N03'), CellID('N04')] data = Data('test') cell_data_set = { cells[0].value: (cells[0], data), cells[1].value: (cells[1], data), cells[2].value: (cells[2], data) } c_dataset = CellDataSet('id', cell_data_set=cell_data_set) c_dataset.add(cells[3], data) self.assertEqual(c_dataset.cells, cells)
def query_by_cell_dataset_id(self, id): """ :param id: identifier of the CellDataset :return: List of tuples with stored cells and data associated stored in the CellDataset with that id. """ cell_datasets_founded = self.db.c_data_sets.find({"_id": id}) cell_data_sets = [] for cell_dataset in cell_datasets_founded: cds = CellDataSet(id=id) cells_in_cds_founded = self.db.cells.find({"cell_dataset_id": cell_dataset["_id"]}) for cell in cells_in_cds_founded: cds.add(CellID(cell['cellID']), Data(cell["data"])) cell_data_sets.append(cds) return cell_data_sets
def test_delete_cell(self): store.dropAll() cds = CellDataSet("id") cells = ['P0', 'P1', 'P2', 'P3', 'P4', 'P5'] for cell in cells: cds.add(CellID(cell), Data("")) store.insert(cds) deleted_cells = store.delete_cell(CellID('P0')) self.assertEqual(deleted_cells, 1) stored_cells = store.query_by_cell(CellID('P0')) self.assertEqual(stored_cells.__len__(), 0) store.dropAll()
def get_cell_dataset_from_tif_file(self, file, id): cds = CellDataSet(id=id) dataset, band, refinement = self.tif_file_treatment(file) for j in range(dataset.height): print(str(j) + "/" + str((dataset.height))) for i in range(dataset.width): cell_rHealPix_coords = dataset.xy(j, i) cell = self.dggs.get_cell_from_projected_point( refinement, cell_rHealPix_coords) data = Data(int(band[j, i])) cds.add(cell, data) if j == 10: break return cds
def test_query_by_cell(self): store.dropAll() cds = CellDataSet("id") cells = ['P0', 'P1', 'P2', 'P3', 'P4', 'P5'] for cell in cells: cds.add(CellID(cell), Data("")) store.insert(cds) stored_cells = store.query_by_cell(CellID('P0')) num_cells = 0 for cell in stored_cells: assert cells.__contains__(cell[0].value) num_cells = num_cells + 1 self.assertEqual(num_cells, 1) store.dropAll()
def test_insert_and_all_cells(self): store.dropAll() cds = CellDataSet("id") cells = ['P0', 'P1', 'P2', 'P3', 'P4', 'P5'] for cell in cells: cds.add(CellID(cell), Data("")) store.insert(cds) stored_cells = store.all_cells() num_cells = 0 for cell in stored_cells: assert cells.__contains__(cell[0].value) num_cells = num_cells + 1 self.assertEqual(num_cells, len(cells)) store.dropAll()
def query_by_cell_to_cell_datasets(self, cell_id): """ :param cell_id: CellID :return: List of CellDataSets where cell_id is located """ cells_founded = self.db.cells.find({"id": cell_id.value}) cell_data_sets = [] for cell in cells_founded: cds = CellDataSet() cells_in_bds_founded = self.db.cells.find( {"cell_dataset_id": cell["cell_dataset_id"]}) for cell_2 in cells_in_bds_founded: cell, data = self.get_Cell_Data(cell_2) cds.add(cell, data) cell_data_sets.append(cds) return cell_data_sets
def test_delete_cell_in_cell_datasets(self): store.dropAll() cds = CellDataSet("id") cells = ['P0', 'P1', 'P2', 'P3', 'P4', 'P5'] for cell in cells: cds.add(CellID(cell), Data("")) store.insert(cds) deleted_cells = store.delete_cell_in_cell_datasets("id", CellID('P0')) self.assertEqual(deleted_cells, 1) stored_cds = store.query_by_cell_in_cell_datasets("id", CellID('P0')) num_cds = 0 for cds in stored_cds: assert cds.get_cells().__len__() == 0 num_cds = num_cds + 1 self.assertEqual(num_cds, 1) store.dropAll()
def test_query_by_cell_in_cell_datasets(self): store.dropAll() cds = CellDataSet("id") cells = ['P0', 'P1', 'P2', 'P3', 'P4', 'P5'] for cell in cells: cds.add(CellID(cell), Data("")) store.insert(cds) stored_cds = store.query_by_cell_in_cell_datasets("id", CellID('P0')) num_cds = 0 num_cells = 0 for cds in stored_cds: for cell in cds.get_cells(): assert cells.__contains__(cell.value) num_cells = num_cells + 1 num_cds = num_cds + 1 self.assertEqual(num_cds, 1) self.assertEqual(num_cells, 1) store.dropAll()