Conversation
d48b350 to
d096aea
Compare
TimMcCauley
left a comment
There was a problem hiding this comment.
@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.
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.
The folder structure for testing the osm files is invalid. See "/openpoiservice/tests/base.py#L21"
Corrected space distance
|
|
||
| geocoder = None | ||
| geocode_categories = None | ||
| if ops_settings['geocoder'] is not None: |
There was a problem hiding this comment.
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.
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() |
| 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.
try-except like in the array call in the following lines?
| geocode_categories[id] = {} | ||
|
|
||
| return geocode_categories | ||
|
|
There was a problem hiding this comment.
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): | |||
|
|
|||
| 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.
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.
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() |
| geocode_categories = CategoryTools('categories.yml').generate_geocode_categories() | ||
|
|
||
|
|
||
| if "TESTING" in os.environ: |
There was a problem hiding this comment.
Here you have to decide if you replace the strings. I think this is a one time call so just leave it like that.
MichaelsJP
left a comment
There was a problem hiding this comment.
Top. Good coding style! Here a 🥔 for you...
82cf49c to
f5995f2
Compare
[WP] Add AddressObject() in objects.py