diff --git a/MisplaceAI/Dockerfile b/MisplaceAI/Dockerfile index 93f1a9548fca2e5a1a1390a2441fa56ce835943e..f61d8610af216673377bba0cd0539f4aad6a0351 100644 --- a/MisplaceAI/Dockerfile +++ b/MisplaceAI/Dockerfile @@ -23,7 +23,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ COPY requirements.txt /app/requirements.txt RUN pip install --no-cache-dir -r requirements.txt -# Install TensorFlow Object Detection API (this assumes models directory is already present) +# Install TensorFlow Object Detection API RUN cd /app/models/research \ && protoc object_detection/protos/*.proto --python_out=. \ && cp object_detection/packages/tf2/setup.py . \ diff --git a/MisplaceAI/admin_app/apps.py b/MisplaceAI/admin_app/apps.py index 661acc88bda93fe1bce4d1bb35fd6d88f602dcee..feec60333894e69fbe2fafebf64626eae5837f21 100644 --- a/MisplaceAI/admin_app/apps.py +++ b/MisplaceAI/admin_app/apps.py @@ -1,3 +1,4 @@ +#MisplaceAI/admin_app/apps.py from django.apps import AppConfig class AdminAppConfig(AppConfig): diff --git a/MisplaceAI/process_misplaced_manager/views.py b/MisplaceAI/process_misplaced_manager/views.py index 7a3c88ec22b9c466254cb30ef43d3ef9d75f875d..aaf6954dd6a211af6232c708d5ae8c8a2b0617b3 100644 --- a/MisplaceAI/process_misplaced_manager/views.py +++ b/MisplaceAI/process_misplaced_manager/views.py @@ -262,141 +262,4 @@ def process_video_for_misplaced_objects(video_path, frame_interval): - - - - - - - - -# class UploadedVideoViewSet(viewsets.ModelViewSet): -# queryset = UploadedVideo.objects.all() -# serializer_class = UploadedVideoSerializer -# permission_classes = [IsAuthenticated] - -# @api_view(['POST']) -# @permission_classes([IsAuthenticated]) -# def upload_video(request): -# print("Received request to upload video") -# print("Request data:", request.data) -# print("Request FILES:", request.FILES) - -# if 'video' not in request.FILES: -# print("No video file provided in request") -# return Response({'error': 'No video file provided'}, status=status.HTTP_400_BAD_REQUEST) - -# serializer = UploadedVideoSerializer(data={'video': request.FILES['video']}) -# if serializer.is_valid(): -# print("Serializer data is valid") -# serializer.save() -# print("Video successfully saved:", serializer.data) -# return Response(serializer.data, status=status.HTTP_201_CREATED) -# else: -# print("Serializer errors:", serializer.errors) -# return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - - - - - - -# @api_view(['GET']) -# @permission_classes([IsAuthenticated]) -# def display_video_results(request, video_id): -# print("Received request to display video results for video ID", video_id) -# try: -# video = get_object_or_404(UploadedVideo, id=video_id) -# video_path = video.video.path - -# print("Processing video at path:", video_path) -# detected_objects, misplaced_objects, output_video_path = process_video_for_misplaced_objects(video_path) - -# response_data = { -# 'video_url': request.build_absolute_uri(video.video.url), -# 'output_video_url': request.build_absolute_uri(settings.MEDIA_URL + 'videos/' + os.path.basename(output_video_path)), -# 'detected_objects': detected_objects, -# 'misplaced_objects': misplaced_objects -# } -# print("Successfully processed video and generated results") -# return Response(response_data, status=status.HTTP_200_OK) -# except Exception as e: -# print(f"Error processing video results: {e}") -# return JsonResponse({'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) - - - - - - - - - - - - - - - - - - - - -# def process_video_for_misplaced_objects(video_path): -# print("Starting object detection for video:", video_path) -# cap = cv2.VideoCapture(video_path) -# print("Video capture object created") -# frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) -# print("Frame width:", frame_width) -# frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) -# print("Frame height:", frame_height) -# fps = int(cap.get(cv2.CAP_PROP_FPS)) -# print("FPS:", fps) - -# output_video_path = os.path.join(settings.MEDIA_ROOT, 'videos', os.path.basename(video_path).replace('.mp4', '_annotated.mp4')) -# print("Output video path:", output_video_path) -# out = cv2.VideoWriter(output_video_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (frame_width, frame_height)) -# print("Video writer object created") -# misplaced_objects_all_frames = [] -# print("Misplaced objects list created") -# detected_objects_all_frames = [] -# print("Detected objects list created") - -# frame_count = 0 - -# while cap.isOpened(): -# print(f"Processing frame {frame_count}") -# ret, frame = cap.read() -# print("Frame read") -# if not ret: -# break -# print("Frame read successfully") -# image_np = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) -# print("Frame converted to RGB") - -# # Convert the frame to PIL image -# image_pil = Image.fromarray(image_np) - -# detected_objects = run_inference(detection_model, category_index, image_pil) -# print(f"Detected objects in frame {frame_count}: {detected_objects}") - -# placement_rules = PlacementRules() -# misplaced_objects = placement_rules.check_placement(detected_objects) -# print(f"Misplaced objects in frame {frame_count}: {misplaced_objects}") - -# detected_objects_all_frames.append(detected_objects) -# misplaced_objects_all_frames.append(misplaced_objects) - -# # Annotate the frame with bounding boxes and labels -# annotated_image_pil = visualize_pil_misplaced_objects(image_pil, detected_objects, misplaced_objects) -# annotated_image_np = np.array(annotated_image_pil) -# out.write(cv2.cvtColor(annotated_image_np, cv2.COLOR_RGB2BGR)) - -# frame_count += 1 - -# cap.release() -# out.release() - -# print("Finished processing video:", output_video_path) -# return detected_objects_all_frames, misplaced_objects_all_frames, output_video_path \ No newline at end of file + \ No newline at end of file diff --git a/MisplaceAI/requirements.txt b/MisplaceAI/requirements.txt index 288deadd1040d17007e53ed2dfccf9c16363bb05..1d8de2a3338503d89137b6ca5475623760444b88 100644 --- a/MisplaceAI/requirements.txt +++ b/MisplaceAI/requirements.txt @@ -1,7 +1,7 @@ Django==3.2 mysqlclient==2.1.0 Pillow==9.3.0 -tensorflow +tensorflow==2.16.1 opencv-python==4.5.5.64 djangorestframework==3.12.4 django-cors-headers==3.10.0 diff --git a/MisplaceAI/rules/__pycache__/views.cpython-310.pyc b/MisplaceAI/rules/__pycache__/views.cpython-310.pyc index 9954d00955e64d52f74351e51b23c8cae74bb9fd..91e3d6df835d284d3701c831bf2741222f17167a 100644 Binary files a/MisplaceAI/rules/__pycache__/views.cpython-310.pyc and b/MisplaceAI/rules/__pycache__/views.cpython-310.pyc differ diff --git a/MisplaceAI/rules/serializers.py b/MisplaceAI/rules/serializers.py index 24875e803a56358be76e5bb506f57e2661144ba0..968862ab6ede396889c30d92e77efb2f7c8dbc7f 100644 --- a/MisplaceAI/rules/serializers.py +++ b/MisplaceAI/rules/serializers.py @@ -20,7 +20,7 @@ class ItemSerializer(serializers.ModelSerializer): fields = ['id', 'name'] class RuleSerializer(serializers.ModelSerializer): - user = UserSerializer() + user = UserSerializer(read_only=True) item = ItemSerializer() locations = LocationSerializer(many=True) diff --git a/MisplaceAI/rules/views.py b/MisplaceAI/rules/views.py index c53681bd0ce19f42ff7487e87f4b33ee46926c44..3409a85f070434243c39eebaee2fc99c7669132a 100644 --- a/MisplaceAI/rules/views.py +++ b/MisplaceAI/rules/views.py @@ -80,7 +80,8 @@ class AdminManageRuleView(APIView): permission_classes = [IsAuthenticated] def get(self, request, *args, **kwargs): - rules = Rule.objects.all().order_by('id') + # Filter rules based on the authenticated user + rules = Rule.objects.filter(user=request.user).order_by('id') serializer = RuleSerializer(rules, many=True) return Response(serializer.data, status=status.HTTP_200_OK) diff --git a/frontend/src/pages/Admin/AdminUsers.js b/frontend/src/pages/Admin/AdminUsers.js index f26affaf8e21652181d78758b765d93d2918ba41..d730370cfc29f609f7c08c5406edb9554ce189c5 100644 --- a/frontend/src/pages/Admin/AdminUsers.js +++ b/frontend/src/pages/Admin/AdminUsers.js @@ -1,4 +1,5 @@ -// src/pages/Admin/AdminUsers.js +//src/pages/Admin/AdminUsers.js + import React, { useEffect, useState } from 'react'; import api from '../../services/api'; import '../../styles/main.css'; // Ensure this is the correct path to main.css @@ -8,15 +9,18 @@ const AdminUsers = () => { useEffect(() => { const fetchUsers = async () => { - const response = await api.get('/admin-app/users/'); + const response = await api.get('api/admin-app/users/'); setUsers(response.data); }; fetchUsers(); }, []); const handleDeactivate = async (userId) => { - await api.post(`/api/admin-app/users/deactivate/${userId}/`); - setUsers(users.map(user => user.id === userId ? { ...user, is_active: false } : user)); + const confirmDeactivate = window.confirm('Are you sure you want to deactivate this user?'); + if (confirmDeactivate) { + await api.post(`/api/admin-app/users/deactivate/${userId}/`); + setUsers(users.map(user => user.id === userId ? { ...user, is_active: false } : user)); + } }; const handleActivate = async (userId) => { @@ -25,8 +29,11 @@ const AdminUsers = () => { }; const handleDelete = async (userId) => { - await api.post(`/api/admin-app/users/delete/${userId}/`); - setUsers(users.filter(user => user.id !== userId)); + const confirmDelete = window.confirm('Are you sure you want to delete this user?'); + if (confirmDelete) { + await api.delete(`/api/admin-app/users/delete/${userId}/`); + setUsers(users.filter(user => user.id !== userId)); + } }; return ( diff --git a/schema.sql b/schema.sql index 35db410baedd376bfe477d7b723c5578797db971..549fdf1f9d55c86a025c510eb6b9cd0b4587fbdc 100644 --- a/schema.sql +++ b/schema.sql @@ -64,7 +64,7 @@ CREATE TABLE `auth_permission` ( PRIMARY KEY (`id`), UNIQUE KEY `auth_permission_content_type_id_codename_01ab375a_uniq` (`content_type_id`,`codename`), CONSTRAINT `auth_permission_content_type_id_2f476e4b_fk_django_co` FOREIGN KEY (`content_type_id`) REFERENCES `django_content_type` (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=49 DEFAULT CHARSET=latin1; +) ENGINE=InnoDB AUTO_INCREMENT=53 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -88,7 +88,7 @@ CREATE TABLE `auth_user` ( `date_joined` datetime(6) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1; +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -166,7 +166,7 @@ CREATE TABLE `django_content_type` ( `model` varchar(100) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `django_content_type_app_label_model_76bd3d3b_uniq` (`app_label`,`model`) -) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=latin1; +) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -182,7 +182,7 @@ CREATE TABLE `django_migrations` ( `name` varchar(255) NOT NULL, `applied` datetime(6) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=latin1; +) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -228,7 +228,7 @@ CREATE TABLE `process_misplaced_manager_uploadedimage` ( `image` varchar(100) NOT NULL, `uploaded_at` datetime(6) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -242,8 +242,31 @@ CREATE TABLE `process_misplaced_manager_uploadedvideo` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `video` varchar(100) NOT NULL, `uploaded_at` datetime(6) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; + `user_id` int(11) NOT NULL, + `user_video_frame_preference_id` bigint(20) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `process_misplaced_ma_user_id_f01b3449_fk_auth_user` (`user_id`), + KEY `process_misplaced_ma_user_video_frame_pre_9a42197b_fk_process_m` (`user_video_frame_preference_id`), + CONSTRAINT `process_misplaced_ma_user_id_f01b3449_fk_auth_user` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`), + CONSTRAINT `process_misplaced_ma_user_video_frame_pre_9a42197b_fk_process_m` FOREIGN KEY (`user_video_frame_preference_id`) REFERENCES `process_misplaced_manager_uservideoframepreference` (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `process_misplaced_manager_uservideoframepreference` +-- + +DROP TABLE IF EXISTS `process_misplaced_manager_uservideoframepreference`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `process_misplaced_manager_uservideoframepreference` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `frame_interval` int(11) NOT NULL, + `user_id` int(11) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `user_id` (`user_id`), + CONSTRAINT `process_misplaced_ma_user_id_c4fd8017_fk_auth_user` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -258,7 +281,7 @@ CREATE TABLE `rules_item` ( `name` varchar(255) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; +) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -273,7 +296,7 @@ CREATE TABLE `rules_location` ( `name` varchar(255) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; +) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -292,7 +315,7 @@ CREATE TABLE `rules_rule` ( KEY `rules_rule_user_id_a3576cd9_fk_auth_user_id` (`user_id`), CONSTRAINT `rules_rule_item_id_e7fc9070_fk_rules_item_id` FOREIGN KEY (`item_id`) REFERENCES `rules_item` (`id`), CONSTRAINT `rules_rule_user_id_a3576cd9_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; +) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -311,7 +334,7 @@ CREATE TABLE `rules_rule_locations` ( KEY `rules_rule_locations_location_id_71e247a5_fk_rules_location_id` (`location_id`), CONSTRAINT `rules_rule_locations_location_id_71e247a5_fk_rules_location_id` FOREIGN KEY (`location_id`) REFERENCES `rules_location` (`id`), CONSTRAINT `rules_rule_locations_rule_id_2a81ba57_fk_rules_rule_id` FOREIGN KEY (`rule_id`) REFERENCES `rules_rule` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; +) ENGINE=InnoDB AUTO_INCREMENT=63 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; @@ -323,4 +346,4 @@ CREATE TABLE `rules_rule_locations` ( /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2024-06-25 15:35:20 +-- Dump completed on 2024-07-01 16:22:46