Verified Commit 1809018f authored by Elger Jonker's avatar Elger Jonker

Fix #130 import using a different property, allow area/datatype changes in...

Fix #130 import using a different property, allow area/datatype changes in items for the same organization
parent 10e7fe6a
Pipeline #37110909 failed with stage
in 13 minutes and 10 seconds
......@@ -345,6 +345,16 @@ def store_updates(feature: Dict, country: str = "NL", organization_type: str = "
country=country,
type__name=organization_type,
is_dead=False)
except Organization.DoesNotExist:
log.debug("Could not find organization by property 'alt_name', trying another way.")
if not matching_organization and "localname" in properties:
try:
matching_organization = Organization.objects.get(name=properties["localname"],
country=country,
type__name=organization_type,
is_dead=False)
except Organization.DoesNotExist:
# out of options...
# This happens sometimes, as you might get areas that are outside the country or not on the map yet.
......@@ -367,7 +377,11 @@ def store_updates(feature: Dict, country: str = "NL", organization_type: str = "
# log.info("Missing boundary:administrative")
# return
old_coordinate = Coordinate.objects.filter(organization=matching_organization, is_dead=False)
if not when:
old_coordinate = Coordinate.objects.filter(organization=matching_organization, is_dead=False)
else:
old_coordinate = Coordinate.objects.filter(organization=matching_organization, is_dead=False,
created_on__lte=when)
if old_coordinate.count() == 1 and old_coordinate[0].area == coordinates["coordinates"]:
log.info("Retrieved coordinates are the same, not changing anything.")
......@@ -415,7 +429,7 @@ def get_osm_data_wambachers(country: str = "NL", organization_type: str = "munic
"""
curl -f -o NL_province.zip 'https://wambachers-osm.website/boundaries/exportBoundaries
?cliVersion=1.0
&cliKey=c0e3473f-6ba2-4571-9331-4b3084022021 done: add cliKey to config
&cliKey=[key] done: add cliKey to config
&exportFormat=json
&exportLayout=levels
&exportAreas=land
......
......@@ -1440,7 +1440,7 @@ def get_map_data(country: str = "NL", organization_type: str = "municipality", d
WHERE (stacked_coordinate.created_on <= '%(when)s' AND stacked_coordinate.is_dead = 0)
OR
('%(when)s' BETWEEN stacked_coordinate.created_on AND stacked_coordinate.is_dead_since
AND stacked_coordinate.is_dead = 1) GROUP BY area, organization_id) as coordinate_stack
AND stacked_coordinate.is_dead = 1) GROUP BY organization_id) as coordinate_stack
ON coordinate_stack.organization_id = map_organizationrating.organization_id
INNER JOIN
(SELECT MAX(id) as stacked_organizationrating_id FROM map_organizationrating
......@@ -1453,6 +1453,13 @@ def get_map_data(country: str = "NL", organization_type: str = "municipality", d
""" % {"when": when, "OrganizationTypeId": get_organization_type(organization_type),
"country": get_country(country)}
# coordinate_stack was also grouped by area, which doesn't help if there are updates: if the type of shape changes
# then the area is selected for each type of shape (since the filter is both true for now and the past). Thus
# removing area grouping will make sure that the share type can change without delivering double results.
# You can test this with dutch provinces, who where imported as a different type suddenly. When loading the data
# the map showed old and new coordinates on and off, meaning the result was semi-random somewhere. This was due to
# area being in the stack. See change on issue #130. All maps seemed to be correct over time after this change still
# print(sql)
# with the new solution, you only get just ONE area result per organization... -> nope, group by area :)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment