You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
1.1 KiB

from django.contrib.gis.measure import Distance
from service import models
from postamates.settings import DEFAULT_PLACEMENT_POINT_UPDATE_RADIUS
class LayerService:
def count_post_pvz_for_placementpoint(self, obj):
points = models.PlacementPoint.objects.filter(geometry__distance_lt=(obj.wkt, Distance(
m=DEFAULT_PLACEMENT_POINT_UPDATE_RADIUS))).all()
for point in points:
LayerService.count_post_pvz(point)
@staticmethod
def get_post_and_pvz_categroies():
return models.Post_and_pvzCategory.objects.all(), models.Post_and_pvzGroup.objects.all()
@staticmethod
def count_post_pvz(point):
point.rivals_post_cnt = models.Post_and_pvz.objects.filter(
category__name="Постамат", include_in_ml=True,
wkt__distance_lt=(point.geometry, Distance(m=DEFAULT_PLACEMENT_POINT_UPDATE_RADIUS))).count()
point.rivals_pvz_cnt = models.Post_and_pvz.objects.filter(
category__name="ПВЗ", include_in_ml=True,
wkt__distance_lt=(point.geometry, Distance(m=DEFAULT_PLACEMENT_POINT_UPDATE_RADIUS))).count()
point.save()