Merge pull request '# Wartungskommando Optimization' (#442) from 439_Wartungskommando_Nachverschneidung into master
Reviewed-on: #442
This commit is contained in:
commit
de93092a52
@ -8,10 +8,11 @@ Created on: 04.01.22
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from django.contrib.gis.db.models.functions import Area
|
from django.contrib.gis.db.models.functions import Area
|
||||||
|
from django.db.models import Q
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
|
|
||||||
from konova.management.commands.setup import BaseKonovaCommand
|
from konova.management.commands.setup import BaseKonovaCommand
|
||||||
from konova.models import Geometry, Parcel, District
|
from konova.models import Geometry
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseKonovaCommand):
|
class Command(BaseKonovaCommand):
|
||||||
@ -41,7 +42,10 @@ class Command(BaseKonovaCommand):
|
|||||||
_today = now().date()
|
_today = now().date()
|
||||||
_date_threshold = _today - datetime.timedelta(days=1)
|
_date_threshold = _today - datetime.timedelta(days=1)
|
||||||
geometry_objects = Geometry.objects.filter(
|
geometry_objects = Geometry.objects.filter(
|
||||||
parcel_update_start__date__lte=_date_threshold,
|
Q(
|
||||||
|
Q(parcel_update_start__date__lte=_date_threshold) |
|
||||||
|
Q(parcel_update_start__isnull=True)
|
||||||
|
),
|
||||||
parcel_update_end__isnull=True
|
parcel_update_end__isnull=True
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -55,12 +59,20 @@ class Command(BaseKonovaCommand):
|
|||||||
self._write_warning(f"Process parcels for {geometries.count()} geometry entries now ...")
|
self._write_warning(f"Process parcels for {geometries.count()} geometry entries now ...")
|
||||||
i = 0
|
i = 0
|
||||||
num_geoms = geometries.count()
|
num_geoms = geometries.count()
|
||||||
|
geoms_with_errors = {}
|
||||||
for geometry in geometries:
|
for geometry in geometries:
|
||||||
self._write_warning(f"--- {datetime.datetime.now()} Process {geometry.id} now ...")
|
self._write_warning(f"--- {datetime.datetime.now()} Process {geometry.id} now ...")
|
||||||
|
try:
|
||||||
geometry.update_parcels()
|
geometry.update_parcels()
|
||||||
self._write_warning(f"--- Processed {geometry.get_underlying_parcels().count()} underlying parcels")
|
self._write_warning(f"--- Processed {geometry.get_underlying_parcels().count()} underlying parcels")
|
||||||
|
except Exception as e:
|
||||||
|
geoms_with_errors[geometry.id] = str(e)
|
||||||
i += 1
|
i += 1
|
||||||
self._write_warning(f"--- {i}/{num_geoms} processed")
|
self._write_warning(f"--- {i}/{num_geoms} processed")
|
||||||
|
|
||||||
self._write_success("Updating parcels done!")
|
self._write_success("Updating parcels done!")
|
||||||
|
|
||||||
|
for key, val in geoms_with_errors.items():
|
||||||
|
self._write_error(f" Error on {key}: {val}")
|
||||||
|
self._write_success(f"{num_geoms - len(geoms_with_errors)} geometries successfuly recalculated!")
|
||||||
self._break_line()
|
self._break_line()
|
||||||
|
@ -366,11 +366,10 @@ class Geometry(BaseResource):
|
|||||||
diff = geom_envelope - self.geom
|
diff = geom_envelope - self.geom
|
||||||
|
|
||||||
if diff.area == 0:
|
if diff.area == 0:
|
||||||
ratio = 1
|
complexity_factor = 1
|
||||||
else:
|
else:
|
||||||
ratio = self.geom.area / diff.area
|
complexity_factor = self.geom.area / diff.area
|
||||||
|
|
||||||
complexity_factor = 1 - ratio
|
|
||||||
return complexity_factor
|
return complexity_factor
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user