-
Notifications
You must be signed in to change notification settings - Fork 22
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
base: development
Are you sure you want to change the base?
Conversation
d48b350
to
d096aea
Compare
There was a problem hiding this 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.
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. |
from openpoiservice.server.db_import.objects import AddressObject, GeocoderSetup | ||
from openpoiservice.server.categories.categories import CategoryTools | ||
|
||
# from base import BaseTestCase |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
- Solution, define a variable class holding the static variable strings:
>>> class MyConfigVariableClass:
... geocoderSettingsVariable = 'geocoder'
...
>>> MyConfigVariableClass.geocoderSettingsVariable
'geocoder'
- 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']
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. See above.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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 | ||
|
There was a problem hiding this comment.
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): | |||
|
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
There was a problem hiding this 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...
82cf49c
to
f5995f2
Compare
[WP] Add AddressObject() in objects.py