Mike-Heneghan / ALISS

ALISS (A Local Information System for Scotland) is a service to help you find help and support close to you when you need it most.
https://aliss.org
0 stars 0 forks source link

Look into issue with postcode district not found #116

Closed Mike-Heneghan closed 4 years ago

Mike-Heneghan commented 4 years ago
Internal Server Error: /search/

AttributeError at /search/ ‘NoneType’ object has no attribute ‘latitude’

Issues with one of the postcode districts.

Mike-Heneghan commented 4 years ago

Realised that there are occasions where the Postcode get_by_district method returns no results.

We have the average latitude and longitude (centroid) and we are then trying to find the nearest point (postcode) to this centroid.

Currently, I think there can be situations where the average point has a latitude or longitude which is less than any of the points. In these circumstances, the query returns no results.

As a fallback, I added a condition to check the length of the query result and check it it greater than zero.

If it is not greater than equal I would search by greater than the average point to try to find results in there.

Although I think there might be four potential orderings in which the result might be.

Mike-Heneghan commented 4 years ago

https://www.gbmaps.com/4-digit-postcode-maps/postcode-district-pdf-maps/iv-inverness-postcode-district-map.pdf

The shape of postcode districts and clustering of postcodes within a district leads to situations where the district has no postcodes with less than or equal to latitudes and longitudes of the average point.

Mike-Heneghan commented 4 years ago

From discussions today it was decided that going forward as an enhancement to the postcode district search after the average latitude and longitude has been calculated fro the district the closest points in each quadrant i.e. (lte, lte) (lte, gte), (gte, lte), (gte, gte) will be found and the one with the closest Euclidean distance to the average point selected and returned.

This process should have the advantage of being more resilient as a postcode point should definitely be found and it should be closer to the logical centre based on density of postcodes.

Mike-Heneghan commented 4 years ago

Noticed an issue with an error searching a similar postcode district which also wasn't supported. On this occasion, it appears to be because the postcode district is no longer in use although I think we might need to add better error handling.

Mike-Heneghan commented 4 years ago

Updated the code to pick the closest point un each quadrant and then measure the distance to the central point. Manually testing with google maps.

Screenshot 2019-11-15 at 12 35 07
Mike-Heneghan commented 4 years ago

Test with the G83 postcode district which has an unusual shape but is likely to have different concentrations of postcode.

Screenshot 2019-11-15 at 12 57 26
Mike-Heneghan commented 4 years ago

Noticed an issue with an error searching a similar postcode district which also wasn't supported. On this occasion, it appears to be because the postcode district is no longer in use although I think we might need to add better error handling.

Found the error to be raised syntax wasn't correct so rather than returning "Postcode not supported" we were getting a 500 error.

Mike-Heneghan commented 4 years ago

Merged