Instructions:
The project focuses on the use of FMCW radar.
It is used for data collection, point detection, tracking and other functions.
The project is broken down into several modules.
The aim of this division is to decouple as much as possible the functionalities present in each module, and make the development of new functionalities more flexible and rapid.

Some information will be presented to you in json format:
- module: the name of the module
- module_structure: the structure of the module (the files making up the module and their hierarchy)
- module_files_already_generated_doc: the documentation of the module's files if already generated
- other_modules_doc: the documentation of the other modules on which the module depends (possibly none at all)
- gen_doc_of_file: the file you will be given to generate the documentation of. If no file is given, the documentation of the entire module must be generated.
Your goal is to create a markdown documentation of the file you will be given, or the entire module if no file is given.
This documentation is intended to guide a developer who is new to the project, you can therefore add whatever you feel is relevant for this task.


Informations:
{"module": "radar_area_detection", "module_structure": "radar_area_detection/detection.py;radar_area_detection/display.py;radar_area_detection/main.py;radar_area_detection\\comm/camera_alert.py;radar_area_detection\\comm/rabbitmq.py;radar_area_detection\\conf/6432_ti_config.cfg;radar_area_detection\\conf/6843_ti_config.cfg;radar_area_detection\\conf/detection_conf.json;radar_area_detection\\conf/main.json;radar_area_detection\\conf/rabbitmq_conf.json;radar_area_detection\\conf/tracking_conf.json;", "module_files_already_generated_doc": [{"file": "docs\\radar_area_detection\\display.md", "doc": "# radar_area_detection/display.py Documentation\n\n## Overview\n\nThe `display.py` script is part of the [radar_area_detection](radar_area_detection.md) module, which integrates with the area detection and object tracking functionalities. This script specifically provides visualization capabilities, extending the `TrackingDisplay2D` class from the radar_tracking module to represent detection areas and the status of those areas (either as \"ok\" or under \"alert\").\n\n## File Structure\n\ndisplay.py includes the following class:\n\n- `AreasDisplay2D`: Extends the `TrackingDisplay2D` class to display detection areas and denote their status on a 2D plot.\n\n### AreasDisplay2D Class\n\nThe `AreasDisplay2D` class is responsible for visualizing areas on a 2D display, differentiating between areas that are clear (ok) and those that have an active alert. It allows real-time updates of the visualization as the status of the areas changes according to the radar data.\n\n#### Constructor\n\n- **\\_\\_init__(self, *args, \\*\\*kwargs)**: Initializes the `AreasDisplay2D` class with arguments passed to its superclass and initializes an empty list for patches.\n\n#### Attributes\n\n- **patches**: List. Stores the drawing patches corresponding to areas on the display.\n\n#### Methods\n\n- **_prepare_draw(self, clusters, ok_areas: List[Area], alert_areas: List[Area])**: Internally prepares the drawing of the clusters and areas. It removes any existing patches and re-adds them according to the updated area states.\n- **show(self, clusters, area_detector: AreaDetector)**: Public method to display the radar clusters and areas. This method calls _prepare_draw with the ok_areas and alert_areas from an AreaDetector instance and then proceeds to draw the updated visualization.\n\n### Integration with Other Modules\n\nThe detect.py script in the [radar_area_detection](radar_area_detection.md) module interacts with the AreasDisplay2D class to visualize active areas and alerts. Moreover, the AreasDisplay2D class uses functionality from the radar_tracking module\u00e2\u20ac\u2122s visualization utilities, signifying how various modules within the system come together to fulfill the project\u00e2\u20ac\u2122s overall objectives.\n\n## Usage\n\nDevelopers can instantiate the `AreasDisplay2D` class to visualise the area detection results in the context of FMCW radar applications. This enables a graphical representation of which areas are clear (ok) and which are under alert.\n\n## Data Flow\n\n1. An instance of `AreasDisplay2D` is created with appropriate arguments.\n2. Radar data (clusters) and area statuses are processed by an `AreaDetector`.\n3. Area statuses and clusters are passed to the `AreasDisplay2D` instance\u00e2\u20ac\u2122s show method.\n4. The show method updates the visual representation according to the current state of detection areas and tracked clusters.\n\n## Developer Notes\n\n- Use the `AreasDisplay2D` class to create a visual feedback loop for area detection and alert visualization in real-time radar applications.\n- Ensure active areas and their statuses are correctly updated and reflected in the visualization to provide continuous situational awareness.\n- The visual representation is crucial for debugging and monitoring the radar area detection functionality, hence strive for clear visual distinction between different states for better readability and interpretation.\n\n## Conclusion\n\n`display.py` within the [radar_area_detection](radar_area_detection.md) module serves a pivotal role in visually representing the status of detection areas in real-time. The AreasDisplay2D class demonstrates an effective integration of visualization techniques with radar detection and tracking capabilities. It contributes to the wider goal of creating a modular and adaptable system for FMCW radar applications.\n\n[Radar Area Detection](radar_area_detection.md)"}, {"file": "docs\\radar_area_detection\\comm\\camera_alert.md", "doc": "# radar_area_detection/comm/camera_alert.py Documentation\n\n## Overview\n\nThe `camera_alert.py` script resides within the radar_area_detection.comm submodule of the [radar_area_detection](../radar_area_detection.md) module. This script defines a concrete implementation of an alert system based on camera activation, which integrates with the radar area detection system to respond to specific detection events using web requests.\n\n## File Structure\n\n`camera_alert.py` contains the following class:\n\n- `CameraAlert`: This class extends the abstract base Alert class, specifying actions to perform when an alert must be raised or cleared via camera control.\n\n### CameraAlert Class\n\nThe `CameraAlert` class is designed to send commands to a networked camera to start or stop recording based on area detection alerts.\n\n#### Constructor\n\n- `__init__(self, ip, port)`: Initializes the CameraAlert with network configurations.\n\n#### Attributes\n\n- `ip`: String. The IP address of the camera.\n- `port`: Integer. The port number to access the camera.\n\n#### Methods\n\n- `RaiseAlert`: Sends an HTTP POST request to the camera\u00e2\u20ac\u2122s server to start recording when an alert is raised.\n- `ClearAlert`: Sends an HTTP POST request to the camera\u00e2\u20ac\u2122s server to stop recording when an alert is cleared.\n\n## Integration with Other Modules\n\nCameraAlert extends the Alert class from [radar_area_detection.detection](../detection.md), linking camera control to the area detection logic using polymorphism.\n\n## Usage\n\nThe `CameraAlert` class may be instantiated and passed to AreaDetector instances within detection.py to specify that the camera should react to detection events.\n\nDevelopers can use this script as follows:\n\n1. Instantiate the `CameraAlert` with the appropriate IP and port for the camera.\n2. Integrate the instance with the area detection system so the camera actions are triggered during alert conditions.\n\n## Error Handling\n\nThis script catches exceptions during the HTTP request process and prints an error message, which helps to identify network or camera accessibility issues.\n\n## External Dependence\n\n`camera_alert.py` depends on the requests library to perform HTTP requests. Make sure that requests is installed and available in the project\u00e2\u20ac\u2122s environment.\n\n## Data Flow\n\n1. The area detection system determines that an alert condition is met.\n2. AreaDetector triggers the RaiseAlert method on the CameraAlert instance.\n3. CameraAlert sends an HTTP request to the camera to start or stop recording based on the state of the alert.\n\n## Developer Notes\n\nDevelopers looking to further customize behavior or add features should consider:\n\n- Expanding the CameraAlert class to handle more sophisticated network protocols or add authentication as needed.\n- Implementing retry logic or asynchronous requests if the synchronous POST request model proves to be a bottleneck or if the timeout parameter needs adjustment.\n- Adding logging mechanisms to capture successful interactions and failed attempts for better operational visibility.\n\n## Conclusion\n\nThe `camera_alert.py` script effectively bridges the gap between radar area detection and physical security measures, empowering the system to take real-world, automated actions in response to detection events. By following the robust design principle of extending an abstract base class, this module enhances the flexibility and scalability of the overall radar area detection mechanism.\n\n[Radar Area Detection](../radar_area_detection.md)"}, {"file": "docs\\radar_area_detection\\comm\\rabbitmq.md", "doc": "# Radar Area Detection: RabbitMQ Communication Interface\n\n## Overview\n\nThe rabbitmq.py is located within the radar_area_detection.comm submodule of the radar_area_detection module. This script facilitates communication between the radar area detection system and RabbitMQ message broker. The role of this interface is to enable the sending of JSON formatted data concerning area detection events and statuses over a network.\n\n## Features\n\n- Establishes a connection to RabbitMQ server using given host and port information.\n- Allows for the declaration of queues where messages will be posted.\n- Provides methods to send JSON data to specified queues.\n- Enables clean disconnection from the RabbitMQ server.\n\n## Class: RabbitMQSender\n\n### Constructor\n\n- __init__(self, host, port, queue, exchange)\nInitializes the RabbitMQSender instance with network and channel configurations.\n\n#### Parameters\n\n- host: String representing the RabbitMQ server\u00e2\u20ac\u2122s hostname.\n- port: Integer for the network port on which the RabbitMQ service is listening.\n- queue: The queue name where messages will be sent.\n- exchange: The exchange parameter specifies the exchange that the message should be routed through.\n\n### Methods\n\n- connect()\nInitiates a connection to the RabbitMQ server and declares a messaging queue.\n\n- send_json(self, data)\nSends JSON formatted data through the established channel to the specified queue.\n\n- disconnect()\nCloses the connection with the RabbitMQ server to release network resources.\n\n- configure_rabbitmq(rabbitmq_conf)\nStatic method that configures and returns a RabbitMQSender object if enabled in the configuration.\n\n#### Parameters\n\n- rabbitmq_conf: A dictionary containing RabbitMQ configuration including host, port, queue, and exchange.\n\n## Integration with Other Modules\n\nWhile not documented within the other_modules_doc, it\u00e2\u20ac\u2122s implied that this class would be used in concert with the radar_area_detection module\u00e2\u20ac\u2122s detection and alerting components. Its functionality would be particularly useful when transmitting alerts or status updates to other systems monitoring or acting based on area intrusion detection.\n\n## Usage Instructions\n\n1. Include the rabbitmq.py within your project\u00e2\u20ac\u2122s communication package.\n2. Utilize the RabbitMQSender.configure_rabbitmq() static method to provide a ready-to-use configured instance based on your RabbitMQ settings.\n3. Use the send_json method to publish messages to your RabbitMQ server as needed.\n4. Properly call disconnect to ensure graceful shutdown and cleanup of connections.\n\n## Developer Notes\n\n- Make sure RabbitMQ service is running and accessible on the specified host and port before attempting a connection.\n- Implement appropriate error handling and logging when sending messages to track any communication issues or message delivery failures.\n- Depending on the size and frequency of messages, consider potential impact on network resources and optimize the sending strategy accordingly (batching, async sending, etc.).\n- In a multi-threaded or async application, ensure thread-safety or proper synchronization when interacting with the RabbitMQ connection.\n\n## Conclusion\n\nThe rabbitmq.py script provides a straightforward and efficient means of interfacing with a RabbitMQ server to send alerts and data from the radar area detection system. It enables real-time communication and coordination with other systems within a larger infrastructure that relies on timely and reliable delivery of radar detection events."}, {"file": "docs\\radar_area_detection\\conf\\detection_conf.md", "doc": "# detection_conf.json Documentation\n\n## Overview\n\nThis documentation provides an overview of the configuration file `detection_conf.json` used within the [Radar Area Detection module](../radar_area_detection.md).\n\n## Parameters\n\n`detection_conf.json` example:\n\n```json\n{\n  \"areas\": [[-1, 1, 0.5, 2.5]],\n  \"camera\": {\n    \"enable\": true,\n    \"ip\": \"127.0.0.1\",\n    \"port\": 5000\n  }\n}\n```\n\n- `areas`: A list of detection areas, where each area is defined by a list of four floats representing the boundaries in Cartesian coordinates. Coordinates follow the order [x_left, x_right, y_bottom, y_top]. Example: [-1, 1, 0.5, 2.5] defines an area that extends from -1 to 1 along the x-axis, and from 0.5 to 2.5 along the y-axis.\n- `camera`: A configuration object for camera alert integration.\n  - `enable`: A boolean flag that indicates whether the camera alert functionality should be active.\n  - `ip`: A string specifying the IP address of the networked camera.\n  - `port`: An integer representing the port number to access the camera services.\n\n[Radar Area Detection](../radar_area_detection.md)"}, {"file": "docs\\radar_area_detection\\conf\\main.md", "doc": "# main.json Documentation\n\n## Overview\n\nThis documentation provides an overview of the configuration file `main.json` used within the [Radar Area Detection module](../radar_area_detection.md).\n\n## Parameters\n\n`main.json` example:\n\n```json\n{\n  \"cfg_file_path\": \"conf/6432_ti_config.cfg\",\n  \"model\": \"6432\",\n  \"CLI_port\": \"/dev/ttyUSB0\",\n  \"data_port\": \"/dev/ttyUSB1\",\n  \"horizontal_inclination\": 0,\n  \"vertical_inclination\": null,\n  \"min_point_vel\": 0.1,\n  \"local_display\": false,\n  \"area_detection_conf\": \"conf/detection_conf.json\",\n  \"tracking_conf\": \"conf/tracking_conf.json\",\n  \"rabbitmq_conf\": \"conf/rabbitmq_conf.json\"\n}\n```\n\n- `cfg_file_path`: radar configuration file path relative to main script executation location.\n- `model`: radar model [\"1642\", \"6843\", \"6432\"]\n- `CLI_port`: CLI port for radar data acquisition.\n- `data_port`: data port for radar data acquisition.\n- `horizontal_inclination`: radar horizontal inclination (degrees).\n- `vertical_inclination`: radar vertical inclination (degrees).\n- `min_point_vel`: minimum velocity of detected points (m/s).\n- `local_display`: display radar data locally.\n- `area_detection_conf`: area detection configuration file path.\n- `tracking_conf`: tracking configuration file path.\n- `rabbitmq_conf`: RabbitMQ configuration file path.\n\n[Radar Area Detection](../radar_area_detection.md)"}, {"file": "docs\\radar_area_detection\\conf\\rabbitmq_conf.md", "doc": "# rabbitmq_conf.json Documentation\n\n## Overview\n\nThis documentation provides an overview of the configuration file `rabbitmq_conf.json` used within the [Radar Area Detection module](../radar_area_detection.md).\n\n## Parameters\n\n`main.json` example:\n\n```json\n{\n  \"enable\": true,\n  \"host\": \"102.168.160.35\",\n  \"port\": 5672,\n  \"queue\": \"clusters\",\n  \"exchange\": \"amq-fanout\"\n}\n```\n\n- `enable`: enable RabbitMQ\n- `host`: RabbitMQ host\n- `port`: RabbitMQ port\n- `queue`: RabbitMQ queue\n- `exchange`: RabbitMQ exchange\n\n[Radar Area Detection](../radar_area_detection.md)"}, {"file": "docs\\radar_area_detection\\conf\\tracking_conf.md", "doc": "# tracking_conf.json Documentation\n\n## Overview\n\nSee [tracking conf](../../radar_tracking/conf/tracking.md)\n\n[Radar Area Detection](../radar_area_detection.md)"}], "other_modules_doc": [{"module": "radar_visuals", "doc": "# radar_visuals Module Documentation\n\n## Overview\n\nThe `radar_visuals` module is a dedicated visualization package within a project focused on the use of Frequency Modulated Continuous Wave (FMCW) radar. It is designed to provide tools and utilities for the rendering of radar data in various visual formats, supporting functionalities like data collection, point detection, and tracking analysis. The module aims to facilitate rapid development and integration of new visualization features through a decoupled and flexible structure.\n\n## Module Structure\n\nThe `radar_visuals` module currently contains the following file:\n\n- [display.py](display.md): A Python script offering a suite of classes and functions for creating dynamic and static displays for radar data visualization.\n\n## Module Files Documentation\n\n### [display.py](display.md)\n\nThe [display.py](display.md) file within the radar_visuals package encompasses multiple visualization methods and is central to the module. Below is a summary of the provided documentation:\n\n#### Overview\nThe script is essential for visualizing radar data and includes capabilities for 2D, 3D, and polar plotting. It is versatile enough to accommodate both real-time and static data presentations.\n\n#### Components\nEnums such as **PlayingMode**, **Projection**, and **GraphType** allow the user to define the display behavior, the plot\u00e2\u20ac\u2122s projection type, and the graph style, respectively. Along with utility functions like color_from_id and plot_signal, the script provides two main classes:\n\n- `UpdatableDisplay`: The abstract base class for displays that can be updated, initializing the figure, axes, and other graphical elements.\n- `SimpleUpdatableDisplay`: A concrete implementation of UpdatableDisplay that prepares and updates displays with new data points.\n\n#### Functionalities\nThe primary functionalities include creating interactive graphs to visualize radar data, updating them according to predefined playing modes, and ensuring compatibility with different data types and visual projections.\n\n#### Data Flow\nThe typical workflow involves:\n1. Initializing a display object with the required properties.\n2. Accumulating or simulating radar data points.\n3. Updating the display as new data arrives through the show() method.\n4. Presenting the visual representation of the radar data to users based on the set playing mode.\n\n#### Developer Notes\nDevelopers are advised to match data dimensions with graph types and projections, manage update rates effectively, and assign unique colors to data sources using UUIDs for better data distinction.\n\n#### Integration\nDespite being part of the radar_visuals package, [display.py](display.md) operates independently from other components, specifically focusing on visualization purposes and not on signal processing.\n\n## Usage\n\nThe module can be employed to:\n\n- Visualize FMCW radar-related data points, signals, and more complex datasets.\n- Develop new visualization tools tailored to the specifics of radar data.\n- Enhance the interpretation of radar data through graphically rich plots.\n\n## Conclusion\n\n`radar_visuals` is a crucial module for the graphical representation and analysis of radar data within a larger FMCW radar-focused project. The modular structure accommodates efficient development, enabling users and developers to easily integrate new visualization techniques suited to their specific needs. The module\u00e2\u20ac\u2122s design streamlines the translation of complex data into understandable and insightful visual formats, supporting a wide range of functionalities from debugging to presentation.\n\n[Radar SDK](../../README.md)"}, {"module": "radar_toolbox", "doc": "# radar_toolbox Module Documentation\n\n## Overview\n\nThe radar_toolbox module is a collection of tools designed for interfacing with Frequency Modulated Continuous Wave (FMCW) radar systems. It is utilized for various purposes such as data collection, point detection, and other radar signal processing functions.  \nThe module serves as the foundational toolset for FMCW radar systems, streamlining the process from initial data capture to data preparation for analytics.  \nThe module is structured to decouple functionalities into distinct units to promote flexibility and rapid development of new features.  \n\n## Module Files Documentation\n\nDevelopers new to radar_toolbox will find documentation for several key files within the module. An outline of this documentation includes:\n\n- [fmcw_utils](fmcw_utils.md)\n  - Detailed information on handling FMCW radar systems, managing configurations, processing radar signals, and transforming them into analyzable forms.\n- [utils](utils.md)\n  - A comprehensive overview of utility functions that aid in loading configurations, preprocessing radar data, and assisting with model training and coordinate adjustments.\n- [raw_data/adc](raw_data/adc.md)\n  - Documentation of the adc.py script which serves as an interface to ADC hardware, allowing for the capture and real-time processing of radar data streams.\n- [raw_data/raw_bin_to_numpy](raw_data/raw_bin_to_numpy.md)\n  - Explains the process of converting raw binary radar data into a NumPy array and the steps involved in ensuring data integrity during conversion.\n- [raw_data/record_raw_data](raw_data/record_raw_data.md)\n  - A guide to a script focused on raw data recording, detailing the initiation of data capture and subsequent data stream management.\n- [TI_data/record_ti_data](TI_data/record_ti_data.md)\n  - Documentation for a script specific to TI radar hardware, describing real-time data capture and CSV data storage functionality.\n- [TI_data/sensor_com](TI_data/sensor_com.md)\n  - Communication protocols and data structure parsing methods for TI mmWave radar boards are outlined for managing interactions with these devices.\n\n## Usage\n\nDevelopers can use the radar_toolbox module to:\n\n- Set up FMCW radar data capture sessions.\n- Record and process raw radar data.\n- Convert binary radar data captures into formats suitable for analysis, such as NumPy arrays.\n- Interact and configure TI mmWave radars for data acquisition.\n\n## Data Flow Summary\n\nThe data flow within the radar_toolbox module follows these general steps:\n\n1. Configuration is set up using JSON files and configuration profiles for the specific radar models.\n2. Data recording sessions are initiated, capturing the radar data and storing it in binary format.\n3. Raw binary data is processed, filtered, and organized into structured data arrays.\n4. Data is made ready for analysis, transformed into point clouds or other representations necessary for further processing and interpretation.\n\n## External Dependencies\n\nWhile the module works as an independent toolkit within the project scope, it interfaces with radar hardware and other software modules that handle advanced data analysis, visualization, and machine learning applications.\n\n[Radar SDK](../../README.md)"}, {"module": "radar_tracking", "doc": "# FMCW Radar Tracking Project Documentation\n\n## radar_tracking Module\n\nThe `radar_tracking` module sits at the heart of the FMCW radar project, providing algorithms and utilities focused on the tracking of objects detected by the radar system.\n\n### Module Structure\n\nThe module is composed of several scripts and a configuration file organized as follows:\n\n- [tracking_utils.py](tracking_utils.md): Utilities for configuring and initializing tracking components.\n- [conf/tracking.json](conf/tracking.md): A JSON-formatted configuration file specifying parameters for the tracking system.\n- inference/:\n  - `example_kalman_filter.py`: Perform inference using Kalman filters.\n  - `example_tracking.py`: An example script demonstrating the tracking process.\n- models/:\n  - [kalman.py](models/kalman.md): Implementations of Kalman filter for state estimation.\n  - [tracking.py](models/tracking.md): The main tracking algorithm handling the temporal correlation of clusters.\n  - clustering/:\n    - [cluster.py](models/clustering/cluster.md): Data structure for managing clusters of points.\n    - [cluster_predictor.py](models/clustering/cluster_predictor.md): Class for predicting clustering behavior based on certain algorithms.\n    - `optimizer.py`: utilities for searching best hyperparameters for clustering algorithms.\n    - algos/:\n      - `clustering_algorithm.py`: Abstract base algorithms for clustering.\n      - `dbscan.py`: DBSCAN clustering algorithm implementation.\n      - `gaussian_mixture.py`: Gaussian Mixture Model clustering implementation.\n      - `meanshift.py`: Mean Shift clustering algorithm implementation.\n- [visuals/display.py](visuals/display.md): Visualization classes for displaying the tracking data.\n\n### Dependencies\n\nThe `radar_tracking` module relies on other parts of the FMCW radar project:\n\n- [radar_toolbox](../radar_toolbox/radar_toolbox.md):\nA toolkit for interacting with the radar hardware and processing raw radar data.\n\n- [radar_visuals](../radar_visuals/radar_visuals.md):\nProvides dynamic and static displays to visualize radar data, which can be helpful to show tracking results in an accessible form.\n\n## Development Notes\n \nThe radar_tracking module integrates sophisticated algorithms and diverse data sets to track objects with high precision.  \nFor practical understanding, developers are encouraged to interact with example scripts inside the inference subdirectory. They illustrate how the various components come together to achieve object tracking.\n\n[Radar SDK](../../README.md)"}], "gen_doc_of_file": {"path": "radar_area_detection\\detection.py", "content": "import time\nfrom abc import ABC, abstractmethod\nfrom dataclasses import dataclass\nfrom typing import List\n\nimport numpy as np\n\n\n@dataclass\nclass Area:\n    xl: float\n    xr: float\n    yb: float\n    yt: float\n\n    def serialize(self):\n        return {\n            \"xl\": self.xl,\n            \"xr\": self.xr,\n            \"yb\": self.yb,\n            \"yt\": self.yt\n        }\n\n    def __hash__(self):\n        return hash((self.xl, self.xr, self.yb, self.yt))\n\n\nclass Alert(ABC):\n    @abstractmethod\n    def RaiseAlert(self):\n        pass\n\n    @abstractmethod\n    def ClearAlert(self):\n        pass\n\n\nclass AreaDetector:\n    def __init__(self, areas, alerts: List[Alert] = None, alert_delay_time=0):\n        self.alerts = alerts\n        self.alert_delay_time = alert_delay_time\n        self.areas = []\n        for area in areas:\n            assert len(area) == 4, \"Each area must be made of 4 values: [x left, x right, y bottom, y top]\"\n            self.areas.append(Area(*area))\n        self.ok_areas = set()\n        self.suspected_areas = {}\n        self.alert_areas = set()\n        self.alert_triggered = False\n\n    def update(self, clusters_up_to_date):\n        \"\"\"\n        To call every step.\n        :param clusters_up_to_date: list of tracked clusters.\n        \"\"\"\n        current_time = time.time()\n        self.ok_areas.clear()\n        for area in self.areas:\n            suspect = False\n            for cluster in clusters_up_to_date:\n                x, y = cluster.centroid[cluster.width_axis], cluster.centroid[cluster.depth_axis]\n                if area.xl <= x <= area.xr and area.yb <= y <= area.yt:\n                    suspect = True\n                    break\n            self.adjust_tracking(current_time, area, suspect)\n        self.handle_alerts()\n\n    def adjust_tracking(self, current_time, area, suspect):\n        if not suspect:\n            self.suspected_areas.pop(area, None)\n            if area in self.alert_areas:\n                self.alert_areas.remove(area)\n            self.ok_areas.add(area)\n        elif area not in self.alert_areas:\n            if area not in self.suspected_areas:\n                self.suspected_areas[area] = current_time\n            if current_time - self.suspected_areas[area] >= self.alert_delay_time:\n                self.alert_areas.add(area)\n                self.suspected_areas.pop(area)\n\n    def handle_alerts(self):\n        if self.alerts is None:\n            return\n        if len(self.alert_areas) > 0:\n            if not self.alert_triggered:\n                self.alert_triggered = True\n                for alert in self.alerts:\n                    alert.RaiseAlert()\n        else:\n            if self.alert_triggered:\n                self.alert_triggered = False\n                for alert in self.alerts:\n                    alert.ClearAlert()\n\n    def serialize(self):\n        return {\n            \"ok_areas\": [area.serialize() for area in self.ok_areas],\n            \"alert_areas\": [area.serialize() for area in self.alert_areas]\n        }\n\n\n@dataclass\nclass Profile:\n    name: str\n    avg_surface: float\n    surface_weight: float\n    avg_height: float\n    height_weight: float\n    alert_delay_time: float\n    alert: Alert\n\n    def serialize(self):\n        return {\n            \"name\": self.name,\n            \"avg_surface\": self.avg_surface,\n            \"height_weight\": self.height_weight,\n            \"alert_delay_time\": self.alert_delay_time\n        }\n\n    def __hash__(self):\n        return hash(self.name)\n\n\nclass ProfileAreaDetector:\n    def __init__(self, profiles: List[Profile], areas: List[List[float]]):\n        self.profiles = profiles\n        self.area_detectors = {\n            profile: AreaDetector(areas, alerts=[profile.alert], alert_delay_time=profile.alert_delay_time)\n            for profile in profiles\n        }\n\n        self.areas = self.area_detectors[profiles[0]].areas\n\n    def update(self, _clusters):\n        clusters_per_profile = self.filter_clusters_by_profile(_clusters)\n        for profile, clusters in clusters_per_profile.items():\n            self.area_detectors[profile].update(clusters)\n\n    def filter_clusters_by_profile(self, clusters):\n        clusters_per_profile = {profile: [] for profile in self.profiles}\n        for cluster in clusters:\n            cluster_surface = cluster.get_facing_area()\n            cluster_height = cluster.get_height()\n            profile_weights = np.zeros(len(self.profiles))\n            for idx, profile in enumerate(self.profiles):\n                surface_distance = abs(cluster_surface - profile.avg_surface) / (cluster_surface + profile.avg_surface)\n                profile_weights[idx] += profile.surface_weight * (1 - surface_distance)\n                height_distance = abs(cluster_height - profile.avg_height) / (cluster_height + profile.avg_height)\n                profile_weights[idx] += profile.height_weight * (1 - height_distance)\n            best_profile_idx = np.argmax(profile_weights)\n            best_profile = self.profiles[best_profile_idx]\n            print(f\"{best_profile.name} | Height: {cluster_height} | Surface: {cluster_surface}\")  # TODO: remove\n            clusters_per_profile[best_profile].append(cluster)\n        return clusters_per_profile\n\n    def serialize(self):\n        return {\n            profile.name: detector.serialize() for profile, detector in self.area_detectors.items()\n        }\n"}}