Skip to content

Commit

Permalink
Revert "Improve coordinate checks"
Browse files Browse the repository at this point in the history
  • Loading branch information
dalepotter committed Jun 2, 2017
1 parent 93c863f commit c03095e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 58 deletions.
Binary file removed .coverage
Binary file not shown.
1 change: 0 additions & 1 deletion gitdate.json

This file was deleted.

15 changes: 4 additions & 11 deletions stats/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,20 +243,13 @@ def valid_value(value_element):


def valid_coords(x):
try:
coords = x.split(' ')
except AttributeError:
return False
coords = x.split(' ')
if len(coords) != 2:
return False
try:
lat = decimal.Decimal(coords[0])
lng = decimal.Decimal(coords[1])
# the (0, 0) coordinate is invalid since it's in the ocean in international waters and near-certainly not actual data
if lat == 0 and lng == 0:
return False
# values outside the valid (lat, lng) coordinate space are invalid
elif lat < -90 or lat > 90 or lng < -180 or lng > 180:
x = decimal.Decimal(coords[0])
y = decimal.Decimal(coords[1])
if x == 0 and y ==0:
return False
else:
return True
Expand Down
47 changes: 1 addition & 46 deletions stats/tests/test_valid_functions.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,6 @@
from stats.dashboard import valid_coords, valid_date, valid_url, valid_value
from stats.dashboard import valid_date, valid_url, valid_value
from lxml import etree

def test_valid_coords():
"""
Check that coordinates for a location on Earth are correctly detected as valid or not.
Coordinates are located within an `iati-activity/location/point/pos`, though the validity function takes only the text.
Note:
The `(0, 0)` coordinate is permitted data against the IATI Standard, though is deemed invalid for Stats purposes since there is no reasonable reason an Activity would be undertaken there - it's in international waters in the ocean.
"""
# empty values
assert not valid_coords(etree.fromstring('<pos/>').text)
assert not valid_coords(etree.fromstring('<pos />').text)
assert not valid_coords(etree.fromstring('<pos></pos>').text)
assert not valid_coords(etree.fromstring('<pos> </pos>').text)
# incorrect spacing
assert not valid_coords(etree.fromstring('<pos> 1 2 </pos>').text)
assert not valid_coords(etree.fromstring('<pos> 1 2</pos>').text)
assert not valid_coords(etree.fromstring('<pos>1 2 </pos>').text)
# invalid characters
assert not valid_coords(etree.fromstring('<pos>a b</pos>').text)
assert not valid_coords(etree.fromstring('<pos>one two</pos>').text)
# incorrect number of values
assert not valid_coords(etree.fromstring('<pos>1</pos>').text)
assert not valid_coords(etree.fromstring('<pos>1 2 3</pos>').text)
assert not valid_coords(etree.fromstring('<pos>1 2.3 4</pos>').text)
# beyond boundary values
assert not valid_coords(etree.fromstring('<pos>-90.00001 -180.00001</pos>').text)
assert not valid_coords(etree.fromstring('<pos>-90.00001 180.00001</pos>').text)
assert not valid_coords(etree.fromstring('<pos>90.00001 -180.00001</pos>').text)
assert not valid_coords(etree.fromstring('<pos>90.00001 180.00001</pos>').text)
# value deemed invalid for Stats purposes (though valid against the Standard)
assert not valid_coords(etree.fromstring('<pos>0 0</pos>').text)

# general permitted values
assert valid_coords(etree.fromstring('<pos>1 2</pos>').text)
assert valid_coords(etree.fromstring('<pos>1.2 2.3</pos>').text)
assert valid_coords(etree.fromstring('<pos>1.23456789 2.34567890</pos>').text)
assert valid_coords(etree.fromstring('<pos>-1.2 -2.3</pos>').text)
assert valid_coords(etree.fromstring('<pos>-1.23456789 -2.34567890</pos>').text)
# boundary values
assert valid_coords(etree.fromstring('<pos>-90 -180</pos>').text)
assert valid_coords(etree.fromstring('<pos>-90 180</pos>').text)
assert valid_coords(etree.fromstring('<pos>90 -180</pos>').text)
assert valid_coords(etree.fromstring('<pos>90 180</pos>').text)

def test_valid_date():
assert not valid_date(etree.XML('<activity-date iso-date=""/>'))
assert valid_date(etree.XML('<activity-date iso-date="2014-01-01"/>'))
Expand Down

0 comments on commit c03095e

Please sign in to comment.