better array handling in the optimizer
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Failing after 2m39s
Build and deploy the backend to staging / Deploy to staging (pull_request) Has been skipped
Run linting on the backend code / Build (pull_request) Successful in 25s
Run testing on the backend code / Build (pull_request) Failing after 1m37s

This commit is contained in:
2025-01-14 11:59:23 +01:00
parent 41976e3e85
commit 4fae658dbb
6 changed files with 366 additions and 280 deletions

View File

@@ -1,3 +1,4 @@
"""Module used to import data from OSM and arrange them in categories."""
import math, yaml, logging
from OSMPythonTools.overpass import Overpass, overpassQueryBuilder
from OSMPythonTools.cachingStrategy import CachingStrategy, JSON
@@ -79,7 +80,7 @@ class LandmarkManager:
# Create a bbox using the around technique
bbox = tuple((f"around:{reachable_bbox_side/2}", str(center_coordinates[0]), str(center_coordinates[1])))
# list for sightseeing
if preferences.sightseeing.score != 0:
score_function = lambda score: score * 10 * preferences.sightseeing.score / 5
@@ -101,7 +102,7 @@ class LandmarkManager:
if preferences.shopping.score != 0:
score_function = lambda score: score * 10 * preferences.shopping.score / 5
current_landmarks = self.fetch_landmarks(bbox, self.amenity_selectors['shopping'], preferences.shopping.type, score_function)
# set time for all shopping activites :
for landmark in current_landmarks : landmark.duration = 30
all_landmarks.update(current_landmarks)
@@ -110,7 +111,7 @@ class LandmarkManager:
shopping_manager = ClusterManager(bbox, 'shopping')
shopping_clusters = shopping_manager.generate_clusters()
all_landmarks.update(shopping_clusters)
landmarks_constrained = take_most_important(all_landmarks, self.N_important)
@@ -152,7 +153,7 @@ class LandmarkManager:
elementType=['node', 'way', 'relation']
)
try:
try:
radius_result = self.overpass.query(radius_query)
N_elem = radius_result.countWays() + radius_result.countRelations()
self.logger.debug(f"There are {N_elem} ways/relations within 50m")
@@ -242,28 +243,28 @@ class LandmarkManager:
name = elem.tag('name')
location = (elem.centerLat(), elem.centerLon())
osm_type = elem.type() # Add type: 'way' or 'relation'
osm_id = elem.id() # Add OSM id
osm_id = elem.id() # Add OSM id
# TODO: exclude these from the get go
# handle unprecise and no-name locations
if name is None or location[0] is None:
if osm_type == 'node' and 'viewpoint' in elem.tags().values():
if osm_type == 'node' and 'viewpoint' in elem.tags().values():
name = 'Viewpoint'
name_en = 'Viewpoint'
location = (elem.lat(), elem.lon())
else :
else :
continue
# skip if part of another building
if 'building:part' in elem.tags().keys() and elem.tag('building:part') == 'yes':
continue
elem_type = landmarktype # Add the landmark type as 'sightseeing,
elem_type = landmarktype # Add the landmark type as 'sightseeing,
n_tags = len(elem.tags().keys()) # Add number of tags
score = n_tags**self.tag_exponent # Add score
duration = 5 # Set base duration to 5 minutes
skip = False # Set skipping parameter to false
tag_values = set(elem.tags().values()) # Store tag values
tag_values = set(elem.tags().values()) # Store tag values
# Retrieve image, name and website :
@@ -275,7 +276,7 @@ class LandmarkManager:
if elem_type != "nature" and elem.tag('leisure') == "park":
elem_type = "nature"
if elem.tag('wikipedia') is not None :
score += self.wikipedia_bonus
@@ -309,9 +310,9 @@ class LandmarkManager:
# continue
score = score_function(score)
if "place_of_worship" in tag_values :
if 'cathedral' in tag_values :
if 'cathedral' in tag_values :
duration = 10
else :
score *= self.church_coeff
@@ -319,7 +320,7 @@ class LandmarkManager:
elif 'viewpoint' in tag_values :
# viewpoints must count more
score = score * self.viewpoint_bonus
elif "museum" in tag_values or "aquarium" in tag_values or "planetarium" in tag_values:
duration = 60
@@ -339,7 +340,7 @@ class LandmarkManager:
website_url = website_url
)
return_list.append(landmark)
self.logger.debug(f"Fetched {len(return_list)} landmarks of type {landmarktype} in {bbox}")
return return_list