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

Custom Weather: Validation #3313

Merged
merged 2 commits into from May 18, 2020
Merged

Custom Weather: Validation #3313

merged 2 commits into from May 18, 2020

Conversation

rajadain
Copy link
Member

@rajadain rajadain commented May 14, 2020

Overview

Adds, enhances validations for custom weather uploads.

The err helper method is used as shorthand for reporting errors. The first parameter is the message, the second is the line number. If specified, the line number will be prefixed to the error message.

The validations check for the following:

  • Valid CSV header
  • Valid length of file
  • Valid year range between first and last date
  • All dates are properly parseable
  • There are no duplicate dates
  • There are no missing / out of order dates
  • Precipitation and temperature are valid floats
  • Precipitation is not negative

If a file has too many errors, we only report that first 10. This is configurable in the MAX_ERRORS variable.

Connects #3284

Demo

image

image

image

image

image

image

image

image

image

Notes

If you find any unrelated bugs during the testing, please add them to #3312.

Testing Instructions

  • Download this file: weather-data-tests.zip (this is slightly different from past versions of this zip, so please re-download it)
  • Run bundle --debug
  • Go to a MapShed project and upload all files except for full-3-years and full-30-years
    • Ensure you see the correct errors for every one of them
    • Inspect the files at the reported lines to ensure the errors are reported correctly
  • Upload full-3-years and full-30-years
    • Ensure they are accepted successfully

Previously upload button's state was set in two different places:
turned off during a fetch, and turned back on during error
handling. This was because we assumed that in the success case
the entire view would be replaced with Existing Weather Data View.

However, in case of re-uploading after validation errors, the
button needs to be turned back on. Furthermore, it is better to
consolidate all the logic concerning it in one place makes it
more composable.
@rajadain
Copy link
Member Author

Fixing the lint ...

@rajadain
Copy link
Member Author

Lint fixed in 7ff73ee. Added some comments in 8af32b4.

Copy link
Contributor

@mmcfarland mmcfarland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good accounting of the edge cases here. I did find one aspect that will report false negatives if there are certain errors, but none that allow invalid data to be accepted. The false negatives would be resolved if the user fixed the valid errors, but my concern is that they might prove to be red herring that confuse the user. I'm fine with deferring a fix for that if it's not trivial, because the user should be able to understand the issue by looking at the source/error messages.

I also added a comment to #3312 about a workflow that, while not really a bug (the user doesn't hit save), may leave CWD files attached to a scenario that the user doesn't expect to be there.

Nice work.

# line numbers start at 1, and we need to account for the header.
err(e.message, idx + 2)

previous_d = d
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may not be problematic enough to address, but you'll introduce an "incorrect date sequence" error for every other error that may be contained in the list. This may be confusing if there are a few "real" errors, but they start trying to fix their date sequences. The problem is that the previous_d is incremented even if the row fails, so the next "correct" row looks like it should be incremented an addition date - but really the previous row meant to capture that date. You can see the fact that the follow up line-error is consistent to the real errors:

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is tolerable for now. I've recorded this in the enhancement card #3316.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I think this is tolerable is that I hope we are communicating well enough that we need contiguous dates of data, and when the user is fixing the file they may notice and ensure that the dates are contiguous, fixing all of this together.

Yet, attention narrows as matter of course, and this case may yet become annoying enough for us to solve. But given the budget I propose we wait to hear from users before fixing it.

@rajadain
Copy link
Member Author

Thanks for taking a look! Going to squash and merge now.

The `err` helper method is used as shorthand for reporting
errors. The first parameter is the message, the second is the
line number. If specified, the line number will be prefixed to
the error message.

The validations check for the following:

  - Valid CSV header
  - Valid length of file
  - Valid year range between first and last date
  - All dates are properly parseable
  - There are no duplicate dates
  - There are no missing / out of order dates
  - Precipitation and temperature are valid floats
  - Precipitation is not negative

If a file has too many errors, we only report that first 10.
This is configurable in the MAX_ERRORS variable.
@rajadain rajadain force-pushed the tt/custom-weather-validation branch from 8af32b4 to 4e9e3ae Compare May 18, 2020 01:02
@rajadain rajadain merged commit ba6758e into develop May 18, 2020
@rajadain rajadain deleted the tt/custom-weather-validation branch May 18, 2020 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Custom Weather Data OSI Funding Source: OSI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants