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 446b380..38d70d0 100644 Binary files a/src/requirements.txt and b/src/requirements.txt differ