From 4c6e257d1d3e60a0e9a6951397deea72bef7eebc Mon Sep 17 00:00:00 2001 From: wqy Date: Tue, 27 Jun 2023 20:51:09 +0800 Subject: [PATCH] Fix service area case --- dev.py | 11 +++++++++++ devops.py | 11 ----------- epanet/epanet.py | 2 +- epanet/epanet2_ec.py | 17 ++++++++++++++++- test_tjnetwork.py | 5 +++-- 5 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 dev.py delete mode 100644 devops.py diff --git a/dev.py b/dev.py new file mode 100644 index 0000000..08f18a4 --- /dev/null +++ b/dev.py @@ -0,0 +1,11 @@ +from tjnetwork import * + +p = 'dev' +read_inp(p, './inp/net3.inp', '3') + +open_project(p) + +sass = calculate_service_area(p) +assert len(sass) == 25 +print(sass[0]) +print(sass[1]) \ No newline at end of file diff --git a/devops.py b/devops.py deleted file mode 100644 index a34e68b..0000000 --- a/devops.py +++ /dev/null @@ -1,11 +0,0 @@ -from tjnetwork import * - -if __name__ == '__main__': - p = 'net4' - copy_project('net3', p) - open_project(p) - set_vertex(p, ChangeSet({'link' : '20', 'coords': [{'x': 20.0, 'y': 40.0}, {'x': 40.0, 'y': 20.0}]})) - set_restore_operation_to_current(p) - close_project(p) - for i in range(1, 11): - copy_project(p, f'{p}_{i}') diff --git a/epanet/epanet.py b/epanet/epanet.py index 8ce2275..e3f53f0 100644 --- a/epanet/epanet.py +++ b/epanet/epanet.py @@ -33,7 +33,7 @@ class Output: def _check(self, result): - if result != 0: + if result != 0 and result != 10: msg = ctypes.c_char_p() code = self._lib.ENR_checkError(self._handle, ctypes.byref(msg)) assert code == result diff --git a/epanet/epanet2_ec.py b/epanet/epanet2_ec.py index e6bce6b..c0df16b 100644 --- a/epanet/epanet2_ec.py +++ b/epanet/epanet2_ec.py @@ -2,6 +2,9 @@ ERROR_CODE = {} # EPANET 2 Error Messages ERROR_CODE['0'] = "ok" + +ERROR_CODE['10'] = "Warning: model run issued warnings" + ERROR_CODE['101'] = "insufficient memory available" ERROR_CODE['102'] = "no network data available" ERROR_CODE['103'] = "hydraulic solver not opened" @@ -74,4 +77,16 @@ ERROR_CODE['305'] = "cannot open hydraulics file" ERROR_CODE['306'] = "hydraulics file does not match network data" ERROR_CODE['307'] = "cannot read hydraulics file" ERROR_CODE['308'] = "cannot save results to file" -ERROR_CODE['309'] = "cannot save results to report file" \ No newline at end of file +ERROR_CODE['309'] = "cannot save results to report file" + +ERROR_CODE['411'] = "Input Error 411: no memory allocated for results" +ERROR_CODE['412'] = "Input Error 412: binary file hasn't been opened" +ERROR_CODE['421'] = "Input Error 421: invalid parameter code" +ERROR_CODE['422'] = "Input Error 422: reporting period index out of range" +ERROR_CODE['423'] = "Input Error 423: element index out of range" + +ERROR_CODE['434'] = "File Error 434: unable to open binary file" +ERROR_CODE['435'] = "File Error 435: invalid binary file type" +ERROR_CODE['436'] = "File Error 436: no results in binary file" + +ERROR_CODE['ERR'] = "Error: An unknown error has occurred" diff --git a/test_tjnetwork.py b/test_tjnetwork.py index b22c932..aa06f6f 100644 --- a/test_tjnetwork.py +++ b/test_tjnetwork.py @@ -6192,8 +6192,9 @@ class TestApi: sass = calculate_service_area(p) assert len(sass) == 25 - assert sass[0] == {'River': ['River', '60', '61', '123', '601', '121', '120', '119', '125', '117', '257', '151', '157', '127', '153', '115', '261', '259', '149', '159', '20', '129', '111', '113', '107', '263', '147', '161', '3', '131', '139', '109', '197', '193', '105', '145', '163', '195', '141', '103', '191', '101', '164', '265', '143', '187', '166', '169', '267', '15', '204', '167', '171', '269', '189', '185', '173', '271', '183', '184', '199', '181', '179', '205', '201', '273', '35', '177', '40', '207', '203', '275', '1', '206', '208', '209', '211', '213', '237', '215', '229', '217', '231', '219', '225'], '2': ['2', '50', '255', '247', '253', '251', '241', '249', '239', '243', '237', '229', '231']} - assert sass[1] == {'River': ['River', '60', '61', '123', '601', '121', '120', '119', '125', '117', '151', '157', '127', '153', '115', '149', '159', '20', '129', '111', '113', '147', '161', '3', '131', '139', '197', '193', '145', '163', '195', '141', '191', '267', '164', '265', '143', '187', '189', '166', '169', '15', '204', '183', '167', '171', '269', '185', '179', '173', '271', '184', '40', '199', '181', '205', '1', '201', '273', '35', '177', '207', '203', '275', '206', '208', '209', '211', '213', '237', '215', '229', '239', '217', '231', '241', '249', '219', '225', '243', '247'], 'Lake': ['Lake', '10', '101', '103', '105', '109', '107', '263', '111', '115', '259', '261', '113', '197', '257', '117', '193', '191', '120', '267', '187', '119', '189', '265', '204', '151', '157', '183', '169', '185', '149', '159', '179', '167', '171', '269', '184', '147', '161', '40', '173', '271', '205', '145', '163', '195', '1', '199', '181', '207', '141', '164', '201', '273', '35', '177', '206', '143', '166', '203', '275', '208', '15', '209', '211', '213', '237', '215', '229', '239', '217', '231', '241', '249', '219', '225', '243', '247'], '2': ['2', '50', '255', '247', '253', '251', '249']} + + assert sass[0] == {'River': ['River', '60', '61', '123', '601', '121', '120', '119', '117', '257', '151', '157', '115', '259', '261', '149', '159', '111', '113', '263', '147', '161', '197', '193', '105', '145', '163', '195', '191', '267', '107', '141', '164', '265', '187', '189', '143', '166', '169', '204', '15', '167', '171', '269', '185', '173', '271', '184', '199', '205', '201', '207', '273', '203', '275'], '1': ['1', '40', '179', '177', '183', '181', '185', '189', '35', '271', '184', '187', '171', '205', '204', '173', '207', '273', '199', '275', '201', '203'], '2': ['2', '50', '255', '247', '253', '251', '241', '249', '239', '243', '237', '211', '229', '209', '213', '231', '208', '215', '206', '217', '207', '219', '225', '275', '201', '203'], '3': ['3', '20', '127', '125', '129', '121', '153', '131', '139', '120', '119', '151', '141', '117', '257', '157', '149', '143', '115', '259', '261', '159', '147', '15', '111', '113', '263', '161', '145', '197', '193', '105', '163', '195', '191', '267', '107', '164', '265', '187', '189', '166', '169', '204', '167', '171', '269', '185', '173', '271', '184', '199', '205', '201', '207', '273', '203', '275']} + assert sass[1] == {'River': ['River', '60', '61', '123', '601', '121', '120', '119', '117', '257', '151', '157', '115', '259', '261', '149', '159', '111', '113', '263', '147', '161', '197', '193', '105', '145', '163', '195', '191', '107', '141', '164', '265', '187', '143', '166', '169', '267', '204', '15', '167', '171', '269', '189', '185', '173', '271', '184', '199', '205', '201', '207', '273', '203', '275'], 'Lake': ['Lake', '10', '101', '103', '105', '109', '107', '111', '115', '113', '197', '193', '191', '187', '204', '185', '184', '205', '207', '273', '275', '199', '201', '203'], '1': ['1', '40', '179', '177', '183', '181', '185', '189', '35', '271', '184', '187', '171', '205', '204', '173', '207', '273', '199', '275', '201', '203'], '2': ['2', '50', '255', '247', '253', '251', '241', '249', '239', '243', '237', '211', '229', '209', '213', '231', '208', '215', '206', '217', '207', '219', '225', '275', '201', '203'], '3': ['3', '20', '127', '125', '129', '121', '153', '131', '139', '120', '119', '151', '141', '117', '257', '157', '149', '143', '115', '259', '261', '159', '147', '15', '111', '113', '263', '161', '145', '197', '193', '105', '163', '195', '191', '107', '164', '265', '187', '166', '169', '267', '204', '167', '171', '269', '189', '185', '173', '271', '184', '199', '205', '201', '207', '273', '203', '275']} self.leave(p)