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

Adds support for accuracyThreshold #1703

Merged
merged 10 commits into from
Aug 15, 2017
Merged

Adds support for accuracyThreshold #1703

merged 10 commits into from
Aug 15, 2017

Conversation

oliverroick
Copy link
Member

Proposed changes in this pull request

Implements #597: Adds support for XLSForm's accuracyThreshold to set the minimum GPS accuracy required when collecting coordinates in GeoODK.

  • Adds questionnaires.validators.validate_accuracy, which checks if a given value is a positive float. This is used in various places to validate input for accuracyThreshold.
  • Refactor questionnaires.models.Question.TYPE_CHOICES into questionnaires.choices.QUESTION_TYPES to resolve a circular import between models and validators
  • Adds the new field gps_accuracy to questionnaires.models.Question.
  • Extends questionnaires.managers.QuestionManager.create_from_dict so it reads and stores accuracyThreshold from XLSForms.
  • Extends xforms.renderers.XFormRenderer so accuracyThreshold is added to rendered XForms, which are used by GeoODK.
  • Adds field gps_accuracy to questionnaires.serializers.QuestionSerializer so the value is read and written via the JSON API.
  • Extends questionnaires.validators.QUESTION_SCHEMA so gps_accuracy is validated using questionnaires.validators.validate_accuracy. questionnaires.validators.validate_schema is also extended, so fields can be validated using validation functions.

When should this PR be merged

Should go into the sprint 20 release.

Risks

None.

Follow-up actions

The rendering of accuracyThreshold into XForms needs to be verified using GeoODK.

Checklist (for reviewing)

General

  • Is this PR explained thoroughly? All code changes must be accounted for in the PR description.
    • Review 1
    • Review 2
  • Is the PR labeled correctly? It should have the migration label if a new migration is added.
    • Review 1
    • Review 2
  • Is the risk level assessment sufficient? The risks section should contain all risks that might be introduced with the PR and which actions we need to take to mitigate these risks. Possible risks are database migrations, new libraries that need to be installed or changes to deployment scripts.
    • Review 1
    • Review 2

Functionality

  • Are all requirements met? Compare implemented functionality with the requirements specification.
    • Review 1
    • Review 2
  • Does the UI work as expected? There should be no Javascript errors in the console; all resources should load. There should be no unexpected errors. Deliberately try to break the feature to find out if there are corner cases that are not handled.
    • Review 1
    • Review 2

Code

  • Do you fully understand the introduced changes to the code? If not ask for clarification, it might uncover ways to solve a problem in a more elegant and efficient way.
    • Review 1
    • Review 2
  • Does the PR introduce any inefficient database requests? Use the debug server to check for duplicate requests.
    • Review 1
    • Review 2
  • Are all necessary strings marked for translation? All strings that are exposed to users via the UI must be marked for translation.
    • Review 1
    • Review 2
  • Is the code documented sufficiently? Large and complex classes, functions or methods must be annotated with comments following our code-style guidelines.
    • Review 1
    • Review 2
  • Has the scalability of this change been evaluated?
    • Review 1
    • Review 2
  • Is there a maintenance plan in place?
    • Review 1
    • Review 2

Tests

  • Are there sufficient test cases? Ensure that all components are tested individually; models, forms, and serializers should be tested in isolation even if a test for a view covers these components.
    • Review 1
    • Review 2
  • If this is a bug fix, are tests for the issue in place? There must be a test case for the bug to ensure the issue won’t regress. Make sure that the tests break without the new code to fix the issue.
    • Review 1
    • Review 2
  • If this is a new feature or a significant change to an existing feature? has the manual testing spreadsheet been updated with instructions for manual testing?
    • Review 1
    • Review 2

Security

  • Confirm this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets.
    • Review 1
    • Review 2
  • Are all UI and API inputs run through forms or serializers?
    • Review 1
    • Review 2
  • Are all external inputs validated and sanitized appropriately?
    • Review 1
    • Review 2
  • Does all branching logic have a default case?
    • Review 1
    • Review 2
  • Does this solution handle outliers and edge cases gracefully?
    • Review 1
    • Review 2
  • Are all external communications secured and restricted to SSL?
    • Review 1
    • Review 2

