From dbc87064ad04803ca877b1aa1ca670e52f007e1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Steinr=C3=BCcken?= Date: Tue, 14 May 2019 17:25:26 +0200 Subject: [PATCH 1/2] Correctly calculate spatialGuaranteedCorrectness on sparse maps It currently returns a too small gurantee if the sweepline hits fewer points in one direction than requested (ie. it runs out of the map) --- CHANGELOG.md | 4 ++++ bones/spatialBone.py | 15 ++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37a791f..c1d5408 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ This file documents any relevant changes done to ViUR server since version 2. ## [develop] - Current development version +### Fixed +- spatialGuaranteedCorrectness on very sparse maps ([#165](https://github.com/viur-framework/server/pull/165)) + + ## [2.4.0] Agung - 2019-05-17 diff --git a/bones/spatialBone.py b/bones/spatialBone.py index ef49943..737119f 100644 --- a/bones/spatialBone.py +++ b/bones/spatialBone.py @@ -238,14 +238,15 @@ def customMultiQueryMerge(self, name, lat, lng, dbFilter, result, targetAmount): # If a result further away than this distance there might be missing results before that result # If there are no results in a give lane (f.e. because we are close the border and there is no point # in between) we choose a arbitrary large value for that lower bound + expectedAmount = self.calculateInternalMultiQueryAmount(targetAmount) # How many items we expect in each direction limits = [ - haversine(latRight[-1][name+".lat.val"], lng, lat, lng) if latRight else 2^31, # Lat - Right Side - haversine(latLeft[-1][name+".lat.val"], lng, lat, lng) if latLeft else 2^31, # Lat - Left Side - haversine(lat, lngBottom[-1][name+".lng.val"], lat, lng) if lngBottom else 2^31, # Lng - Bottom - haversine(lat, lngTop[-1][name+".lng.val"], lat, lng) if lngTop else 2^31, # Lng - Top - haversine(lat+gridSizeLat,lng,lat,lng), - haversine(lat,lng+gridSizeLng,lat,lng) - ] + haversine(latRight[-1][name + ".lat.val"], lng, lat, lng) if latRight and len(latRight) == expectedAmount else 2 ^ 31, # Lat - Right Side + haversine(latLeft[-1][name + ".lat.val"], lng, lat, lng) if latLeft and len(latLeft) == expectedAmount else 2 ^ 31, # Lat - Left Side + haversine(lat, lngBottom[-1][name + ".lng.val"], lat, lng) if lngBottom and len(lngBottom) == expectedAmount else 2 ^ 31, # Lng - Bottom + haversine(lat, lngTop[-1][name + ".lng.val"], lat, lng) if lngTop and len(lngTop) == expectedAmount else 2 ^ 31, # Lng - Top + haversine(lat + gridSizeLat, lng, lat, lng), + haversine(lat, lng + gridSizeLng, lat, lng) + ] dbFilter.customQueryInfo["spatialGuaranteedCorrectness"] = min(limits) logging.debug("SpatialGuaranteedCorrectness: %s", dbFilter.customQueryInfo["spatialGuaranteedCorrectness"]) # Filter duplicates From 57dbc128164c63ca85c976788fcdb3375cdf8cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Steinr=C3=BCcken?= Date: Fri, 17 May 2019 11:26:59 +0200 Subject: [PATCH 2/2] Fixed incorrect expression of pow(2,31), Updated Changelog --- CHANGELOG.md | 2 +- bones/spatialBone.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1d5408..c4e3da2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ This file documents any relevant changes done to ViUR server since version 2. ## [develop] - Current development version ### Fixed -- spatialGuaranteedCorrectness on very sparse maps ([#165](https://github.com/viur-framework/server/pull/165)) +- spatialGuaranteedCorrectness of bones/spatial on very sparse maps ([#167](https://github.com/viur-framework/server/pull/167)) diff --git a/bones/spatialBone.py b/bones/spatialBone.py index 737119f..04b5bb4 100644 --- a/bones/spatialBone.py +++ b/bones/spatialBone.py @@ -240,10 +240,10 @@ def customMultiQueryMerge(self, name, lat, lng, dbFilter, result, targetAmount): # in between) we choose a arbitrary large value for that lower bound expectedAmount = self.calculateInternalMultiQueryAmount(targetAmount) # How many items we expect in each direction limits = [ - haversine(latRight[-1][name + ".lat.val"], lng, lat, lng) if latRight and len(latRight) == expectedAmount else 2 ^ 31, # Lat - Right Side - haversine(latLeft[-1][name + ".lat.val"], lng, lat, lng) if latLeft and len(latLeft) == expectedAmount else 2 ^ 31, # Lat - Left Side - haversine(lat, lngBottom[-1][name + ".lng.val"], lat, lng) if lngBottom and len(lngBottom) == expectedAmount else 2 ^ 31, # Lng - Bottom - haversine(lat, lngTop[-1][name + ".lng.val"], lat, lng) if lngTop and len(lngTop) == expectedAmount else 2 ^ 31, # Lng - Top + haversine(latRight[-1][name + ".lat.val"], lng, lat, lng) if latRight and len(latRight) == expectedAmount else 2 ** 31, # Lat - Right Side + haversine(latLeft[-1][name + ".lat.val"], lng, lat, lng) if latLeft and len(latLeft) == expectedAmount else 2 ** 31, # Lat - Left Side + haversine(lat, lngBottom[-1][name + ".lng.val"], lat, lng) if lngBottom and len(lngBottom) == expectedAmount else 2 ** 31, # Lng - Bottom + haversine(lat, lngTop[-1][name + ".lng.val"], lat, lng) if lngTop and len(lngTop) == expectedAmount else 2 ** 31, # Lng - Top haversine(lat + gridSizeLat, lng, lat, lng), haversine(lat, lng + gridSizeLng, lat, lng) ]