def test_get_boundaries(self): boundary1 = OptimalBoundary(cells=[ CellID('N'), CellID('O0'), CellID('P123'), CellID('S34567') ]) boundary2 = OptimalBoundary(cells=[CellID('O35'), CellID('P234')]) boundary3 = OptimalBoundary(cells=[CellID('S034'), CellID('S57')]) data = Data('') b_ds = { boundary1.boundary_ID.value: (boundary1, data), boundary2.boundary_ID.value: (boundary2, data), boundary3.boundary_ID.value: (boundary3, data) } b_dataset = BoundaryDataSet('id', b_ds) boundaries = b_dataset.get_boundaries() self.assertEqual(boundaries, [boundary1, boundary2, boundary3])
def fromJSON(self, bds, file=False): if file: bds = json.load(bds) self.boundary_data_set = {} self.id = bds['id'] boundary_list = bds['boundary_data_set'] for boundary in boundary_list: self.add(OptimalBoundary(boundary_ID=AUID(boundary['AUID'])), Data(boundary['data'])) return self
def test_optimal_boundary_from_cells(self): optimal_boundary = OptimalBoundary(cells=[ CellID('N11'), CellID('N12'), CellID('N13'), CellID('N88'), CellID('O0'), CellID('P123'), CellID('S34567') ]) self.assertEqual( optimal_boundary.boundary_ID.value, 'RN11$))2$))3$)))88$))))O0$)))P123$)))))S34567$))))))))')
def test_get_boundary_data_list(self): boundary1 = OptimalBoundary(cells=[ CellID('N'), CellID('O0'), CellID('P123'), CellID('S34567') ]) boundary2 = OptimalBoundary(cells=[CellID('O35'), CellID('P234')]) boundary3 = OptimalBoundary(cells=[CellID('S034'), CellID('S57')]) data = Data('data') data2 = Data('data2') b_ds = { boundary1.boundary_ID.value: (boundary1, data), boundary2.boundary_ID.value: (boundary2, data), boundary3.boundary_ID.value: (boundary3, data2) } b_dataset = BoundaryDataSet('id', b_ds) self.assertEqual( b_dataset.get_boundary_data_list( [boundary1.boundary_ID, boundary3.boundary_ID]), [data, data2])
def test_boundary_dataset_add(self): boundary1 = OptimalBoundary(cells=[ CellID('N'), CellID('O0'), CellID('P123'), CellID('S34567') ]) boundary2 = OptimalBoundary(cells=[CellID('O35'), CellID('P234')]) boundary3 = OptimalBoundary(cells=[CellID('S034'), CellID('S57')]) data = Data('') b_ds = { boundary1.boundary_ID.value: (boundary1, data), boundary2.boundary_ID.value: (boundary2, data), } b_dataset = BoundaryDataSet('id', b_ds) b_dataset.add(boundary3, data) b_ds2 = { boundary1.boundary_ID.value: (boundary1, data), boundary2.boundary_ID.value: (boundary2, data), boundary3.boundary_ID.value: (boundary3, data) } self.assertEqual(b_dataset.boundary_data_set, b_ds2)
def all_boundary_datasets(self): """ :return: List of all stored BoundaryDatasets """ boundary_data_sets = [] boundaries_datasets_founded = self.db.b_data_sets.find() for boundary_dataset in boundaries_datasets_founded: bds = BoundaryDataSet(id=boundary_dataset["_id"]) boundaries_in_bds_founded = self.db.boundaries.find( {"boundary_dataset_id": boundary_dataset["_id"]}) for boundary in boundaries_in_bds_founded: bds.add(OptimalBoundary(boundary_ID=AUID(boundary["auid"])), Data(boundary["data"])) boundary_data_sets.append(bds) return boundary_data_sets
def query_by_boundary_dataset_id(self, id): """ :param id: identifier of the BoundaryDataset :return: BoundaryDataset stored with that id. """ boundaries_datasets_founded = self.db.b_data_sets.find({"_id": id}) boundary_data_sets = [] for boundary_dataset in boundaries_datasets_founded: bds = BoundaryDataSet(id=id) boundaries_in_bds_founded = self.db.boundaries.find( {"boundary_dataset_id": boundary_dataset["_id"]}) for boundary in boundaries_in_bds_founded: bds.add(OptimalBoundary(boundary_ID=AUID(boundary["auid"])), Data(boundary["data"])) boundary_data_sets.append(bds) return boundary_data_sets