Documentation

  • Are changes to the UI documented in the platform docs? If this PR introduces new platform site functionality or changes existing ones, the changes must be documented in the Cadasta Platform Documentation.
    • Review 1
    • Review 2
  • Are changes to the API documented in the API docs? If this PR introduces new API functionality or changes existing ones, the changes must be documented in the API docs.
    • Review 1
    • Review 2
  • Are reusable components documented? If this PR introduces components that are relevant to other developers (for instance a mixin for a view or a generic form) they should be documented in the Wiki.
    • Review 1
    • Review 2

Copy link
Contributor

@seav seav left a comment

Choose a reason for hiding this comment

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

This is a solid piece of work! I only have one inline code comment. Aside from that I have the following questions:

  1. Does pyxform validate that accuracyThreshold is only present on geo fields? I don't think it makes sense for us to reject XLSForms that have invalid values for accuracyThreshold on non-geo fields. If pyxform doesn't support this validation, should we build it ourselves?
  2. For the manual test cases, I suppose we should add test cases for attempting to upload XLSForms with valid and various invalid values (like -1.5, 0, and STRING).

@@ -45,6 +63,10 @@ def test_validate_id_string_contains_whitespace(self):
"'id_string' cannot be blank or contain whitespace.")


def positive(val):
return val > 1
Copy link
Contributor

Choose a reason for hiding this comment

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

The function name doesn't seem to match the condition. Should this be val > 0? (But this is admittedly inconsequential in the grand scheme of things.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed that.

@oliverroick
Copy link
Member Author

Does pyxform validate that accuracyThreshold is only present on geo fields? I don't think it makes sense for us to reject XLSForms that have invalid values for accuracyThreshold on non-geo fields. If pyxform doesn't support this validation, should we build it ourselves?

pyxform does not check if accuracyThreshold is only present on geo fields. I agree that it probably makes sense to only validate those for geometry fields. I'll work on it tomorrow.

For the manual test cases, I suppose we should add test cases for attempting to upload XLSForms with valid and various invalid values (like -1.5, 0, and STRING).

Sounds about right.

@oliverroick
Copy link
Member Author

@seav I added code to make sure accuracyThreshold is only validated on geometry fields and ignored for all other fields.

Copy link
Contributor

@seav seav left a comment

Choose a reason for hiding this comment

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

Just a couple of spelling errors and this should be good to go from my end. :)

assert model.gps_accuracy == 1.5

def test_create_from_dict_ingnore_accuracy_threshold(self):
"""For non-geomtrey fields accuracy should be ignored"""
Copy link
Contributor

Choose a reason for hiding this comment

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

[MINOR] "geomtrey" should be ""geometry".

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

@@ -21,6 +21,12 @@ def test_wrong_type(self):
assert validators.validate_accuracy('Something') is False


class GpsRelevvantTest(TestCase):
Copy link
Contributor

Choose a reason for hiding this comment

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

[MINOR] Relevvant should be Relevant.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

@seav
Copy link
Contributor

seav commented Aug 11, 2017

(Weird. I check items on the review checklist but they aren't persistent...)

@oliverroick
Copy link
Member Author

(Weird. I check items on the review checklist but they aren't persistent...)

It seems to only work for bugs for some reason...

@alukach
Copy link
Contributor

alukach commented Aug 11, 2017

Sorry about the delay, will attempt to get to this over the weekend.

return json.get('type') in XFORM_GEOM_FIELDS


def validate_id_string(json):
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: json doesn't feel like an appropriate name for this field as JSON is a str and these are obviously dict instances. Maybe just data? 🤷‍♂️

Copy link
Contributor

Choose a reason for hiding this comment

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

I see that this is done elsewhere. Maybe it's our convention and we should leave as is.

@amplifi amplifi force-pushed the feature/gps-accuracy branch from 28a97ba to 4d9fd1e Compare August 15, 2017 22:44
@amplifi amplifi merged commit 0cf53b3 into master Aug 15, 2017
@amplifi amplifi deleted the feature/gps-accuracy branch August 15, 2017 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants