|
|
|
|
@ -14,6 +14,8 @@ from rest_framework.viewsets import ReadOnlyModelViewSet
|
|
|
|
|
|
|
|
|
|
from service import serializers, models, pagination
|
|
|
|
|
from service import utils
|
|
|
|
|
from service.pagination import MyPagination
|
|
|
|
|
from service.serializers import PlacementPointSerializer
|
|
|
|
|
from service.utils import raschet as raschet_alg, load_data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -195,6 +197,8 @@ class PlacementPointViewSet(ReadOnlyModelViewSet):
|
|
|
|
|
excluded = self.request.GET.get('excluded[]')
|
|
|
|
|
plan_first = self.request.GET.get('plan_first[]')
|
|
|
|
|
plan_current = self.request.GET.get('plan_current[]')
|
|
|
|
|
rayons = self.request.GET.get('rayon[]')
|
|
|
|
|
aos = self.request.GET.get('ao[]')
|
|
|
|
|
if location_ids:
|
|
|
|
|
location_ids = list(location_ids.split(','))
|
|
|
|
|
qs = qs.filter(location_id__in=location_ids)
|
|
|
|
|
@ -225,6 +229,12 @@ class PlacementPointViewSet(ReadOnlyModelViewSet):
|
|
|
|
|
if plan_current:
|
|
|
|
|
plan_current = list(plan_current.split(','))
|
|
|
|
|
qs = qs.filter(plan_current__range=plan_current)
|
|
|
|
|
if rayons:
|
|
|
|
|
rayons = list(rayons.split(','))
|
|
|
|
|
qs = qs.filter(rayon_id__in=rayons)
|
|
|
|
|
if aos:
|
|
|
|
|
aos = list(aos.split(','))
|
|
|
|
|
qs = qs.filter(okrug_id__in=aos)
|
|
|
|
|
if excluded:
|
|
|
|
|
excluded = list(excluded.split(','))
|
|
|
|
|
qs = qs.filter(~Q(location_id__in=excluded))
|
|
|
|
|
@ -318,11 +328,21 @@ class update_status(APIView):
|
|
|
|
|
age = self.request.GET.get('age[]')
|
|
|
|
|
included = self.request.GET.get('included[]')
|
|
|
|
|
excluded = self.request.GET.get('excluded[]')
|
|
|
|
|
rayons = self.request.GET.get('rayon[]')
|
|
|
|
|
aos = self.request.GET.get('ao[]')
|
|
|
|
|
if not new_status:
|
|
|
|
|
return Response({'message': 'No status provided'}, status=http_status.HTTP_400_BAD_REQUEST)
|
|
|
|
|
if not any([location_ids, prediction_first, plan_first, plan_current, prediction_current, categories, status,
|
|
|
|
|
delta, fact, age]):
|
|
|
|
|
if not any(
|
|
|
|
|
[location_ids, rayons, aos, prediction_first, plan_first, plan_current, prediction_current, categories,
|
|
|
|
|
status,
|
|
|
|
|
delta, fact, age]):
|
|
|
|
|
qs = models.PlacementPoint.objects.none()
|
|
|
|
|
if rayons:
|
|
|
|
|
rayons = list(rayons.split(','))
|
|
|
|
|
qs = qs.filter(rayon_id__in=rayons)
|
|
|
|
|
if aos:
|
|
|
|
|
aos = list(aos.split(','))
|
|
|
|
|
qs = qs.filter(okrug_id__in=aos)
|
|
|
|
|
if location_ids:
|
|
|
|
|
location_ids = list(location_ids.split(','))
|
|
|
|
|
qs = qs.filter(location_id__in=location_ids)
|
|
|
|
|
@ -360,8 +380,10 @@ class update_status(APIView):
|
|
|
|
|
inclded = list(included.split(','))
|
|
|
|
|
qs2 = models.PlacementPoint.objects.filter(location_id__in=inclded).all()
|
|
|
|
|
qs = (qs | qs2).distinct()
|
|
|
|
|
if not any([location_ids, prediction_first, plan_first, plan_current, prediction_current, categories, status,
|
|
|
|
|
delta, fact, age, excluded, included]):
|
|
|
|
|
if not any(
|
|
|
|
|
[location_ids, rayons, aos, prediction_first, plan_first, plan_current, prediction_current, categories,
|
|
|
|
|
status,
|
|
|
|
|
delta, fact, age, excluded, included]):
|
|
|
|
|
return Response({'message': 'Empty queryset'}, status=http_status.HTTP_200_OK)
|
|
|
|
|
|
|
|
|
|
qs.update(**{'status': new_status})
|
|
|
|
|
@ -396,6 +418,8 @@ class get_excel(APIView):
|
|
|
|
|
excluded = self.request.GET.get('excluded[]')
|
|
|
|
|
plan_first = self.request.GET.get('plan_first[]')
|
|
|
|
|
plan_current = self.request.GET.get('plan_current[]')
|
|
|
|
|
rayons = self.request.GET.get('rayon[]')
|
|
|
|
|
aos = self.request.GET.get('ao[]')
|
|
|
|
|
if location_ids:
|
|
|
|
|
location_ids = list(location_ids.split(','))
|
|
|
|
|
qs = qs.filter(location_id__in=location_ids)
|
|
|
|
|
@ -423,6 +447,12 @@ class get_excel(APIView):
|
|
|
|
|
if plan_first:
|
|
|
|
|
plan_first = list(plan_first.split(','))
|
|
|
|
|
qs = qs.filter(plan_first__range=plan_first)
|
|
|
|
|
if rayons:
|
|
|
|
|
rayons = list(rayons.split(','))
|
|
|
|
|
qs = qs.filter(rayon_id__in=rayons)
|
|
|
|
|
if aos:
|
|
|
|
|
aos = list(aos.split(','))
|
|
|
|
|
qs = qs.filter(okrug_id__in=aos)
|
|
|
|
|
if plan_current:
|
|
|
|
|
plan_current = list(plan_current.split(','))
|
|
|
|
|
qs = qs.filter(plan_current__range=plan_current)
|
|
|
|
|
@ -435,7 +465,7 @@ class get_excel(APIView):
|
|
|
|
|
qs = (qs | qs2).distinct()
|
|
|
|
|
data = pd.DataFrame(list(qs.values()))
|
|
|
|
|
data['start_date'] = data['start_date'].dt.tz_localize(None)
|
|
|
|
|
data['sample_trn']=data['sample_trn'].astype(int)
|
|
|
|
|
data['sample_trn'] = data['sample_trn'].astype(int)
|
|
|
|
|
with BytesIO() as b:
|
|
|
|
|
with pd.ExcelWriter(b) as writer:
|
|
|
|
|
data.to_excel(writer, sheet_name="Placement Points", index=False)
|
|
|
|
|
@ -447,3 +477,42 @@ class get_excel(APIView):
|
|
|
|
|
)
|
|
|
|
|
res['Content-Disposition'] = f'attachment; filename={filename}'
|
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class get_top_10k(APIView):
|
|
|
|
|
def get(self, request):
|
|
|
|
|
if models.PlacementPoint.objects.count()>10000:
|
|
|
|
|
qs = models.PlacementPoint.objects.order_by('-prediction_current').all()[10000]
|
|
|
|
|
return Response({'prediction_current':qs.prediction_current},200)
|
|
|
|
|
return Response({'prediction_current': models.PlacementPoint.objects.order_by('prediction_current').first().prediction_current}, 200)
|
|
|
|
|
|
|
|
|
|
class search_address(APIView):
|
|
|
|
|
pagination_class=MyPagination
|
|
|
|
|
queryset = models.PlacementPoint.objects.all()
|
|
|
|
|
serializer_class = PlacementPointSerializer
|
|
|
|
|
@property
|
|
|
|
|
def paginator(self):
|
|
|
|
|
if not hasattr(self, '_paginator'):
|
|
|
|
|
if self.pagination_class is None:
|
|
|
|
|
self._paginator = None
|
|
|
|
|
else:
|
|
|
|
|
self._paginator = self.pagination_class()
|
|
|
|
|
return self._paginator
|
|
|
|
|
|
|
|
|
|
def paginate_queryset(self, queryset):
|
|
|
|
|
if self.paginator is None:
|
|
|
|
|
return None
|
|
|
|
|
return self.paginator.paginate_queryset(queryset, self.request, view=self)
|
|
|
|
|
|
|
|
|
|
def get_paginated_response(self, data):
|
|
|
|
|
assert self.paginator is not None
|
|
|
|
|
return self.paginator.get_paginated_response(data)
|
|
|
|
|
def get(self, request):
|
|
|
|
|
address = self.request.GET.get('address')
|
|
|
|
|
qs = self.queryset.filter(address__icontains=address)
|
|
|
|
|
page = self.paginate_queryset(qs)
|
|
|
|
|
if page is not None:
|
|
|
|
|
serializer = self.serializer_class(page, many=True)
|
|
|
|
|
return self.get_paginated_response(serializer.data)
|
|
|
|
|
serializer = self.serializer_class(qs, many=True)
|
|
|
|
|
return Response(serializer.data)
|