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

Enhancement #2 address details option #58

Open
wants to merge 8 commits into
base: development
Choose a base branch
from

Conversation

isikl
Copy link
Contributor

@isikl isikl commented Jan 23, 2019

[WP] Add AddressObject() in objects.py

@isikl isikl force-pushed the enhancement-#2-address-details-option branch from d48b350 to d096aea Compare January 23, 2019 15:02
Copy link
Contributor

@TimMcCauley TimMcCauley left a comment

Choose a reason for hiding this comment

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

@isikl so far so good - we are slowly getting there. Can you implement some logic somewhere around https://github.com/GIScience/openpoiservice/blob/master/openpoiservice/server/db_import/parser.py#L19 where the service checks initially if addresses should be imported? the rest of the logic will depend on the flag set there.

openpoiservice/server/db_import/models.py Outdated Show resolved Hide resolved
openpoiservice/server/db_import/parse_osm.py Outdated Show resolved Hide resolved
openpoiservice/server/db_import/objects.py Outdated Show resolved Hide resolved
@isikl
Copy link
Contributor Author

isikl commented Feb 11, 2019

I guess kind of the problem is the bbox in the database query. Takes coordinates for Heidelberg, but POIs are requested for Bremen, too. Using a large enough bbox manually it works fine, but coudn't figure out yet where the problem arises.

openpoiservice/server/db_import/models.py Outdated Show resolved Hide resolved
openpoiservice/server/db_import/objects.py Outdated Show resolved Hide resolved
openpoiservice/server/db_import/objects.py Outdated Show resolved Hide resolved
openpoiservice/server/db_import/objects.py Outdated Show resolved Hide resolved
openpoiservice/server/db_import/parser.py Outdated Show resolved Hide resolved
@isikl isikl requested a review from MichaelsJP March 15, 2019 16:10
from openpoiservice.server.db_import.objects import AddressObject, GeocoderSetup
from openpoiservice.server.categories.categories import CategoryTools

# from base import BaseTestCase
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cannot find references 'BaseTestCase'. Same in other testing files. Therefore, line 10 "from openpoiservice.tests.base import BaseTestCase"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The folder structure for testing the osm files is invalid. See "/openpoiservice/tests/base.py#L21"

Corrected space distance
@@ -19,6 +20,13 @@
basedir = os.path.abspath(os.path.dirname(__file__))
ops_settings = yaml.safe_load(open(os.path.join(basedir, 'ops_settings.yml')))

geocoder = None
geocode_categories = None
if ops_settings['geocoder'] is not None:
Copy link
Member

@MichaelsJP MichaelsJP Mar 26, 2019

Choose a reason for hiding this comment

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

Generally it's better to define those recurring strings in a "static" object somewhere. In this case you could define a static settings variable class in openpoiservice.server and import it alongside the ops_settings object etc.
Another option is that you define all the config file variables you need once in the openpoiservice.server and import these instead of ops_settings.
The reason is, it will reduce complexity and coding time when you have those strings in one place. Once you change something in the config file you'll only have to adjust one variable in the openpoiservice.server file. My advice would be to follow option 2.
E.g.

  1. Solution, define a variable class holding the static variable strings:
>>> class MyConfigVariableClass:
...     geocoderSettingsVariable = 'geocoder'
...
>>> MyConfigVariableClass.geocoderSettingsVariable
'geocoder'
  1. Solution, define global variables in openpoiservice.server, assign config parameters to it and import them wherever you need them
someSettings = ops_settings['some_config_parameter']['some_sub_config_parameter']

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those strings won't be changed or modified by the user. He will just add further parameters, which will be checked the way you showed. Adjust the strings anyway?

geocoder = None
geocode_categories = None
if ops_settings['geocoder'] is not None:
geocoder = GeocoderSetup(list(ops_settings['geocoder'].items())[0]).define_geocoder()
Copy link
Member

Choose a reason for hiding this comment

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

Same here. See above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same here.

@@ -264,12 +256,24 @@ def generate_geojson_features(cls, query, limit):
}
properties["category_ids"] = category_ids_obj

# Checks if Tags are available
if q[5][0] is not None:
Copy link
Member

Choose a reason for hiding this comment

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

try-except like in the array call in the following lines?

geocode_categories[id] = {}

return geocode_categories

Copy link
Member

Choose a reason for hiding this comment

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

In general it's better to have no nested for-loops. Think about moving every for-loop to a different function...

@@ -14,9 +20,7 @@ def __init__(self, uuid, categories, osmid, lat_lng, osm_type):

Copy link
Member

Choose a reason for hiding this comment

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

Remove dead code?

def address_request(self):

# address_delaied = RateLimiter(self.geocoder.reverse, min_delay_seconds=1)
response = self.geocoder.reverse(query=self.lat_lng)
Copy link
Member

Choose a reason for hiding this comment

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

Add a try-except here to catch possible connection errors, e.g. resource not available etc.


class TestAddressBlueprint(BaseTestCase):

def test_address_request(self):
Copy link
Member

Choose a reason for hiding this comment

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

Add a test that expects a http connection error to test if it is properly returned by the function (see missing try-except above for address_request)

geocode_categories = None
if ops_settings['geocoder'] is not None:
geocoder = GeocoderSetup(list(ops_settings['geocoder'].items())[0]).define_geocoder()
geocode_categories = CategoryTools('categories.yml').generate_geocode_categories()
Copy link
Member

Choose a reason for hiding this comment

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

Same here. See above

geocoder = GeocoderSetup(list(ops_settings['geocoder'].items())[0]).define_geocoder()
geocode_categories = CategoryTools('categories.yml').generate_geocode_categories()


if "TESTING" in os.environ:
Copy link
Member

Choose a reason for hiding this comment

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

Here you have to decide if you replace the strings. I think this is a one time call so just leave it like that.

Copy link
Member

@MichaelsJP MichaelsJP left a comment

Choose a reason for hiding this comment

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

Top. Good coding style! Here a 🥔 for you...

@TimMcCauley TimMcCauley force-pushed the development branch 2 times, most recently from 82cf49c to f5995f2 Compare April 26, 2019 15:50
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.

3 participants