From a2e6175ee40c47b2894abb5c29d582f91473bd6d Mon Sep 17 00:00:00 2001 From: through-your-tears Date: Sun, 7 Apr 2024 12:05:37 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B2=D0=B7=D0=B0=D0=B8=D0=BC=D0=BE=D0=B4?= =?UTF-8?q?=D0=B5=D0=B9=D1=81=D1=82=D0=B2=D0=B8=D1=8F=20=D1=81=20=D0=B4?= =?UTF-8?q?=D1=80=D1=83=D0=B3=D0=B8=D0=BC=20=D1=81=D0=B5=D1=80=D0=B2=D0=B8?= =?UTF-8?q?=D1=81=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 2 +- src/conf/settings.py | 2 ++ src/organizations/services.py | 32 ++++++++++++++++++++++++++++++++ src/organizations/views.py | 9 ++++++++- src/requirements.txt | Bin 684 -> 700 bytes 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 6584ee4..b230648 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: build: context: ./src dockerfile: Dockerfile - command: gunicorn conf.wsgi:application --bind 0.0.0.0:8000 + command: gunicorn conf.wsgi:application --bind 0.0.0.0:8000 --threads 4 volumes: - static_volume:/home/app/web/static - media_volume:/home/app/web/media diff --git a/src/conf/settings.py b/src/conf/settings.py index 1bacdb3..b0e1f49 100644 --- a/src/conf/settings.py +++ b/src/conf/settings.py @@ -197,3 +197,5 @@ SESSION_ENGINE = "django.contrib.sessions.backends.cache" SESSION_CACHE_ALIAS = "default" CACHE_TTL = 60 * 1 + +RECOMMEND_BASE_API_URL = 'https://hack3.k-lab.su/' diff --git a/src/organizations/services.py b/src/organizations/services.py index b4d2197..c28d102 100644 --- a/src/organizations/services.py +++ b/src/organizations/services.py @@ -1,5 +1,8 @@ from django.contrib.gis.geos.point import Point +from django.conf import settings +import requests +from business.repositories import QRCodeUsingRepository from .repositories import LocationRepository, OrganizationRepository, CategoryRepository @@ -57,3 +60,32 @@ def parse_organizations_to_db(data): except Exception: pass + +def send_locations_to_recommend_service(): + for org in OrganizationRepository.all(): + requests.post(url=settings.RECOMMEND_BASE_API_URL, data={ + "location_id": org.location.pk, + "category_id": org.category.pk, + "latitude": org.location.coords[0], + "longitude": org.location.coords[1] + }) + + +def get_recommendation(user, now_location): + data = [] + for org_id in QRCodeUsingRepository.get_organizations(user).values_list('organization__pk', flat=True): + organization = OrganizationRepository.get(org_id) + data.append({ + "location_id": organization.location.pk, + "category_id": organization.category.pk, + "latitude": organization.location.coords[0], + "longitude": organization.location.coords[1] + }) + if now_location: + data.append({ + "location_id": -1, + "category_id": -1, + "latitude": now_location[0], + "longitude": now_location[1] + }) + requests.post(url=settings.RECOMMEND_BASE_API_URL, data=data) diff --git a/src/organizations/views.py b/src/organizations/views.py index 2139cf5..05e304d 100644 --- a/src/organizations/views.py +++ b/src/organizations/views.py @@ -14,7 +14,7 @@ from core.permissions import IsAuthorOrReadOnly from business.repositories import QRCodeUsingRepository from .repositories import CategoryRepository, OrganizationRepository from .serializers import CategorySerializer, OrganizationListSerializer, OrganizationCreateSerializer -from .services import parse_organizations_to_db +from .services import parse_organizations_to_db, send_locations_to_recommend_service, get_recommendation # Create your views here. @@ -123,6 +123,13 @@ class VisitedOrganizationsListAPIView(ListAPIView): return QRCodeUsingRepository.get_organizations(self.request.user) +class SendDataToRecommendAPIView(APIView): + + def post(self, request): + send_locations_to_recommend_service() + return Response(status=status.HTTP_200_OK) + + class UploadAPIView(APIView): def post(self, request): diff --git a/src/requirements.txt b/src/requirements.txt index 446b380f5fd6fb8fb14c243422fd07a2f5bde21b..38d70d02f81b42312781ec9e8b6f5293b210b142 100644 GIT binary patch delta 28 gcmZ3(x`%bc3MP>vhE#?^hEgC|%uoWvybN3n0Cl_ubN~PV delta 12 TcmdnPx`uVb3MLj_1}+8w8h8Te