From 29d53a08d235e321258cc79d3b7f72c30faa7486 Mon Sep 17 00:00:00 2001 From: nnnLik Date: Wed, 14 Jun 2023 21:24:24 +0300 Subject: [PATCH 01/23] [ADD] machine control reports #273 --- src/newOrderView/services/order_services.py | 31 +++++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/newOrderView/services/order_services.py b/src/newOrderView/services/order_services.py index a1ac5623..66b7c896 100644 --- a/src/newOrderView/services/order_services.py +++ b/src/newOrderView/services/order_services.py @@ -60,11 +60,11 @@ def get_operations(from_date: str, to_date: str) -> List[Dict[str, Any]]: if from_date and to_date: operations_query += " AND sk.data >= ? AND sk.data <= ?" - from_date_dt = datetime.strptime(from_date, "%Y-%m-%d") - from_date_dt = from_date_dt + timedelta(microseconds=1) + from_date_dt: datetime = datetime.strptime(from_date, "%Y-%m-%d") + from_date_dt: datetime = from_date_dt + timedelta(microseconds=1) - to_date_dt = datetime.strptime(to_date, "%Y-%m-%d") - to_date_dt = to_date_dt + timedelta(days=1) - timedelta(microseconds=1) + to_date_dt: datetime = datetime.strptime(to_date, "%Y-%m-%d") + to_date_dt: datetime = to_date_dt + timedelta(days=1) - timedelta(microseconds=1) params.extend([from_date_dt, to_date_dt]) @@ -125,6 +125,8 @@ def get_operations(from_date: str, to_date: str) -> List[Dict[str, Any]]: operation["eTime"] = endTime_unix operations_list.append(operation) + + # Machine Control zone_cameras_ids: Iterable[int] = ZoneCameras.objects.filter(index_workplace=operation_id).values_list('id', flat=True) zone_cameras_ids: List[int] = [JSONField().to_python(id) for id in zone_cameras_ids] @@ -142,10 +144,11 @@ def get_operations(from_date: str, to_date: str) -> List[Dict[str, Any]]: for report in reports_with_matching_zona_id: zona_data: Dict[int, str] = report.extra - id: int = report.id - orId: str = zone_cameras_names[zona_data["zonaID"]] + machine_control_report_id: int = report.id + zone_id: str = zone_cameras_names[zona_data["zonaID"]] start_tracking: str = report.start_tracking stop_tracking: str = report.stop_tracking + sTime: int = int( datetime.strptime( start_tracking, "%Y-%m-%d %H:%M:%S.%f" @@ -154,20 +157,30 @@ def get_operations(from_date: str, to_date: str) -> List[Dict[str, Any]]: eTime: int = int( datetime.strptime(stop_tracking, "%Y-%m-%d %H:%M:%S.%f").timestamp() ) + report_data: Dict[str, Any] = { - "id": id, - "orId": orId, + "id": machine_control_report_id, + "orId": zone_id, "sTime": sTime * 1000, "eTime": eTime * 1000, } reports.append(report_data) + # machine control reports + result = { + "oprTypeID": machine_control_report_id, + "oprName": zone_cameras_names[zona_data["name"]], + "oprs": reports + } + + result_list.append(result) + + # operation result = { "oprTypeID": operation_id, "oprName": operation_name, "oprs": operations_list, - "reports": reports, } result_list.append(result) From 1e58ab290de23ec34f2e2ed6380ea7c8e067be32 Mon Sep 17 00:00:00 2001 From: nnnLik Date: Wed, 14 Jun 2023 21:30:11 +0300 Subject: [PATCH 02/23] [FIX] ordID in machine control reports --- src/newOrderView/services/order_services.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/newOrderView/services/order_services.py b/src/newOrderView/services/order_services.py index 66b7c896..8fcce1b9 100644 --- a/src/newOrderView/services/order_services.py +++ b/src/newOrderView/services/order_services.py @@ -145,7 +145,7 @@ def get_operations(from_date: str, to_date: str) -> List[Dict[str, Any]]: for report in reports_with_matching_zona_id: zona_data: Dict[int, str] = report.extra machine_control_report_id: int = report.id - zone_id: str = zone_cameras_names[zona_data["zonaID"]] + zone_name: str = zone_cameras_names[zona_data["zonaID"]] start_tracking: str = report.start_tracking stop_tracking: str = report.stop_tracking @@ -160,7 +160,7 @@ def get_operations(from_date: str, to_date: str) -> List[Dict[str, Any]]: report_data: Dict[str, Any] = { "id": machine_control_report_id, - "orId": zone_id, + "orId": zone_name, "sTime": sTime * 1000, "eTime": eTime * 1000, } @@ -170,7 +170,7 @@ def get_operations(from_date: str, to_date: str) -> List[Dict[str, Any]]: # machine control reports result = { "oprTypeID": machine_control_report_id, - "oprName": zone_cameras_names[zona_data["name"]], + "oprName": zone_name, "oprs": reports } From 39d339082de7a392f2462ee07db99805fddd7fed Mon Sep 17 00:00:00 2001 From: nnnLik Date: Wed, 14 Jun 2023 21:40:42 +0300 Subject: [PATCH 03/23] [EDIT] get zone id instead report id --- src/newOrderView/services/order_services.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/newOrderView/services/order_services.py b/src/newOrderView/services/order_services.py index 8fcce1b9..d79dda07 100644 --- a/src/newOrderView/services/order_services.py +++ b/src/newOrderView/services/order_services.py @@ -143,9 +143,10 @@ def get_operations(from_date: str, to_date: str) -> List[Dict[str, Any]]: logger.warning(f"zone_cameras_names - {zone_cameras_names}, reports_with_matching_zona_id - {reports_with_matching_zona_id}") for report in reports_with_matching_zona_id: - zona_data: Dict[int, str] = report.extra + zone_data: Dict[int, str] = report.extra + zone_id: int = zone_data["zonaID"] machine_control_report_id: int = report.id - zone_name: str = zone_cameras_names[zona_data["zonaID"]] + zone_name: str = zone_cameras_names[zone_id] start_tracking: str = report.start_tracking stop_tracking: str = report.stop_tracking @@ -169,7 +170,7 @@ def get_operations(from_date: str, to_date: str) -> List[Dict[str, Any]]: # machine control reports result = { - "oprTypeID": machine_control_report_id, + "oprTypeID": zone_id, "oprName": zone_name, "oprs": reports } From b5fb9aa679671632911fedfa4dc9a93382f5ab67 Mon Sep 17 00:00:00 2001 From: RasulMakhmudov Date: Thu, 15 Jun 2023 10:44:46 +0300 Subject: [PATCH 04/23] [EDIT] keys, zona name --- src/newOrderView/services/order_services.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/newOrderView/services/order_services.py b/src/newOrderView/services/order_services.py index d79dda07..3f38dda9 100644 --- a/src/newOrderView/services/order_services.py +++ b/src/newOrderView/services/order_services.py @@ -100,7 +100,6 @@ def get_operations(from_date: str, to_date: str) -> List[Dict[str, Any]]: startTime_dt: datetime = convert_to_gmt0(startTime_dt) startTime_unix: int = convert_to_unix(startTime_dt) - operation["sTime"] = startTime_unix if endTime is not None: @@ -125,28 +124,26 @@ def get_operations(from_date: str, to_date: str) -> List[Dict[str, Any]]: operation["eTime"] = endTime_unix operations_list.append(operation) - + # Machine Control zone_cameras_ids: Iterable[int] = ZoneCameras.objects.filter(index_workplace=operation_id).values_list('id', flat=True) zone_cameras_ids: List[int] = [JSONField().to_python(id) for id in zone_cameras_ids] - zone_cameras_names: Dict[int, str] = dict( - ZoneCameras.objects.filter(index_workplace=operation_id).values_list('id', 'name') - ) reports_with_matching_zona_id: Iterable[QuerySet] = Report.objects.filter( - Q(algorithm=3) & Q(extra__has_key="zonaID") & Q(extra__zonaID__in=zone_cameras_ids) + Q(algorithm=3) & Q(extra__has_key="zoneId") & Q(extra__zonaID__in=zone_cameras_ids) ) reports: List[Dict[str, Any]] = [] - logger.warning(f"zone_cameras_names - {zone_cameras_names}, reports_with_matching_zona_id - {reports_with_matching_zona_id}") + logger.warning(f"reports_with_matching_zona_id - {reports_with_matching_zona_id}") for report in reports_with_matching_zona_id: zone_data: Dict[int, str] = report.extra - zone_id: int = zone_data["zonaID"] + zone_id: int = zone_data["zoneId"] + zone_name: str = zone_data["zoneName"] + machine_control_report_id: int = report.id - zone_name: str = zone_cameras_names[zone_id] start_tracking: str = report.start_tracking stop_tracking: str = report.stop_tracking @@ -168,7 +165,7 @@ def get_operations(from_date: str, to_date: str) -> List[Dict[str, Any]]: reports.append(report_data) - # machine control reports + # Machine control reports result = { "oprTypeID": zone_id, "oprName": zone_name, @@ -177,7 +174,7 @@ def get_operations(from_date: str, to_date: str) -> List[Dict[str, Any]]: result_list.append(result) - # operation + # operation skans result = { "oprTypeID": operation_id, "oprName": operation_name, From 3a9a9e589c358e948bbe306847762c54acc0f912 Mon Sep 17 00:00:00 2001 From: RasulMakhmudov Date: Thu, 15 Jun 2023 11:08:03 +0300 Subject: [PATCH 05/23] [FIX] zone id key in extra --- src/newOrderView/services/order_services.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/newOrderView/services/order_services.py b/src/newOrderView/services/order_services.py index 3f38dda9..71c4b400 100644 --- a/src/newOrderView/services/order_services.py +++ b/src/newOrderView/services/order_services.py @@ -131,7 +131,7 @@ def get_operations(from_date: str, to_date: str) -> List[Dict[str, Any]]: zone_cameras_ids: List[int] = [JSONField().to_python(id) for id in zone_cameras_ids] reports_with_matching_zona_id: Iterable[QuerySet] = Report.objects.filter( - Q(algorithm=3) & Q(extra__has_key="zoneId") & Q(extra__zonaID__in=zone_cameras_ids) + Q(algorithm=3) & Q(extra__has_key="zoneId") & Q(extra__zoneId__in=zone_cameras_ids) ) reports: List[Dict[str, Any]] = [] From 6a39e6c41d95adb4d6e6b6875b4934705694e9e3 Mon Sep 17 00:00:00 2001 From: RasulMakhmudov Date: Thu, 15 Jun 2023 11:10:45 +0300 Subject: [PATCH 06/23] [FIX] duplicate --- src/newOrderView/services/order_services.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/newOrderView/services/order_services.py b/src/newOrderView/services/order_services.py index 71c4b400..4a323b23 100644 --- a/src/newOrderView/services/order_services.py +++ b/src/newOrderView/services/order_services.py @@ -165,23 +165,21 @@ def get_operations(from_date: str, to_date: str) -> List[Dict[str, Any]]: reports.append(report_data) - # Machine control reports - result = { - "oprTypeID": zone_id, - "oprName": zone_name, - "oprs": reports - } + machine_result = { + "oprTypeID": zone_id, + "oprName": zone_name, + "oprs": reports + } - result_list.append(result) + result_list.append(machine_result) - # operation skans - result = { + operation_result = { "oprTypeID": operation_id, "oprName": operation_name, "oprs": operations_list, } - result_list.append(result) + result_list.append(operation_result) return result_list @staticmethod From 5421d95d42d28a5bab196f23072be555232ea8fa Mon Sep 17 00:00:00 2001 From: RasulMakhmudov Date: Thu, 15 Jun 2023 11:17:30 +0300 Subject: [PATCH 07/23] [EDIT] zone id --- src/newOrderView/services/order_services.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/newOrderView/services/order_services.py b/src/newOrderView/services/order_services.py index 4a323b23..36a44cd6 100644 --- a/src/newOrderView/services/order_services.py +++ b/src/newOrderView/services/order_services.py @@ -134,7 +134,7 @@ def get_operations(from_date: str, to_date: str) -> List[Dict[str, Any]]: Q(algorithm=3) & Q(extra__has_key="zoneId") & Q(extra__zoneId__in=zone_cameras_ids) ) - reports: List[Dict[str, Any]] = [] + machine_reports: List[Dict[str, Any]] = [] logger.warning(f"reports_with_matching_zona_id - {reports_with_matching_zona_id}") @@ -157,18 +157,18 @@ def get_operations(from_date: str, to_date: str) -> List[Dict[str, Any]]: ) report_data: Dict[str, Any] = { - "id": machine_control_report_id, + "zoneId": machine_control_report_id, "orId": zone_name, "sTime": sTime * 1000, "eTime": eTime * 1000, } - reports.append(report_data) + machine_reports.append(report_data) machine_result = { "oprTypeID": zone_id, "oprName": zone_name, - "oprs": reports + "oprs": machine_reports } result_list.append(machine_result) From 27ee5feaf082112b65ff09a790f490b418530fbe Mon Sep 17 00:00:00 2001 From: RasulMakhmudov Date: Thu, 15 Jun 2023 11:24:49 +0300 Subject: [PATCH 08/23] [ADD] report id --- src/Reports/serializers.py | 6 ++++++ src/Reports/urls.py | 2 ++ src/Reports/views.py | 9 +++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Reports/serializers.py b/src/Reports/serializers.py index 89bb8e21..5a9dbb02 100644 --- a/src/Reports/serializers.py +++ b/src/Reports/serializers.py @@ -38,3 +38,9 @@ class OperationReportSerializer(serializers.ModelSerializer): class Meta: model = SkanyReport fields = ["id", "operationID", "camera_ip", "startTime", "endTime"] + + +class ReportByIDSerializer(serializers.ModelSerializer): + class Meta: + model = Report + fields = '__all__' \ No newline at end of file diff --git a/src/Reports/urls.py b/src/Reports/urls.py index 966b738d..c4d6fe31 100644 --- a/src/Reports/urls.py +++ b/src/Reports/urls.py @@ -6,6 +6,7 @@ ActionViewSet, SearchReportListView, GetOperationVideoInfo, + GetReportByID, ) @@ -15,6 +16,7 @@ urlpatterns = [ path("report-with-photos/", ActionsWithPhotos.as_view()), + path('reports//', GetReportByID.as_view(), name='get-report-by-id'), path( "search//////", ReportListView.as_view(), diff --git a/src/Reports/views.py b/src/Reports/views.py index b41ca179..afe537c7 100644 --- a/src/Reports/views.py +++ b/src/Reports/views.py @@ -5,7 +5,7 @@ from django.db.models import Q -from rest_framework.generics import GenericAPIView, ListAPIView +from rest_framework.generics import GenericAPIView, ListAPIView, RetrieveAPIView from rest_framework.permissions import IsAuthenticated from rest_framework.exceptions import MethodNotAllowed from rest_framework import status, viewsets @@ -19,7 +19,7 @@ from src.CameraAlgorithms.models import Camera from src.CameraAlgorithms.models import Algorithm from src.Reports.models import Report, SkanyReport -from src.Reports.serializers import ReportSerializers, OperationReportSerializer +from src.Reports.serializers import ReportSerializers, OperationReportSerializer, ReportByIDSerializer from src.Inventory.service import process_item_status from src.Reports.service import edit_extra, create_skanyreport @@ -204,3 +204,8 @@ class GetOperationVideoInfo(ListAPIView): def get_queryset(self): return SkanyReport.objects.exclude(start_time__isnull=True) + + +class GetReportByID(RetrieveAPIView): + queryset = Report.objects.all() + serializer_class = ReportByIDSerializer \ No newline at end of file From 9182361aa6ced81e9901627ee03b0f94e42fee34 Mon Sep 17 00:00:00 2001 From: RasulMakhmudov Date: Thu, 15 Jun 2023 11:32:09 +0300 Subject: [PATCH 09/23] [EDIT] serializer and urls name --- src/Reports/serializers.py | 16 +++++++++++++-- src/Reports/service.py | 9 ++++---- src/Reports/urls.py | 2 +- src/Reports/views.py | 42 +++++++++++++++++++++++--------------- 4 files changed, 45 insertions(+), 24 deletions(-) diff --git a/src/Reports/serializers.py b/src/Reports/serializers.py index 5a9dbb02..c2c0cc7d 100644 --- a/src/Reports/serializers.py +++ b/src/Reports/serializers.py @@ -40,7 +40,19 @@ class Meta: fields = ["id", "operationID", "camera_ip", "startTime", "endTime"] -class ReportByIDSerializer(serializers.ModelSerializer): +class ReportSerializer(serializers.ModelSerializer): + algorithm = AlgorithmSerializer() + camera = serializers.StringRelatedField() + class Meta: model = Report - fields = '__all__' \ No newline at end of file + fields = [ + "id", + "start_tracking", + "stop_tracking", + "violation_found", + "extra", + "status", + "algorithm", + "camera", + ] diff --git a/src/Reports/service.py b/src/Reports/service.py index d4754e97..c08a2a95 100644 --- a/src/Reports/service.py +++ b/src/Reports/service.py @@ -41,7 +41,7 @@ def create_skanyreport( report_data: List[Dict], violation_found: bool, start_tracking: str, - end_tracking: str + end_tracking: str, ) -> None: start_dt = datetime.strptime(start_tracking, "%Y-%m-%d %H:%M:%S.%f") start_utc = start_dt.replace(tzinfo=timezone.utc) @@ -53,12 +53,13 @@ def create_skanyreport( end_gmt = end_utc.astimezone(timezone(timedelta(hours=0))) eTime = int(end_gmt.timestamp()) - skany_indeks = report_data[0].get("skany_index") zlecenie = report_data[0].get("zlecenie") execution_date = report_data[0].get("execution_date") - logger.warning(f"Creating Skany Report start_tracking -> {start_tracking} - {sTime}, end_tracking -> {end_tracking} - {eTime}") + logger.warning( + f"Creating Skany Report start_tracking -> {start_tracking} - {sTime}, end_tracking -> {end_tracking} - {eTime}" + ) SkanyReport.objects.create( report=report, @@ -68,4 +69,4 @@ def create_skanyreport( violation_found=violation_found, start_time=sTime, end_time=eTime, - ) \ No newline at end of file + ) diff --git a/src/Reports/urls.py b/src/Reports/urls.py index c4d6fe31..0b6b03d7 100644 --- a/src/Reports/urls.py +++ b/src/Reports/urls.py @@ -16,7 +16,7 @@ urlpatterns = [ path("report-with-photos/", ActionsWithPhotos.as_view()), - path('reports//', GetReportByID.as_view(), name='get-report-by-id'), + path("by-id//", GetReportByID.as_view(), name="get-report-by-id"), path( "search//////", ReportListView.as_view(), diff --git a/src/Reports/views.py b/src/Reports/views.py index afe537c7..27ecc588 100644 --- a/src/Reports/views.py +++ b/src/Reports/views.py @@ -19,14 +19,17 @@ from src.CameraAlgorithms.models import Camera from src.CameraAlgorithms.models import Algorithm from src.Reports.models import Report, SkanyReport -from src.Reports.serializers import ReportSerializers, OperationReportSerializer, ReportByIDSerializer +from src.Reports.serializers import ( + ReportSerializers, + OperationReportSerializer, + ReportByIDSerializer, +) from src.Inventory.service import process_item_status from src.Reports.service import edit_extra, create_skanyreport logger = logging.getLogger(__name__) - class ActionViewSet(viewsets.ModelViewSet): queryset = Report.objects.all().order_by("-id") serializer_class = ReportSerializers @@ -56,7 +59,7 @@ def post(self, request): algorithm = Algorithm.objects.get(name=algorithm_name) camera = Camera.objects.get(id=camera_ip) - + start_tracking = data.get("start_tracking") stop_tracking = data.get("stop_tracking") @@ -69,15 +72,22 @@ def post(self, request): elif algorithm_name == "operation_control": if not PRODUCTION: - if 'extra' in data: - for data in data['extra']: - if 'place' in data: - logger.warning(f"Operation control extra data is {data}") - requests.post(f"{SERVER_URL}:9876/skany/create/", json=data['extra'][0]) + if "extra" in data: + for data in data["extra"]: + if "place" in data: + logger.warning( + f"Operation control extra data is {data}" + ) + requests.post( + f"{SERVER_URL}:9876/skany/create/", + json=data["extra"][0], + ) break else: logger.warning(f"Operation control extra data is {data}") - requests.post(f"{SERVER_URL}:9876/operation-control/", json=data) + requests.post( + f"{SERVER_URL}:9876/operation-control/", json=data + ) extra = edit_extra(data.get("extra"), camera) else: extra = data.get("extra") @@ -97,11 +107,7 @@ def post(self, request): if algorithm_name == "operation_control": create_skanyreport( - action, - extra, - not violation_found, - start_tracking, - stop_tracking + action, extra, not violation_found, start_tracking, stop_tracking ) if photos: @@ -148,7 +154,9 @@ def get(self, request, algorithm_name, camera_ip, date, start_time, end_time): if camera_ip: queryset = queryset.filter(camera__id=camera_ip) if algorithm_name: - queryset = queryset.exclude(algorithm__name='min_max_control').filter(algorithm__name=algorithm_name) + queryset = queryset.exclude(algorithm__name="min_max_control").filter( + algorithm__name=algorithm_name + ) queryset = queryset.order_by("algorithm__name", "camera__id", "id") @@ -185,7 +193,7 @@ def get_queryset(self): algorithm_filters |= Q(algorithm__name=algorithm_name) queryset = queryset.filter(algorithm_filters) - queryset = queryset.exclude(algorithm__name='min_max_control') + queryset = queryset.exclude(algorithm__name="min_max_control") queryset = queryset.order_by("-id") @@ -208,4 +216,4 @@ def get_queryset(self): class GetReportByID(RetrieveAPIView): queryset = Report.objects.all() - serializer_class = ReportByIDSerializer \ No newline at end of file + serializer_class = ReportByIDSerializer From 9d9231964a89bbda6cb0b48de98a505310e4a5f7 Mon Sep 17 00:00:00 2001 From: RasulMakhmudov Date: Thu, 15 Jun 2023 11:39:59 +0300 Subject: [PATCH 10/23] [FIX] serializer --- src/Reports/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Reports/serializers.py b/src/Reports/serializers.py index c2c0cc7d..b04749c4 100644 --- a/src/Reports/serializers.py +++ b/src/Reports/serializers.py @@ -40,7 +40,7 @@ class Meta: fields = ["id", "operationID", "camera_ip", "startTime", "endTime"] -class ReportSerializer(serializers.ModelSerializer): +class ReportByIDSerializer(serializers.ModelSerializer): algorithm = AlgorithmSerializer() camera = serializers.StringRelatedField() From 32713dbd146bba4548df91f8dab7f56299b380ef Mon Sep 17 00:00:00 2001 From: RasulMakhmudov Date: Thu, 15 Jun 2023 12:04:22 +0300 Subject: [PATCH 11/23] [EDIT] production to emulate db --- src/Core/const.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Core/const.py b/src/Core/const.py index b180a70a..9de097ab 100644 --- a/src/Core/const.py +++ b/src/Core/const.py @@ -6,11 +6,11 @@ if not SERVER_URL: SERVER_URL = config("SERVER_URL") -PRODUCTION = os.environ.get("PRODUCTION") -if PRODUCTION is not None and PRODUCTION.lower() == "true": - PRODUCTION = True +EMULATE_DB = os.environ.get("EMULATE_DB") +if EMULATE_DB is not None and EMULATE_DB.lower() == "true": + EMULATE_DB = True else: - PRODUCTION = False + EMULATE_DB = False safety_control_ear_protection_description = """ Designed to ensure that the workers in a particular area are wearing ear protection to safeguard their hearing. From 13a911b257c6cdc9c44101529884fbfe667bda84 Mon Sep 17 00:00:00 2001 From: RasulMakhmudov Date: Thu, 15 Jun 2023 12:04:43 +0300 Subject: [PATCH 12/23] [EDIT] servises --- src/newOrderView/services/__init__.py | 2 + .../{order_services.py => operations.py} | 190 +++--------------- src/newOrderView/services/order.py | 163 +++++++++++++++ src/newOrderView/views.py | 10 +- 4 files changed, 198 insertions(+), 167 deletions(-) create mode 100644 src/newOrderView/services/__init__.py rename src/newOrderView/services/{order_services.py => operations.py} (50%) create mode 100644 src/newOrderView/services/order.py diff --git a/src/newOrderView/services/__init__.py b/src/newOrderView/services/__init__.py new file mode 100644 index 00000000..6ccc451e --- /dev/null +++ b/src/newOrderView/services/__init__.py @@ -0,0 +1,2 @@ +from .operations import OperationServices +from .order import OrderServises \ No newline at end of file diff --git a/src/newOrderView/services/order_services.py b/src/newOrderView/services/operations.py similarity index 50% rename from src/newOrderView/services/order_services.py rename to src/newOrderView/services/operations.py index 36a44cd6..aa7f409c 100644 --- a/src/newOrderView/services/order_services.py +++ b/src/newOrderView/services/operations.py @@ -1,4 +1,4 @@ -from typing import Iterable, List, Any, Tuple, Dict, Optional +from typing import Iterable, List, Any, Tuple, Dict from datetime import datetime, timedelta import logging import pytz @@ -11,17 +11,14 @@ from src.CameraAlgorithms.models.camera import ZoneCameras from src.MsSqlConnector.connector import connector as connector_service -from src.OrderView.models import IndexOperations -from src.OrderView.utils import get_skany_video_info -from src.CameraAlgorithms.models import Camera -from src.Reports.models import Report, SkanyReport +from src.Reports.models import Report from ..utils import add_ms, convert_to_gmt0, convert_to_unix logger = logging.getLogger(__name__) -class OrderServices: +class OperationServices: @staticmethod def get_operations(from_date: str, to_date: str) -> List[Dict[str, Any]]: connection: pyodbc.Connection = connector_service.get_database_connection() @@ -156,14 +153,31 @@ def get_operations(from_date: str, to_date: str) -> List[Dict[str, Any]]: datetime.strptime(stop_tracking, "%Y-%m-%d %H:%M:%S.%f").timestamp() ) - report_data: Dict[str, Any] = { - "zoneId": machine_control_report_id, - "orId": zone_name, - "sTime": sTime * 1000, - "eTime": eTime * 1000, - } - - machine_reports.append(report_data) + day_start = datetime.strptime(start_tracking, "%Y-%m-%d %H:%M:%S.%f") + day_start = day_start.replace(hour=6, minute=0, second=0, microsecond=0) + + day_end = datetime.strptime(stop_tracking, "%Y-%m-%d %H:%M:%S.%f") + day_end = day_end.replace(hour=20, minute=0, second=0, microsecond=0) + + # Check if sTime is after the day start, and if so, add a report for the period between day start and sTime + if sTime > day_start.timestamp(): + morning_report = { + "zoneId": machine_control_report_id, + "orId": zone_name, + "sTime": int(day_start.timestamp()) * 1000, + "eTime": sTime * 1000, + } + machine_reports.append(morning_report) + + # Check if eTime is before the day end, and if so, add a report for the period between eTime and day end + if eTime < day_end.timestamp(): + evening_report = { + "zoneId": machine_control_report_id, + "orId": zone_name, + "sTime": eTime * 1000, + "eTime": int(day_end.timestamp()) * 1000, + } + machine_reports.append(evening_report) machine_result = { "oprTypeID": zone_id, @@ -182,154 +196,6 @@ def get_operations(from_date: str, to_date: str) -> List[Dict[str, Any]]: result_list.append(operation_result) return result_list - @staticmethod - def get_order(from_date: str, to_date: str) -> List[Dict[str, Any]]: - connection: pyodbc.Connection = connector_service.get_database_connection() - - order_query: str = """ - SELECT - DISTINCT z.zlecenie AS orderId - FROM Skany sk - JOIN Skany_vs_Zlecenia sz ON sk.indeks = sz.indeksskanu - JOIN zlecenia z ON sz.indekszlecenia = z.indeks - WHERE sk.data >= ? AND sk.data <= ? - """ - - if from_date and to_date: - from_date_dt = datetime.strptime(from_date, "%Y-%m-%d") - from_date_dt = from_date_dt + timedelta(microseconds=1) - - to_date_dt = datetime.strptime(to_date, "%Y-%m-%d") - to_date_dt = to_date_dt + timedelta(days=1) - timedelta(microseconds=1) - - params: List[Any] = [from_date_dt, to_date_dt] - - order_data: List[Tuple[Any]] = connector_service.executer( - connection=connection, query=order_query, params=params - ) - - result_list: List[Dict[str, Any]] = [] - - for order_row in order_data: - order: Dict[str, Any] = { - "orId": order_row[0].strip(), - } - - result_list.append(order) - - return result_list - - @staticmethod - def get_order_by_details(operation_id: int) -> Dict[str, Any]: - connection: pyodbc.Connection = connector_service.get_database_connection() - - order_query = """ - WITH Operation AS ( - SELECT - sk.data AS operationTime - FROM Skany sk - JOIN Stanowiska st ON sk.stanowisko = st.indeks - WHERE sk.indeks = ? - ) - SELECT - z.indeks AS id, - z.zlecenie AS orderId, - st.raport AS operationName, - u.imie AS firstName, - u.nazwisko AS lastName, - CONVERT(VARCHAR(23), op.operationTime, 121) AS startTime, - CASE - WHEN DATEPART(year, sk_next.data) > DATEPART(year, op.operationTime) - OR DATEPART(month, sk_next.data) > DATEPART(month, op.operationTime) - OR DATEPART(day, sk_next.data) > DATEPART(day, op.operationTime) - THEN DATEADD(hour, 1, op.operationTime) - ELSE CONVERT(VARCHAR(23), sk_next.data, 121) - END AS endTime, - st.indeks AS workplaceID, - sk.indeks AS operationID, - z.typ AS type - FROM Zlecenia z - JOIN Skany_vs_Zlecenia sz ON z.indeks = sz.indekszlecenia - JOIN Skany sk ON sz.indeksskanu = sk.indeks - JOIN Stanowiska st ON sk.stanowisko = st.indeks - JOIN Uzytkownicy u ON sk.uzytkownik = u.indeks - JOIN Operation op ON op.operationTime = sk.data - LEFT JOIN Skany sk_next ON sk_next.data > op.operationTime - AND sk_next.stanowisko = st.indeks - WHERE sk.indeks = ? - """ - - params: List[Any] = [operation_id, operation_id] - - order_data: List[Tuple[Any]] = connector_service.executer( - connection=connection, query=order_query, params=params - ) - - if order_data: - id: int = order_data[0][8] - orderId: str = order_data[0][1].strip() - operationName: str = order_data[0][2] - firstName: str = order_data[0][3] - lastName: str = order_data[0][4] - startTime: datetime = datetime.strptime( - str(order_data[0][5]), "%Y-%m-%d %H:%M:%S.%f" - ) - endTime_str = str(order_data[0][6]) if order_data[0][6] else None - - if endTime_str: - if "." not in endTime_str: - endTime_str += ".000" - endTime = datetime.strptime(endTime_str, "%Y-%m-%d %H:%M:%S.%f") - else: - endTime = startTime + timedelta(hours=1) - - workplaceID: int = order_data[0][7] - elementType = order_data[0][9] - video_data: Optional[Dict[str, Any]] = None - - if startTime is not None: - camera_obj: Optional[Camera] = None - operation_status: Optional[bool] = None - video_data: Dict[str, bool] = {} - - skany_report: Optional[SkanyReport] = SkanyReport.objects.filter( - skany_index=id - ).first() - camera_obj: Optional[Camera] = IndexOperations.objects.filter( - type_operation=workplaceID - ).first() - - if skany_report: - operation_status: Optional[bool] = skany_report.violation_found - video_time: Optional[bool] = skany_report.start_time - logger.warning(f"Skany report was founded. Data -> {operation_status}, {video_data}",) - if camera_obj and video_time: - logger.warning(video_time*1000) - video_data: Dict[str, Any] = get_skany_video_info( - time=(video_time * 1000), camera_ip=camera_obj.camera.id - ) - - startTime_unix: int = int(startTime.timestamp()) * 1000 - endTime_unix: int = int(endTime.timestamp()) * 1000 - logger.warning(f"GET START TIME {startTime}") - logger.warning(f"MAKE UNIX {startTime_unix}") - result: Dict[str, Any] = { - "id": id, - "orId": orderId, - "oprName": operationName, - "elType": elementType, - "sTime": startTime_unix, - "eTime": endTime_unix, - "frsName": firstName, - "lstName": lastName, - "status": operation_status, - "video": video_data, - } - - return result - else: - return {} - @staticmethod def get_whnet_operation() -> List[Dict[str, Any]]: connection: pyodbc.Connection = connector_service.get_database_connection() diff --git a/src/newOrderView/services/order.py b/src/newOrderView/services/order.py new file mode 100644 index 00000000..d9eada5c --- /dev/null +++ b/src/newOrderView/services/order.py @@ -0,0 +1,163 @@ +from typing import List, Any, Tuple, Dict, Optional +from datetime import datetime, timedelta +import logging + +import pyodbc + +from src.MsSqlConnector.connector import connector as connector_service +from src.OrderView.models import IndexOperations +from src.OrderView.utils import get_skany_video_info +from src.CameraAlgorithms.models import Camera +from src.Reports.models import SkanyReport + +logger = logging.getLogger(__name__) + + +class OrderServises: + @staticmethod + def get_order(from_date: str, to_date: str) -> List[Dict[str, Any]]: + connection: pyodbc.Connection = connector_service.get_database_connection() + + order_query: str = """ + SELECT + DISTINCT z.zlecenie AS orderId + FROM Skany sk + JOIN Skany_vs_Zlecenia sz ON sk.indeks = sz.indeksskanu + JOIN zlecenia z ON sz.indekszlecenia = z.indeks + WHERE sk.data >= ? AND sk.data <= ? + """ + + if from_date and to_date: + from_date_dt = datetime.strptime(from_date, "%Y-%m-%d") + from_date_dt = from_date_dt + timedelta(microseconds=1) + + to_date_dt = datetime.strptime(to_date, "%Y-%m-%d") + to_date_dt = to_date_dt + timedelta(days=1) - timedelta(microseconds=1) + + params: List[Any] = [from_date_dt, to_date_dt] + + order_data: List[Tuple[Any]] = connector_service.executer( + connection=connection, query=order_query, params=params + ) + + result_list: List[Dict[str, Any]] = [] + + for order_row in order_data: + order: Dict[str, Any] = { + "orId": order_row[0].strip(), + } + + result_list.append(order) + + return result_list + + @staticmethod + def get_order_by_details(operation_id: int) -> Dict[str, Any]: + connection: pyodbc.Connection = connector_service.get_database_connection() + + order_query = """ + WITH Operation AS ( + SELECT + sk.data AS operationTime + FROM Skany sk + JOIN Stanowiska st ON sk.stanowisko = st.indeks + WHERE sk.indeks = ? + ) + SELECT + z.indeks AS id, + z.zlecenie AS orderId, + st.raport AS operationName, + u.imie AS firstName, + u.nazwisko AS lastName, + CONVERT(VARCHAR(23), op.operationTime, 121) AS startTime, + CASE + WHEN DATEPART(year, sk_next.data) > DATEPART(year, op.operationTime) + OR DATEPART(month, sk_next.data) > DATEPART(month, op.operationTime) + OR DATEPART(day, sk_next.data) > DATEPART(day, op.operationTime) + THEN DATEADD(hour, 1, op.operationTime) + ELSE CONVERT(VARCHAR(23), sk_next.data, 121) + END AS endTime, + st.indeks AS workplaceID, + sk.indeks AS operationID, + z.typ AS type + FROM Zlecenia z + JOIN Skany_vs_Zlecenia sz ON z.indeks = sz.indekszlecenia + JOIN Skany sk ON sz.indeksskanu = sk.indeks + JOIN Stanowiska st ON sk.stanowisko = st.indeks + JOIN Uzytkownicy u ON sk.uzytkownik = u.indeks + JOIN Operation op ON op.operationTime = sk.data + LEFT JOIN Skany sk_next ON sk_next.data > op.operationTime + AND sk_next.stanowisko = st.indeks + WHERE sk.indeks = ? + """ + + params: List[Any] = [operation_id, operation_id] + + order_data: List[Tuple[Any]] = connector_service.executer( + connection=connection, query=order_query, params=params + ) + + if order_data: + id: int = order_data[0][8] + orderId: str = order_data[0][1].strip() + operationName: str = order_data[0][2] + firstName: str = order_data[0][3] + lastName: str = order_data[0][4] + startTime: datetime = datetime.strptime( + str(order_data[0][5]), "%Y-%m-%d %H:%M:%S.%f" + ) + endTime_str = str(order_data[0][6]) if order_data[0][6] else None + + if endTime_str: + if "." not in endTime_str: + endTime_str += ".000" + endTime = datetime.strptime(endTime_str, "%Y-%m-%d %H:%M:%S.%f") + else: + endTime = startTime + timedelta(hours=1) + + workplaceID: int = order_data[0][7] + elementType = order_data[0][9] + video_data: Optional[Dict[str, Any]] = None + + if startTime is not None: + camera_obj: Optional[Camera] = None + operation_status: Optional[bool] = None + video_data: Dict[str, bool] = {} + + skany_report: Optional[SkanyReport] = SkanyReport.objects.filter( + skany_index=id + ).first() + camera_obj: Optional[Camera] = IndexOperations.objects.filter( + type_operation=workplaceID + ).first() + + if skany_report: + operation_status: Optional[bool] = skany_report.violation_found + video_time: Optional[bool] = skany_report.start_time + logger.warning(f"Skany report was founded. Data -> {operation_status}, {video_data}",) + if camera_obj and video_time: + logger.warning(video_time*1000) + video_data: Dict[str, Any] = get_skany_video_info( + time=(video_time * 1000), camera_ip=camera_obj.camera.id + ) + + startTime_unix: int = int(startTime.timestamp()) * 1000 + endTime_unix: int = int(endTime.timestamp()) * 1000 + logger.warning(f"GET START TIME {startTime}") + logger.warning(f"MAKE UNIX {startTime_unix}") + result: Dict[str, Any] = { + "id": id, + "orId": orderId, + "oprName": operationName, + "elType": elementType, + "sTime": startTime_unix, + "eTime": endTime_unix, + "frsName": firstName, + "lstName": lastName, + "status": operation_status, + "video": video_data, + } + + return result + else: + return {} diff --git a/src/newOrderView/views.py b/src/newOrderView/views.py index cc97f2e7..d22723c9 100644 --- a/src/newOrderView/views.py +++ b/src/newOrderView/views.py @@ -10,7 +10,7 @@ from src.Core.paginators import OrderViewPaginnator, NoPagination from src.MsSqlConnector.connector import connector as connector_service -from .services.order_services import OrderServices +from .services import OperationServices, OrderServises from .utils import generate_hash @@ -24,7 +24,7 @@ def get(self, request): response = cache.get(key) if response is None: - response: List[Dict[str, Any]] = OrderServices.get_operations( + response: List[Dict[str, Any]] = OperationServices.get_operations( from_date, to_date ) cache.set(key, response, timeout=120) @@ -44,7 +44,7 @@ def get(self, request): response = cache.get("get_order_" + key) if response is None: - response: List[Dict[str, str]] = OrderServices.get_order(from_date, to_date) + response: List[Dict[str, str]] = OrderServises.get_order(from_date, to_date) cache.set(key, response, timeout=120) return JsonResponse(response, status=status.HTTP_200_OK, safe=False) @@ -56,7 +56,7 @@ class GetOrderByDetail(generics.GenericAPIView): @connector_service.check_database_connection def get(self, request): operation_id: int = request.GET.get("operation") - response: Dict[str, Any] = OrderServices.get_order_by_details(operation_id) + response: Dict[str, Any] = OrderServises.get_order_by_details(operation_id) return JsonResponse(data=response, status=status.HTTP_200_OK) @@ -66,6 +66,6 @@ class GetWhnetOperation(generics.GenericAPIView): @method_decorator(cache_page(30)) @connector_service.check_database_connection def get(self, request): - response: Dict[str, Any] = OrderServices.get_whnet_operation() + response: Dict[str, Any] = OperationServices.get_whnet_operation() return JsonResponse(data=response, status=status.HTTP_200_OK, safe=False) From 2b366477b8bb0aed006523e2607ba17485ac032a Mon Sep 17 00:00:00 2001 From: RasulMakhmudov Date: Thu, 15 Jun 2023 12:04:55 +0300 Subject: [PATCH 13/23] [EDIT] const --- src/Reports/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Reports/views.py b/src/Reports/views.py index 27ecc588..e09fbc89 100644 --- a/src/Reports/views.py +++ b/src/Reports/views.py @@ -13,7 +13,7 @@ from rest_framework.response import Response from src.CompanyLicense.decorators import validate_license -from src.Core.const import PRODUCTION, SERVER_URL +from src.Core.const import EMULATE_DB, SERVER_URL from src.Core.paginators import NoPagination from src.ImageReport.models import Image from src.CameraAlgorithms.models import Camera @@ -71,7 +71,7 @@ def post(self, request): extra = process_item_status(data.get("extra")) elif algorithm_name == "operation_control": - if not PRODUCTION: + if not EMULATE_DB: if "extra" in data: for data in data["extra"]: if "place" in data: From 75173ce4983854c34ccfb64316bb1e7e5c004260 Mon Sep 17 00:00:00 2001 From: anikeenko Date: Thu, 15 Jun 2023 12:06:33 +0300 Subject: [PATCH 14/23] EDIT restart process --- src/Core/management/commands/startprocess.py | 31 ++++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/Core/management/commands/startprocess.py b/src/Core/management/commands/startprocess.py index 8ec06583..b887df7d 100644 --- a/src/Core/management/commands/startprocess.py +++ b/src/Core/management/commands/startprocess.py @@ -3,9 +3,11 @@ from django.core.management.base import BaseCommand +from src.Core.const import SERVER_URL from src.Core.exceptions import SenderError, InvalidResponseError from src.Inventory.models import Items +from src.CameraAlgorithms.models.camera import ZoneCameras from src.CameraAlgorithms.models import Camera, CameraAlgorithm from src.CameraAlgorithms.services.cameraalgorithm import ( camera_rtsp_link, @@ -33,20 +35,37 @@ def start_process(self) -> None: if camera_algorithm.algorithm.name == "min_max_control": algorithm_items = Items.objects.filter(camera=camera_obj) + areas = [] + stelag = [] + for item in algorithm_items: - extra_params.append( - { - "itemId": item.id, - "coords": item.coords, - "itemName": item.name, - } + areas.append( + {"itemId": item.id, "itemName": item.name, "coords": item.coords} ) + all_zones = camera_obj.zones + + for zone_id in all_zones: + zone_camera = ZoneCameras.objects.get(id=zone_id["id"], camera=camera_obj) + + stelag.append( + {"zoneId": zone_camera.id, "zoneName": zone_camera.name, "coords": zone_camera.coords} + ) + + new_data = { + "areas": areas, + "zones": stelag + } + + extra_params.append(new_data) + request: Dict[str, Any] = { "camera_url": rtsp_link, "algorithm": algorithm_obj.name, + "server_url": SERVER_URL, "extra": extra_params, } + print("request", request) try: result = send_run_request(request) From 8b12bc6eea16876f899f5b241794c3072165f702 Mon Sep 17 00:00:00 2001 From: RasulMakhmudov Date: Thu, 15 Jun 2023 12:15:42 +0300 Subject: [PATCH 15/23] [FIX] time --- src/Reports/views.py | 2 +- src/newOrderView/services/operations.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Reports/views.py b/src/Reports/views.py index e09fbc89..9fd68524 100644 --- a/src/Reports/views.py +++ b/src/Reports/views.py @@ -71,7 +71,7 @@ def post(self, request): extra = process_item_status(data.get("extra")) elif algorithm_name == "operation_control": - if not EMULATE_DB: + if EMULATE_DB: if "extra" in data: for data in data["extra"]: if "place" in data: diff --git a/src/newOrderView/services/operations.py b/src/newOrderView/services/operations.py index aa7f409c..86913bda 100644 --- a/src/newOrderView/services/operations.py +++ b/src/newOrderView/services/operations.py @@ -179,6 +179,21 @@ def get_operations(from_date: str, to_date: str) -> List[Dict[str, Any]]: } machine_reports.append(evening_report) + # Exclude the time period covered by the report from the daily range + if sTime < day_end.timestamp() and eTime > day_start.timestamp(): + day_start = max(day_start, datetime.fromtimestamp(eTime)) + day_end = min(day_end, datetime.fromtimestamp(sTime)) + + # Check if there is still a valid time range after excluding the report + if day_start < day_end: + daytime_report = { + "zoneId": machine_control_report_id, + "orId": zone_name, + "sTime": int(day_start.timestamp()) * 1000, + "eTime": int(day_end.timestamp()) * 1000, + } + machine_reports.append(daytime_report) + machine_result = { "oprTypeID": zone_id, "oprName": zone_name, From 3a035d56a99ab4b1f1a6a50e909ab4795854985e Mon Sep 17 00:00:00 2001 From: anikeenko Date: Thu, 15 Jun 2023 12:30:23 +0300 Subject: [PATCH 16/23] ADD information print --- src/Core/management/commands/startprocess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/management/commands/startprocess.py b/src/Core/management/commands/startprocess.py index b887df7d..9793c461 100644 --- a/src/Core/management/commands/startprocess.py +++ b/src/Core/management/commands/startprocess.py @@ -56,7 +56,7 @@ def start_process(self) -> None: "areas": areas, "zones": stelag } - + print("New data", new_data) extra_params.append(new_data) request: Dict[str, Any] = { From fc1bf22f3eca05204fc44b0bb02d2c903e73c107 Mon Sep 17 00:00:00 2001 From: anikeenko Date: Thu, 15 Jun 2023 12:34:33 +0300 Subject: [PATCH 17/23] ADD information print --- src/Core/management/commands/startprocess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/management/commands/startprocess.py b/src/Core/management/commands/startprocess.py index 9793c461..fcec8a12 100644 --- a/src/Core/management/commands/startprocess.py +++ b/src/Core/management/commands/startprocess.py @@ -34,7 +34,7 @@ def start_process(self) -> None: if camera_algorithm.algorithm.name == "min_max_control": algorithm_items = Items.objects.filter(camera=camera_obj) - + print("algorithm_items", algorithm_items) areas = [] stelag = [] From ca9888c27d9c83d08e5ee51910ee36fc136a5b98 Mon Sep 17 00:00:00 2001 From: anikeenko Date: Thu, 15 Jun 2023 12:55:23 +0300 Subject: [PATCH 18/23] EDIT restart minmax --- src/Core/management/commands/startprocess.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Core/management/commands/startprocess.py b/src/Core/management/commands/startprocess.py index fcec8a12..1d22070d 100644 --- a/src/Core/management/commands/startprocess.py +++ b/src/Core/management/commands/startprocess.py @@ -31,10 +31,8 @@ def start_process(self) -> None: camera_obj: Camera = camera_algorithm.camera algorithm_obj: CameraAlgorithm = camera_algorithm.algorithm rtsp_link: str = camera_rtsp_link(camera_obj.id) - if camera_algorithm.algorithm.name == "min_max_control": algorithm_items = Items.objects.filter(camera=camera_obj) - print("algorithm_items", algorithm_items) areas = [] stelag = [] @@ -43,7 +41,7 @@ def start_process(self) -> None: {"itemId": item.id, "itemName": item.name, "coords": item.coords} ) - all_zones = camera_obj.zones + all_zones = camera_algorithm.zones for zone_id in all_zones: zone_camera = ZoneCameras.objects.get(id=zone_id["id"], camera=camera_obj) @@ -56,7 +54,6 @@ def start_process(self) -> None: "areas": areas, "zones": stelag } - print("New data", new_data) extra_params.append(new_data) request: Dict[str, Any] = { @@ -65,7 +62,6 @@ def start_process(self) -> None: "server_url": SERVER_URL, "extra": extra_params, } - print("request", request) try: result = send_run_request(request) @@ -77,6 +73,6 @@ def start_process(self) -> None: ) else: new_process_id = result["pid"] - + # camera_algorithm.process_id = new_process_id camera_algorithm.save() From 7e70fe0ccd10f5bf042a0a2d41580f3ee28b3140 Mon Sep 17 00:00:00 2001 From: anikeenko Date: Thu, 15 Jun 2023 13:13:00 +0300 Subject: [PATCH 19/23] EDIT restart minmax --- src/Core/management/commands/startprocess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/management/commands/startprocess.py b/src/Core/management/commands/startprocess.py index 1d22070d..94c2a91f 100644 --- a/src/Core/management/commands/startprocess.py +++ b/src/Core/management/commands/startprocess.py @@ -72,7 +72,7 @@ def start_process(self) -> None: f"Yolo can't start algorithm {algorithm_obj.name} on camera {camera_obj.id}. Details: {e}" ) else: + pass new_process_id = result["pid"] - # camera_algorithm.process_id = new_process_id camera_algorithm.save() From 98bebf6c7293b311edfe20f98f18eea8a0215049 Mon Sep 17 00:00:00 2001 From: anikeenko Date: Thu, 15 Jun 2023 13:30:19 +0300 Subject: [PATCH 20/23] ADD restart machine_control --- src/Core/management/commands/startprocess.py | 31 +++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/Core/management/commands/startprocess.py b/src/Core/management/commands/startprocess.py index 94c2a91f..2416554c 100644 --- a/src/Core/management/commands/startprocess.py +++ b/src/Core/management/commands/startprocess.py @@ -31,6 +31,29 @@ def start_process(self) -> None: camera_obj: Camera = camera_algorithm.camera algorithm_obj: CameraAlgorithm = camera_algorithm.algorithm rtsp_link: str = camera_rtsp_link(camera_obj.id) + + request: Dict[str, Any] = { + "camera_url": rtsp_link, + "algorithm": algorithm_obj.name, + "server_url": SERVER_URL, + "extra": extra_params, + } + + if camera_algorithm.algorithm.name == "machine_control": + all_zones = camera_algorithm.zones + cords = [] + for zone_id in all_zones: + zone_camera = ZoneCameras.objects.get(id=zone_id["id"], camera=camera_obj) + coords = zone_camera.coords + coords[0]["zoneId"] = zone_camera.id + coords[0]["zoneName"] = "zone " + str(zone_camera.name) + + new_object = {"coords": coords} + + cords.append(new_object) + + extra_params.append({"coords": coords}) + if camera_algorithm.algorithm.name == "min_max_control": algorithm_items = Items.objects.filter(camera=camera_obj) areas = [] @@ -56,13 +79,6 @@ def start_process(self) -> None: } extra_params.append(new_data) - request: Dict[str, Any] = { - "camera_url": rtsp_link, - "algorithm": algorithm_obj.name, - "server_url": SERVER_URL, - "extra": extra_params, - } - try: result = send_run_request(request) except SenderError as e: @@ -72,7 +88,6 @@ def start_process(self) -> None: f"Yolo can't start algorithm {algorithm_obj.name} on camera {camera_obj.id}. Details: {e}" ) else: - pass new_process_id = result["pid"] camera_algorithm.process_id = new_process_id camera_algorithm.save() From 0d854991ba63221d44b56eaeb61d15268b289194 Mon Sep 17 00:00:00 2001 From: RasulMakhmudov Date: Thu, 15 Jun 2023 14:29:00 +0300 Subject: [PATCH 21/23] [EDIT] just report --- src/newOrderView/services/operations.py | 48 +++++-------------------- 1 file changed, 8 insertions(+), 40 deletions(-) diff --git a/src/newOrderView/services/operations.py b/src/newOrderView/services/operations.py index 86913bda..b653a6a2 100644 --- a/src/newOrderView/services/operations.py +++ b/src/newOrderView/services/operations.py @@ -153,46 +153,14 @@ def get_operations(from_date: str, to_date: str) -> List[Dict[str, Any]]: datetime.strptime(stop_tracking, "%Y-%m-%d %H:%M:%S.%f").timestamp() ) - day_start = datetime.strptime(start_tracking, "%Y-%m-%d %H:%M:%S.%f") - day_start = day_start.replace(hour=6, minute=0, second=0, microsecond=0) - - day_end = datetime.strptime(stop_tracking, "%Y-%m-%d %H:%M:%S.%f") - day_end = day_end.replace(hour=20, minute=0, second=0, microsecond=0) - - # Check if sTime is after the day start, and if so, add a report for the period between day start and sTime - if sTime > day_start.timestamp(): - morning_report = { - "zoneId": machine_control_report_id, - "orId": zone_name, - "sTime": int(day_start.timestamp()) * 1000, - "eTime": sTime * 1000, - } - machine_reports.append(morning_report) - - # Check if eTime is before the day end, and if so, add a report for the period between eTime and day end - if eTime < day_end.timestamp(): - evening_report = { - "zoneId": machine_control_report_id, - "orId": zone_name, - "sTime": eTime * 1000, - "eTime": int(day_end.timestamp()) * 1000, - } - machine_reports.append(evening_report) - - # Exclude the time period covered by the report from the daily range - if sTime < day_end.timestamp() and eTime > day_start.timestamp(): - day_start = max(day_start, datetime.fromtimestamp(eTime)) - day_end = min(day_end, datetime.fromtimestamp(sTime)) - - # Check if there is still a valid time range after excluding the report - if day_start < day_end: - daytime_report = { - "zoneId": machine_control_report_id, - "orId": zone_name, - "sTime": int(day_start.timestamp()) * 1000, - "eTime": int(day_end.timestamp()) * 1000, - } - machine_reports.append(daytime_report) + report_data: Dict[str, Any] = { + "zoneId": machine_control_report_id, + "orId": zone_name, + "sTime": sTime * 1000, + "eTime": eTime * 1000, + } + + machine_reports.append(report_data) machine_result = { "oprTypeID": zone_id, From 8e42db7a73cab4d2d115868e6471f09b5c5ebedc Mon Sep 17 00:00:00 2001 From: anikeenko Date: Thu, 15 Jun 2023 14:29:35 +0300 Subject: [PATCH 22/23] EDIT report min_max --- src/Inventory/service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Inventory/service.py b/src/Inventory/service.py index 59d325f7..8217064c 100644 --- a/src/Inventory/service.py +++ b/src/Inventory/service.py @@ -21,7 +21,7 @@ def process_item_status(data): data_item = Items.objects.filter(id=item_data['itemId']).values('current_stock_level', 'low_stock_level', 'status', 'multi_row') min_item = data_item[0]['low_stock_level'] - image_path = item_data['image_item'] + image_path = item_data['image'] level_previous_status = data_item[0]['status'] item = Items.objects.filter(id=item_data['itemId']).first() if data_item[0]['multi_row']: From 7efd071d17620e9cda64fbef3ed32f33805068df Mon Sep 17 00:00:00 2001 From: anikeenko Date: Thu, 15 Jun 2023 14:40:58 +0300 Subject: [PATCH 23/23] EDIT report min_max --- src/Inventory/service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Inventory/service.py b/src/Inventory/service.py index 8217064c..59d325f7 100644 --- a/src/Inventory/service.py +++ b/src/Inventory/service.py @@ -21,7 +21,7 @@ def process_item_status(data): data_item = Items.objects.filter(id=item_data['itemId']).values('current_stock_level', 'low_stock_level', 'status', 'multi_row') min_item = data_item[0]['low_stock_level'] - image_path = item_data['image'] + image_path = item_data['image_item'] level_previous_status = data_item[0]['status'] item = Items.objects.filter(id=item_data['itemId']).first() if data_item[0]['multi_row']: