overpass as class
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 2m4s
Run linting on the backend code / Build (pull_request) Successful in 29s
Run testing on the backend code / Build (pull_request) Failing after 4m39s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 24s

This commit is contained in:
2025-01-23 16:02:33 +01:00
parent 1cc935fb34
commit 577ee232fc
5 changed files with 134 additions and 126 deletions

View File

@@ -8,13 +8,12 @@ from ..structs.preferences import Preferences
from ..structs.landmark import Landmark
from .take_most_important import take_most_important
from .cluster_manager import ClusterManager
from ..overpass.overpass import build_query, send_query
from ..overpass.caching_strategy import CachingStrategy
from ..overpass.overpass import Overpass
from ..constants import AMENITY_SELECTORS_PATH, LANDMARK_PARAMETERS_PATH, OPTIMIZER_PARAMETERS_PATH, OSM_CACHE_DIR
# silence the overpass logger
logging.getLogger('overpass').setLevel(level=logging.CRITICAL)
logging.getLogger('Overpass').setLevel(level=logging.CRITICAL)
class LandmarkManager:
@@ -56,7 +55,8 @@ class LandmarkManager:
self.walking_speed = parameters['average_walking_speed']
self.detour_factor = parameters['detour_factor']
CachingStrategy.use('XML', cache_dir=OSM_CACHE_DIR)
# Setup the caching in the Overpass class.
self.overpass = Overpass(caching_strategy='XML', cache_dir=OSM_CACHE_DIR)
self.logger.info('LandmakManager successfully initialized.')
@@ -189,15 +189,15 @@ class LandmarkManager:
for sel in dict_to_selector_list(amenity_selector):
# self.logger.debug(f"Current selector: {sel}")
element_types = ['way', 'relation']
osm_types = ['way', 'relation']
if 'viewpoint' in sel :
query_conditions = []
element_types.append('node')
osm_types.append('node')
query = build_query(
query = self.overpass.build_query(
area = bbox,
element_types = element_types,
osm_types = osm_types,
selector = sel,
conditions = query_conditions, # except for nature....
out = 'center'
@@ -205,7 +205,7 @@ class LandmarkManager:
self.logger.debug(f"Query: {query}")
try:
result = send_query(query)
result = self.overpass.send_query(query)
except Exception as e:
self.logger.error(f"Error fetching landmarks: {e}")
continue