first changes

This commit is contained in:
Helldragon67 2024-08-04 11:32:53 +02:00
parent db82495f11
commit 8a62e68ddd
3 changed files with 44 additions and 24 deletions

View File

@ -1,6 +1,6 @@
city_bbox_side: 5000 #m city_bbox_side: 5000 #m
radius_close_to: 50 radius_close_to: 50
church_coeff: 0.8 church_coeff: 0.8
park_coeff: 1.2 park_coeff: 1.0
tag_coeff: 10 tag_coeff: 10
N_important: 40 N_important: 40

View File

@ -14,7 +14,7 @@ logger = logging.getLogger(__name__)
def test(start_coords: tuple[float, float], finish_coords: tuple[float, float] = None) -> list[Landmark]: def test(start_coords: tuple[float, float], finish_coords: tuple[float, float] = None) -> list[Landmark]:
manager = LandmarkManager()
optimizer = Optimizer() optimizer = Optimizer()
refiner = Refiner(optimizer=optimizer) refiner = Refiner(optimizer=optimizer)
@ -23,7 +23,7 @@ def test(start_coords: tuple[float, float], finish_coords: tuple[float, float] =
sightseeing=Preference( sightseeing=Preference(
name='sightseeing', name='sightseeing',
type='sightseeing', type='sightseeing',
score = 5), score = 3),
nature=Preference( nature=Preference(
name='nature', name='nature',
type='nature', type='nature',
@ -33,10 +33,12 @@ def test(start_coords: tuple[float, float], finish_coords: tuple[float, float] =
type='shopping', type='shopping',
score = 5), score = 5),
max_time_minute=180, max_time_minute=120,
detour_tolerance_minute=30 detour_tolerance_minute=30
) )
manager = LandmarkManager(max_time = preferences.max_time_minute + preferences.detour_tolerance_minute)
# Create start and finish # Create start and finish
if finish_coords is None : if finish_coords is None :
finish_coords = start_coords finish_coords = start_coords
@ -81,5 +83,8 @@ def test(start_coords: tuple[float, float], finish_coords: tuple[float, float] =
# test(tuple((48.8375946, 2.2949904))) # Point random # test(tuple((48.8375946, 2.2949904))) # Point random
# test(tuple((47.377859, 8.540585))) # Zurich HB # test(tuple((47.377859, 8.540585))) # Zurich HB
# test(tuple((45.7576485, 4.8330241))) # Lyon Bellecour # test(tuple((45.7576485, 4.8330241))) # Lyon Bellecour
test(tuple((48.5848435, 7.7332974))) # Strasbourg Gare # test(tuple((48.5848435, 7.7332974))) # Strasbourg Gare
# test(tuple((48.2067858, 16.3692340))) # Vienne # test(tuple((48.2067858, 16.3692340))) # Vienne
# test(tuple((46.996625, 6.935716))) # Neuchatel
# test(tuple((35.897243, 15.511951))) # La Valette
test(tuple((46.51724716185816, 6.629345889640165))) # Lausanne

View File

@ -33,20 +33,29 @@ class LandmarkManager:
N_important: int # number of important landmarks to consider N_important: int # number of important landmarks to consider
def __init__(self) -> None: def __init__(self, max_time: int) -> None:
with constants.AMENITY_SELECTORS_PATH.open('r') as f: with constants.AMENITY_SELECTORS_PATH.open('r') as f:
self.amenity_selectors = yaml.safe_load(f) self.amenity_selectors = yaml.safe_load(f)
with constants.LANDMARK_PARAMETERS_PATH.open('r') as f: with constants.LANDMARK_PARAMETERS_PATH.open('r') as f:
parameters = yaml.safe_load(f) parameters = yaml.safe_load(f)
self.city_bbox_side = parameters['city_bbox_side'] max_bbox_side = parameters['city_bbox_side']
self.radius_close_to = parameters['radius_close_to'] self.radius_close_to = parameters['radius_close_to']
self.church_coeff = parameters['church_coeff'] self.church_coeff = parameters['church_coeff']
self.park_coeff = parameters['park_coeff'] self.park_coeff = parameters['park_coeff']
self.tag_coeff = parameters['tag_coeff'] self.tag_coeff = parameters['tag_coeff']
self.N_important = parameters['N_important'] self.N_important = parameters['N_important']
with constants.OPTIMIZER_PARAMETERS_PATH.open('r') as f:
parameters = yaml.safe_load(f)
speed = parameters['average_walking_speed']
detour = parameters['detour_factor']
max_walk_dist = (max_time/2)/60*speed*1000/detour
self.city_bbox_side = min(max_walk_dist, max_bbox_side)
self.overpass = Overpass() self.overpass = Overpass()
CachingStrategy.use(JSON, cacheDir=constants.OSM_CACHE_DIR) CachingStrategy.use(JSON, cacheDir=constants.OSM_CACHE_DIR)
@ -72,22 +81,22 @@ class LandmarkManager:
L = [] L = []
bbox = self.create_bbox(center_coordinates) bbox = self.create_bbox(center_coordinates)
# list for sightseeing # list for sightseeing
if preferences.sightseeing.score != 0: if preferences.sightseeing.score != 0: # self.count_elements_close_to(loc) +
score_function = lambda loc, n_tags: int((self.count_elements_close_to(loc) + ((n_tags**1.2)*self.tag_coeff) )*self.church_coeff) score_function = lambda loc, n_tags: int((((n_tags**1.2)*self.tag_coeff) )*self.church_coeff)
L1 = self.fetch_landmarks(bbox, self.amenity_selectors['sightseeing'], SIGHTSEEING, score_function) L1 = self.fetch_landmarks(bbox, self.amenity_selectors['sightseeing'], SIGHTSEEING, score_function)
self.correct_score(L1, preferences.sightseeing) self.correct_score(L1, preferences.sightseeing)
L += L1 L += L1
# list for nature # list for nature
if preferences.nature.score != 0: if preferences.nature.score != 0:
score_function = lambda loc, n_tags: int((self.count_elements_close_to(loc) + ((n_tags**1.2)*self.tag_coeff) )*self.park_coeff) score_function = lambda loc, n_tags: int((((n_tags**1.2)*self.tag_coeff) )*self.park_coeff)
L2 = self.fetch_landmarks(bbox, self.amenity_selectors['nature'], NATURE, score_function) L2 = self.fetch_landmarks(bbox, self.amenity_selectors['nature'], NATURE, score_function)
self.correct_score(L2, preferences.nature) self.correct_score(L2, preferences.nature)
L += L2 L += L2
# list for shopping # list for shopping
if preferences.shopping.score != 0: if preferences.shopping.score != 0:
score_function = lambda loc, n_tags: int(self.count_elements_close_to(loc) + ((n_tags**1.2)*self.tag_coeff)) score_function = lambda loc, n_tags: int(((n_tags**1.2)*self.tag_coeff))
L3 = self.fetch_landmarks(bbox, self.amenity_selectors['shopping'], SHOPPING, score_function) L3 = self.fetch_landmarks(bbox, self.amenity_selectors['shopping'], SHOPPING, score_function)
self.correct_score(L3, preferences.shopping) self.correct_score(L3, preferences.shopping)
L += L3 L += L3
@ -296,20 +305,26 @@ class LandmarkManager:
break break
if "wikipedia" in tag: if "wikipedia" in tag:
n_tags += 3 # wikipedia entries count more n_tags += 1 # wikipedia entries count more
if tag == "wikidata": if "viewpoint" in tag:
Q = elem.tag('wikidata') n_tags += 10 # wikipedia entries count more
site = Site("wikidata", "wikidata")
item = ItemPage(site, Q) # if tag == "wikidata":
item.get() # Q = elem.tag('wikidata')
n_languages = len(item.labels) # site = Site("wikidata", "wikidata")
n_tags += n_languages/10 # item = ItemPage(site, Q)
# item.get()
# n_languages = len(item.labels)
# n_tags += n_languages/10
if elem_type != "nature": if elem_type != "nature":
if "leisure" in tag and elem.tag('leisure') == "park": if "leisure" in tag and elem.tag('leisure') == "park":
elem_type = "nature" elem_type = "nature"
if elem_type == "nature":
n_tags += 1
if landmarktype != SHOPPING: if landmarktype != SHOPPING:
if "shop" in tag: if "shop" in tag:
skip = True skip = True