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

Geocoding location lookup #4

Merged
merged 24 commits into from
Aug 3, 2018
Merged

Geocoding location lookup #4

merged 24 commits into from
Aug 3, 2018

Conversation

hxtk
Copy link

@hxtk hxtk commented Aug 3, 2018

This resolves issue #1 . There are some known bugs that may or may not cause realistic edge cases, but in general this functionality works and the old functionality remains for backwards compatibility.

While my classes function, I have not done integration testing for the bot module.

hxtk and others added 24 commits August 1, 2018 12:32
I've made it so that we can look up locations and fetch the closest station.
This adds a dependency of `geopy`.
This ignores several edge cases. Namely, it assumes a flat earth with rectangular coordinates corresponding to the latitude and longitude. I am assuming these edge cases will not be noticeable.

Expected behavior:
```
user: !noaa tide 8722588
scubot: <a listing for station #8722588>

user: !noaa tide 32.8548228,-79.9614
I improved the regular expression for matching latitude/longitude coordinate pairs to remove an edge case where they were separated by only a comma and no space.

To continue the expected behavior listing on the previous commit:

```
user: !noaa tide 8722588
scubot: <listing for station #8722588>

user: !noaa tide "33.6926725,-78.8841985"
scubot: <listing for station #8661000, Myrtle Beach, SC>

user: !noaa tide "Myrtle Beach, SC"
scubot: <listing for station #8661000, Myrtle Beach, SC>
```
Static methods decorated with `@staticmethod` aren't attached to a class instance and therefore aren't (and indeed can't be) passed a reference to `self`
I've found the NOAA website's listing for the latitude and longitude of their stations. This removes a great deal of strain from the geocoding API, which is good because our initial fetch was extremely taxing on the geocoder.

It will still be necessary to merge this branch with the branch that has database caching, as NOAA's response times result in the globe taking several hours to initialize.
Adding basic station caching
Geocoding from NOAA instead of nominatim
The object structure prior to this change did not make it easy to isolate the `StationGlobe` class, whether for testing or prefetching the database cache. I have separated it using dependency injection patterns.

NOTE: This breaks the initialization on L150. Waiting for @suclearnub to provide more information on the NOAA.module_db object scope to fix that
Fix initialization of the updated `StationGlobe` object from the previous commit.
Also I've moved the work into a method to eliminate import side effects.
TinyDB was incompatible with the `Station` object so I created serialization methods to convert between it and a standard Python dictionary.
Scraper was parsing latitude and longitude incorrectly.
Search always returned the last station, regardless of which one was closest.

Both of those issues have been resolved in this commit.
@the-emerald the-emerald changed the base branch from master to geo August 3, 2018 16:33
@the-emerald the-emerald merged commit 15963a5 into scubot:geo Aug 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants