master #443
@ -8,10 +8,11 @@ Created on: 04.01.22
|
||||
import datetime
|
||||
|
||||
from django.contrib.gis.db.models.functions import Area
|
||||
from django.db.models import Q
|
||||
from django.utils.timezone import now
|
||||
|
||||
from konova.management.commands.setup import BaseKonovaCommand
|
||||
from konova.models import Geometry, Parcel, District
|
||||
from konova.models import Geometry
|
||||
|
||||
|
||||
class Command(BaseKonovaCommand):
|
||||
@ -41,7 +42,10 @@ class Command(BaseKonovaCommand):
|
||||
_today = now().date()
|
||||
_date_threshold = _today - datetime.timedelta(days=1)
|
||||
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
|
||||
)
|
||||
|
||||
@ -55,12 +59,20 @@ class Command(BaseKonovaCommand):
|
||||
self._write_warning(f"Process parcels for {geometries.count()} geometry entries now ...")
|
||||
i = 0
|
||||
num_geoms = geometries.count()
|
||||
geoms_with_errors = {}
|
||||
for geometry in geometries:
|
||||
self._write_warning(f"--- {datetime.datetime.now()} Process {geometry.id} now ...")
|
||||
geometry.update_parcels()
|
||||
self._write_warning(f"--- Processed {geometry.get_underlying_parcels().count()} underlying parcels")
|
||||
try:
|
||||
geometry.update_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
|
||||
self._write_warning(f"--- {i}/{num_geoms} processed")
|
||||
|
||||
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()
|
||||
|
@ -366,11 +366,10 @@ class Geometry(BaseResource):
|
||||
diff = geom_envelope - self.geom
|
||||
|
||||
if diff.area == 0:
|
||||
ratio = 1
|
||||
complexity_factor = 1
|
||||
else:
|
||||
ratio = self.geom.area / diff.area
|
||||
complexity_factor = self.geom.area / diff.area
|
||||
|
||||
complexity_factor = 1 - ratio
|
||||
return complexity_factor
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user