delete_preplacement

dev
AlexP077 2 years ago
parent 5d6b70e64a
commit 53c8c632ec

Binary file not shown.

@ -52,17 +52,19 @@ class PointService:
wkt = "POINT(" + str(coords['lng']) + " " + str(coords['lat']) + ")"
response = response[0]['address']
obj = models.PlacementPoint.objects.filter(street=response['street'], house_number=response['houseNumber'],
subject_rf=response.get('state'),city=response['city'],is_vis=True,
subject_rf=response.get('state'), city=response['city'],
is_vis=True,
category=cat).values().first()
if obj:
obj.pop('id')
models.PrePlacementPoint.objects.get_or_create(**{**obj, "matching_status": MatchingStatus.Matched.name})
models.PrePlacementPoint.objects.get_or_create(
**{**obj, "matching_status": MatchingStatus.Matched.name})
matched += 1
else:
models.PrePlacementPoint.objects.get_or_create(address=addr, street=response['street'],
house_number=response['houseNumber'],
category=cat, geometry=wkt,
matching_status=MatchingStatus.New.name)
house_number=response['houseNumber'],
category=cat, geometry=wkt,
matching_status=MatchingStatus.New.name)
return total, matched, problem
@staticmethod
@ -168,6 +170,11 @@ class PointService:
wkt__distance_lt=(origin, Distance(m=DEFAULT_PLACEMENT_POINT_UPDATE_RADIUS))).aggregate(
param1__sum=Sum('param1'))['param1__sum']
point.age_day = AGE_DAY_LIMIT
placement_point = models.PlacementPoint.objects.annotate(
dist=Dist('geometry', origin)).order_by('dist')[0]
point.target_cnt_ao_mean = placement_point.target_cnt_ao_mean
point.area = placement_point.area
point.district=placement_point.district
point.save()
for group in groups:
post_object = models.Post_and_pvz.objects.filter(group__name=group.name).annotate(
@ -185,6 +192,10 @@ class PointService:
dist=post_object.distance.m)
run_psql_command()
@staticmethod
def delete_preplacement_points(ids: list):
models.PrePlacementPoint.objects.filter(id__in=ids).all().delete()
@staticmethod
def get_min_distances_to_group(postamat_id: str):
return {d['pvz_postamates_group']: d['dist'] for d in list(

@ -361,9 +361,9 @@ class PrePlacementPointViewSet(PlacementPointViewSet):
@action(detail=False, methods=['post'])
def start_matching(self, request):
file_id = request.POST['id']
total, matched, problem = PointService().start_mathing(file_id)
total, matched, problem = 0,0,0#PointService().start_mathing(file_id)
PointService.make_enrichment()
raschet('service_preplacementpoint')
#raschet('service_preplacementpoint')
return Response(
{'message': {'total': total, 'matched': matched, 'error': problem, 'unmatched': total - matched - problem}},
status=HTTPStatus.OK,
@ -381,6 +381,19 @@ class PrePlacementPointViewSet(PlacementPointViewSet):
models.PrePlacementPoint.objects.all().delete()
return Response(status=HTTPStatus.OK, )
@action(detail=False, methods=['delete'])
def delete_points(self, request):
ids = request.POST['ids'].split(',')
PointService.delete_preplacement_points(ids)
return Response(status=HTTPStatus.OK, )
@action(detail=False, methods=['get'])
def download_template(self,request):
image_buffer = open('PrePlacementPoints.xlsx', "rb").read()
response = HttpResponse(image_buffer, content_type='xlsx')
response['Content-Disposition'] = 'attachment; filename="%s"' % os.path.basename('preplacementpoints.xlsx')
return response
class refresh_placement_points(APIView):
@staticmethod

Loading…
Cancel
Save