Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve validation message when bounding boxes don't intersect #502 #1376

Merged
merged 5 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ Unreleased Changes
has been merged into ``utils.read_csv_to_dataframe``
(`#1319 <https://github.com/natcap/invest/issues/1319>`_),
(`#1327 <https://github.com/natcap/invest/issues/1327>`_)
* Coastal Blue Carbon
* Added validation for the transition table, raising a validation error if
unexpected values are encountered.
(`#729 <https://github.com/natcap/invest/issues/729>`_)
* Improved the validation message that is returned when not all spatial
inputs overlap (`#502 <https://github.com/natcap/invest/issues/502>`_)
* Workbench
* Fixed a bug where sampledata downloads failed silently (and progress bar
became innacurate) if the Workbench did not have write permission to
Expand All @@ -69,6 +67,10 @@ Unreleased Changes
* Middle clicking an InVEST model tab was opening a blank window. Now
middle clicking will close that tab as expected.
(`#1261 <https://github.com/natcap/invest/issues/1261>`_)
* Coastal Blue Carbon
* Added validation for the transition table, raising a validation error if
unexpected values are encountered.
(`#729 <https://github.com/natcap/invest/issues/729>`_)
* Forest Carbon
* The biophysical table is now case-insensitive.
* HRA
Expand Down
3 changes: 2 additions & 1 deletion src/natcap/invest/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
'NOT_AN_INTEGER': gettext('Value "{value}" does not represent an integer'),
'NOT_BOOLEAN': gettext("Value must be either True or False, not {value}"),
'NO_PROJECTION': gettext('Spatial file {filepath} has no projection'),
'BBOX_NOT_INTERSECT': gettext("Bounding boxes do not intersect: {bboxes}"),
'BBOX_NOT_INTERSECT': gettext('Not all of the spatial layers overlap each '
'other. All bounding boxes must intersect: {bboxes}'),
'NEED_PERMISSION': gettext('You must have {permission} access to this file'),
}

Expand Down
2 changes: 1 addition & 1 deletion tests/test_habitat_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -1934,7 +1934,7 @@ def test_habitat_quality_argspec_spatial_overlap(self):
self.assertTrue(
validate_result,
"expected failed validations instead didn't get any.")
self.assertIn("Bounding boxes do not intersect", validate_result[0][1])
self.assertIn("bounding boxes must intersect", validate_result[0][1])

def test_habitat_quality_argspec_missing_projection(self):
"""Habitat Quality: raise error on missing projection."""
Expand Down
5 changes: 3 additions & 2 deletions workbench/src/renderer/components/SetupTab/ArgInput/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const { ipcRenderer } = window.Workbench.electron;
* @returns {string} - the filtered and formatted part of the message
*/
function filterSpatialOverlapFeedback(message, filepath) {
const newPrefix = i18n.t('Bounding box does not intersect at least one other:');
const newPrefix = i18n.t(
'Not all of the spatial layers overlap each other. Bounding box:');
const bbox = message.split(`${filepath}:`).pop().split('|')[0];
const bboxFormatted = bbox.split(' ').map(
(str) => str.padEnd(22, ' ')
Expand Down Expand Up @@ -167,7 +168,7 @@ export default function ArgInput(props) {
// Messages with this pattern include validation feedback about
// multiple inputs, but the whole message is repeated for each input.
// It's more readable if filtered on the individual input.
const pattern = 'Bounding boxes do not intersect';
const pattern = 'Not all of the spatial layers overlap each other';
if (validationMessage.startsWith(pattern)) {
validationMessage = filterSpatialOverlapFeedback(
validationMessage, value
Expand Down
4 changes: 2 additions & 2 deletions workbench/tests/renderer/setuptab.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,8 @@ describe('Misc form validation stuff', () => {
const rasterValue = './raster.tif';
const expectedVal2 = '-79.0198012081401';
const rasterBox = `[${expectedVal2}, 26.481559513537064, -78.37173806200593, 27.268061760228512]`;
const message = `Bounding boxes do not intersect: ${vectorValue}: ${vectorBox} | ${rasterValue}: ${rasterBox}`;
const newPrefix = 'Bounding box does not intersect at least one other:';
const message = `Not all of the spatial layers overlap each other. All bounding boxes must intersect: ${vectorValue}: ${vectorBox} | ${rasterValue}: ${rasterBox}`;
const newPrefix = 'Not all of the spatial layers overlap each other. Bounding box:';
const vectorMessage = new RegExp(`${newPrefix}\\s*\\[${expectedVal1}`);
const rasterMessage = new RegExp(`${newPrefix}\\s*\\[${expectedVal2}`);

Expand Down
Loading