Personnel trajectory real-time early warning method and system based on traceable data flow
By employing the NiFi streaming processing framework, serial processing with the same key and parallel processing with different keys, and the Redis distributed lock mechanism, the problems of data disorder, concurrency conflicts, and poor transparency in existing real-time personnel trajectory early warning systems are solved, achieving efficient and accurate real-time early warning and adaptability to multiple scenarios.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-23
- Publication Date
- 2026-04-14
AI Technical Summary
Existing technologies for real-time early warning systems of personnel trajectories in urban governance and personnel management suffer from problems such as disordered data processing and concurrency conflicts, poor transparency and controllability, and insufficient real-time performance, making it difficult to meet the real-time and accuracy requirements in high-concurrency scenarios.
A real-time early warning method for personnel trajectories based on traceable data streams is adopted. Through the NiFi streaming processing framework, the data processing mode of serial processing with the same key and parallel processing with different keys, the Redis distributed lock mechanism, and the batch merging mechanism, the orderly processing and transparent management of trajectory data are achieved.
It achieves efficient and accurate real-time early warning, reduces system operation and maintenance costs, improves data transparency and system scalability, can detect abnormal behavior in a timely manner, and adapts to a variety of anomaly detection scenarios.
Smart Images

Figure CN121865202A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to, but is not limited to, the field of urban governance and smart security, and particularly relates to a method and system for real-time early warning of personnel trajectories based on traceable data streams. Background Technology
[0002] Currently, in the fields of urban governance, public security management, and social services, the demand for trajectory monitoring of grassroots staff such as data collectors and grid workers is increasing. These staff members undertake tasks such as information collection, door-to-door visits, security patrols, environmental monitoring, and grid management in their daily work. Their activity range often covers streets, communities, and even larger areas throughout the city. With the development of digitalization and informatization in work, management departments generally require data collectors to regularly upload location information and work status via mobile terminal devices or dedicated data collection apps, so that the management system can monitor their activity trajectories and work distribution in real time. Through the analysis of trajectory data, managers can determine whether data collectors are on duty, whether they enter their assigned grid on time, and whether they have stayed for extended periods or left their work area, thus providing a basis for personnel management, task allocation, and performance evaluation. Existing technologies commonly implement trajectory data analysis in two main ways: The first is a real-time processing solution based on traditional streaming computing platforms (such as Flink and Spark Streaming). This type of solution uses streaming computing tasks to aggregate and calculate the trajectory data generated by personnel in real time, thereby determining whether abnormal behaviors such as leaving their posts, prolonged stays, or exceeding the grid range have occurred. The second type is an offline analysis scheme based on timed batch processing (such as timed batch processing tasks commonly found in big data platforms). This scheme performs periodic batch processing and calculation on trajectory data offline to identify potential abnormal behaviors.
[0003] Disadvantages of existing technology: The first real-time processing solution based on traditional streaming computing platforms has several obvious drawbacks: high system debugging complexity, large adjustment costs when business rules change, lack of visualization support for data processing flow, low overall transparency, and limited operation and maintenance and iteration efficiency.
[0004] The second method involves periodically batch processing and calculating trajectory data offline to identify potential abnormal behaviors. However, its main drawback is poor real-time performance, with processing results typically experiencing delays ranging from several minutes to several hours, making it difficult to meet the needs of application scenarios requiring real-time early warning and immediate intervention. Summary of the Invention
[0005] To address the problems existing in the prior art, this invention provides a method for real-time early warning of personnel trajectories based on traceable data streams.
[0006] This invention is implemented as follows: a real-time early warning method for personnel trajectories based on traceable data streams, the method comprising: S1: The acquisition terminal reports a message containing a unified ID, timestamp and location information every few seconds, which is then parsed and standardized by Apache NiFi through a Kafka message queue. S2 uses NiFi to stream trajectory data and determines whether the interruption of the trajectory of the data collector exceeds the preset time by using offline detection rules and generates an early warning. S3 writes the early warning information into the database and displays it through the early warning platform.
[0007] Furthermore, S2 specifically includes: The system includes an offline alert for data collectors. A data collector is considered offline if there is no activity tracked for 5 minutes. The 5-minute timeframe can be configured, and the specific steps are as follows: (1) Data access uses the ConsumeKafka component to consume the data reported by the data collectors in real time; (2) Data parsing and validation: EvaluateJsonPath / RouteOnAttribute extracts JSON fields through EvaluateJsonPath and converts them into FlowFile attributes; RouteOnAttribute performs rule validation on important attributes such as lon and lat, and determines whether the time is within the working hours based on createTime. Data streams that do not meet the requirements are discarded. (3) Timestamp update and attribute supplementation UpdateAttribute, add partitionkey and lockkey; where partitionkey=${userId:mod(5)} divides all users into 5 groups according to user ID. If more threads are needed, the configuration can be modified; where lockkey=qzcg_track:lxyj_${userId} is the lockkey for distributed lock based on user; (4) Merge files with the same userId according to MergeContent, set a minimum of 60 flowfiles to be merged into one flowfile, and a maximum of 3 minutes to be merged into one flowfile; perform data merging first to improve the efficiency of data early warning. Since the trajectory takes several seconds, the current setting is 3 seconds, which is too much for one data point. Therefore, merge and judge again. The collector only needs 5 minutes, and the 5 minutes can be set to indicate offline if there is no trajectory, so it is not necessary to judge each one. (5) After merging the files, the specific operation of locking based on the lockkey begins. RouteOnAttribute is used to assign different collectors to 5 sub-queues based on the partitionkey to ensure that messages from the same collector enter the same partition. Before entering critical processing, the Redis interface is called through InvokeHTTP to try to acquire a distributed lock (SETNX + EXPIRE) to ensure that the data of the same collector is processed serially. If the lock is not acquired, the FlowFile is rolled back to the queue and retried later to ensure that there is no out-of-order processing. (6) The user who obtains the lock retrieves the last collection time recorded by the collector using the FetchDistributedMapCache component based on qz_track_lxyj:${userId}. If the last time is not retrieved, the earliest monitoring time of the working hours is retrieved and set as the attribute monitor_starttime. The monitor_starttime and offlineTime are placed in the header, and the flowfile merged in the previous step is placed in the body. The latest collection time and offline early warning data of the collector are generated by calling the offline calculation interface through InvokeHTTP. The process of this interface and the logic of the offline calculation interface are as follows: A. Sort the contents of the merged files in ascending order by createTime; B. Compare the minimum time and the maximum time. If they are within the offlineTime range, directly compare the minimum time with monitor_starttime. If they exceed the offlineTime, generate a warning and add it to the warningList. C. If the minimum and maximum times in the flowfile are greater than offlineTime, the minimum time is generated by comparing the monitor_starttime loop with the contents of the flowfile. If there is data with a time interval greater than offlineTime, an alert is generated and added to warnList; if there is no alert, warnsize=0 and the offline calculation interface returns. (7) After calling the offline interface, insert statement data by parsing the returned data of the interface. The main task is to determine whether warnSize is greater than 0. If it is greater than 0, the warnList is split according to the SplitJson component. Then, the content of the flowfile file is obtained by EvaluateJsonPath and converted into attributes. Then, the SQL for inserting the warning is generated by UpdateAttribute. Then, the SQL is executed by the ExecuteSQL component. In order to ensure that the lock release operation is executed after the warning SQL is executed, the last JSON of the warnList is a special flag of startTime=end. According to RouteOnAttribute, if startTime=end, proceed to the next step; if warnSize=0, proceed to the next step. (8) After the previous step is completed, use AttributesToJSON to put the latest collection time into the flowfile, and then put the latest collection time of the collector into the Redis cache through PutDistributedMapCache, where key= qz_track_lxyj:${userId};value= {"lastTime":"2025-08-2908:10:00"}; finally, reset the Redis information of key=${lockkey} through PutDistributedMapCache, and set ttl=1s to delete the lock after 1 second.
[0008] Based on the above technical solutions and the technical problems solved, the advantages and positive effects of the technical solution to be protected by this invention are as follows: This invention proposes a real-time early warning method for personnel trajectories based on traceable data streams. This method constructs a data stream pipeline through a visual streaming processing framework and groups data according to the unique identifier (userId) of each person, achieving a data processing mode of serial processing with the same key and parallel processing with different keys. This ensures the orderliness of individual personnel trajectories and the concurrency of data from multiple personnel. Combined with the Redis distributed lock mechanism, this method further guarantees the serial consistency of the same personnel trajectory during processing, effectively avoiding concurrency contention and missed warnings. High-frequency trajectory data is batch-merged to reduce system computational load and improve early warning efficiency. Based on the continuity and location information of trajectory data, anomaly detection is performed for offline warnings, stationary warnings, and grid departure warnings. Simultaneously, the entire data processing process is presented as a data stream in the visual streaming framework (NiFi), allowing business personnel to track the flow and processing results of each data point. Utilizing the traceable data stream modeling method, the early warning logic becomes transparent and controllable, facilitating debugging, maintenance, and traceability for business personnel. Based on this, this method can achieve real-time detection of multiple scenarios, including offline warnings, stationary warnings, and grid departure warnings for data collectors, promptly identifying and reporting abnormal trajectory events. In summary, this invention has technical advantages such as strong real-time performance, high transparency, high processing efficiency, and good scalability, and can provide reliable technical support for urban governance and personnel management.
[0009] The inventiveness of this invention lies in its breakthrough of the technical bottleneck of traditional streaming computing in real-time early warning scenarios for personnel trajectories, forming a complete, traceable, and efficient real-time processing system. A detailed analysis follows: First, existing technologies generally employ general-purpose streaming computing frameworks such as Spark Streaming or Flink. These frameworks cannot guarantee the strict sequential order of data from the same data collector when dealing with high-concurrency trajectory data. Due to the lack of built-in support for the "serial processing with the same key, parallel processing with different keys" mode, data is often processed out of order, leading to inaccurate warning results. This invention addresses this problem by introducing a grouping mechanism based on unique personnel identifiers. This achieves strict serial processing of trajectory data from the same data collector while maintaining parallel computing between different data collectors. This structure effectively avoids data chaos and contention, fundamentally solving the problem of warning errors caused by out-of-order trajectory data.
[0010] Secondly, traditional real-time early warning systems lack effective locking mechanisms, making it difficult to ensure data consistency in high-concurrency environments. This invention innovatively introduces a Redis distributed lock (SETNX+EXPIRE) mechanism, enabling each data collector to obtain independent atomic control during critical processing stages, eliminating data overwriting or omissions caused by concurrent operations. This mechanism achieves lightweight lock management in streaming computing, significantly improving the system's stability and reliability in high-concurrency environments, and overcoming the technical challenge of balancing lock contention and consistency in traditional data stream systems.
[0011] Furthermore, to address the computational burden caused by high-frequency data, this invention proposes a batch merging mechanism to aggregate multiple trajectories from the same data collector within a short period. This mechanism effectively reduces the system's processing load, balancing real-time performance with computational efficiency, enabling the system to maintain high throughput even under low latency conditions. This optimization approach differs from previous methods that improved performance by upgrading hardware or increasing cluster size, achieving compatibility between performance and real-time performance at the algorithmic level.
[0012] Furthermore, existing systems are mostly "black box" processes, making it difficult for business personnel to intuitively understand data flow and early warning logic, leading to difficulties in debugging and maintenance. This invention introduces a NiFi-based traceable data flow modeling framework to visualize the entire data processing process. The processing path and early warning results of each trajectory data can be tracked in real time, achieving system transparency and traceability. This not only improves the system's debugging efficiency and maintainability but also achieves full lifecycle traceable control of trajectory data flow for the first time in the industry, breaking through the closed technical bias of traditional streaming processing.
[0013] The technical solution of this invention fills a gap in the field of "real-time early warning of personnel trajectory in high-concurrency scenarios" both domestically and internationally. Previous systems struggled to simultaneously achieve real-time performance, sequentiality, and transparency. This invention, however, achieves consistency assurance through serial keying and distributed locking mechanisms, and realizes efficient and controllable data processing through batch merging and a visualized data flow model. It represents a qualitative breakthrough in both system structure and algorithm logic, solving the long-standing industry problem of balancing real-time performance and efficiency.
[0014] This invention not only overcomes the technical biases of traditional solutions, such as "uncontrollable concurrent conflicts," "difficulty in correcting data disorder," and "difficult maintenance of a black-box system," but also proposes a comprehensive solution with theoretical innovation and engineering feasibility, achieving a unified balance of efficiency, traceability, and consistency in real-time processing of personnel trajectory data. Its innovative technical effects include: significantly improved early warning accuracy, substantial reduction in system operation and maintenance costs, and enhanced data transparency and scalability, thus possessing broad application prospects and industrialization potential in multiple fields such as urban governance, public safety, and traffic monitoring.
[0015] 1. Problems and difficulties of existing technologies: Existing real-time personnel trajectory early warning systems, especially in applications related to urban governance and personnel management, have the following main problems: Out-of-order data processing and concurrency conflicts: Traditional streaming computing frameworks (such as Spark Streaming and Flink) lack built-in support for serial processing of data from the same data collector. Under high concurrency, trajectory data from different data collectors can be mixed, leading to out-of-order processing of trajectory information for the same person, which in turn affects the accuracy of early warning results.
[0016] Poor transparency and controllability: Most traditional streaming computing frameworks operate in a "black box" mode, lacking the ability to visualize streaming processing and data tracing, making it difficult for business personnel to debug, optimize, and trace the source, especially during the modification and debugging of complex early warning logic, resulting in high operation and maintenance costs.
[0017] Insufficient real-time performance and waste of resources: Many existing solutions rely on inefficient offline computing or frequent real-time processing, which results in excessive computational load. This leads to large system processing delays and failure to detect abnormal events in a timely manner when dealing with high-frequency data.
[0018] 2. How does this invention solve the problems of the prior art? To address the above problems, this invention proposes a real-time early warning method for personnel trajectories based on traceable data streams, the innovations of which include: Data processing mode with serial processing for the same key and parallel processing for different keys: This invention uses a grouping mechanism based on a unique personnel identifier (such as userId) to achieve serial processing of data from the same data collector and parallel processing of data from different data collectors, ensuring the sequentiality and consistency of the same data collector's trajectory. This solution solves the problems of disordered processing and concurrent conflicts of data from the same person in traditional streaming frameworks, improving the accuracy and consistency of early warnings.
[0019] The distributed lock mechanism ensures the consistency of trajectory data: By using the Redis distributed lock mechanism (SETNX+EXPIRE), this invention guarantees the atomicity of data from the same data collector during critical processing stages, avoiding data races and missed warnings. This mechanism solves the lock management problem in concurrent data processing, ensuring that trajectory data from different data collectors do not interfere with each other under high concurrency.
[0020] Efficient Batch Merging Mechanism: To reduce the computational load of high-frequency trajectory data on the system, this invention introduces a batch merging mechanism. This mechanism merges trajectory data collected by the same data collector within a short period, significantly improving processing efficiency and avoiding the performance overhead of processing data one by one. This solution addresses real-time issues while reducing system resource consumption.
[0021] Transparent Data Flow Modeling and Tracking: Through visualization streaming frameworks such as NiFi, this invention makes the entire data processing process transparent and traceable, allowing business personnel to track the processing path and results of each data trajectory in real time. This mechanism greatly improves the efficiency of system debugging and maintenance, and solves the problems of lack of transparency and traceability in existing technologies.
[0022] 3. Creative technical effects after problem-solving: Through the above-described technical solution, this invention successfully solves several technical problems in the prior art and brings about the following innovative technical effects: Efficient and consistent real-time data processing: By separating parallel and serial data processing and using distributed lock control, the system ensures the sequential processing of the same data collector's trajectory while improving the parallelism of data processing from multiple data collectors. This enables the system to provide efficient and accurate real-time warnings, avoiding missed warnings due to out-of-order processing or concurrent conflicts.
[0023] Enhanced system transparency: Through traceable data flow modeling, the alert logic and data flow process are completely transparent, allowing business personnel to easily track and debug the alert logic, effectively reducing system maintenance costs. Compared to the "black box" model of traditional stream computing, the transparency of this invention significantly improves the system's maintainability and scalability.
[0024] Significantly Improved Early Warning Efficiency: By batch merging trajectory data, the system can significantly reduce computational overhead, especially in high-frequency data processing scenarios, avoiding excessive consumption from processing single data points. This approach improves early warning detection efficiency, enabling the system to efficiently identify abnormal behavior with low latency.
[0025] Comprehensive scenario coverage and flexible scalability: This invention not only realizes common early warning scenarios such as offline, staying, and leaving the grid, but also has good scalability, which can easily cope with other abnormal behavior detection scenarios, such as speeding, cross-region, and staying beyond the boundary, and has higher adaptability and flexibility. Attached Figure Description
[0026] Figure 1 This is a flowchart of a real-time early warning method for personnel trajectories based on traceable data streams provided in an embodiment of the present invention; Figure 2 This is a system deployment topology diagram provided in an embodiment of the present invention; Figure 3 This is a complete NiFi flowchart for offline early warning of data collectors provided in the embodiments of the present invention; Figure 4 This is the NIFI process for adding locks and dividing users into 5 queues by user ID, provided in this embodiment of the invention. Figure 5This is the internal logic of the offline interface provided in the embodiments of the present invention; Figure 6 The parsing interface provided in this embodiment of the invention returns data for inserting early warning data; Figure 7 This is a diagram showing the offline early warning data provided in an embodiment of the present invention; Figure 8 This is a data display diagram of the data collector exiting the grid, provided in an embodiment of the present invention. Figure 9 This is a data display diagram of the collector's stay warning provided in an embodiment of the present invention. Detailed Implementation
[0027] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0028] like Figure 1 As shown, this embodiment of the invention provides a real-time early warning method for personnel trajectories based on traceable data streams. The method includes: S1: The acquisition terminal reports a message containing a unified ID, timestamp and location information every few seconds, which is then parsed and standardized by Apache NiFi through a Kafka message queue. S2 uses NiFi to stream trajectory data and determines whether the interruption of the trajectory of the data collector exceeds the preset time by using offline detection rules and generates an early warning. S3 writes the early warning information into the database and displays it through the early warning platform.
[0029] Specifically as follows: This invention provides S1: Data access and standardization. Every few seconds, the data collector's mobile phone or terminal device reports a JSON message containing a unified ID, timestamp, and location information, which is then sent to Kafka. The data is then accessed through the Kafka message queue and analyzed and standardized using Apache NiFi. The JSON format is as follows:
[0030] This invention provides S2: using Apache NiFi to consume collector trajectory data for traceable streaming processing to monitor and warn of collector trajectory. This invention provides S3: an offline alert is generated through a NIFI process, inserted into MySQL, and then the data is displayed through an alert platform.
[0031] The embodiment of the present invention provides S2 specifically including: The system includes an offline alert for data collectors. A data collector is considered offline if there is no activity tracked for 5 minutes. The 5-minute timeframe can be configured, and the specific steps are as follows: (1) Data access uses the ConsumeKafka component to consume the data reported by the data collectors in real time; (2) Data parsing and validation: EvaluateJsonPath / RouteOnAttribute extracts JSON fields through EvaluateJsonPath and converts them into FlowFile attributes; RouteOnAttribute performs rule validation on important attributes such as lon and lat, and determines whether the time is within the working hours based on createTime. Data streams that do not meet the requirements are discarded. (3) Timestamp update and attribute supplementation UpdateAttribute, add partitionkey and lockkey; where partitionkey=${userId:mod(5)} divides all users into 5 groups according to user ID. If more threads are needed, the configuration can be modified; where lockkey=qzcg_track:lxyj_${userId} is the lockkey for distributed lock based on user; (4) Merge files with the same userId according to MergeContent, set a minimum of 60 flowfiles to be merged into one flowfile, and a maximum of 3 minutes to be merged into one flowfile; perform data merging first to improve the efficiency of data early warning. Since the trajectory takes several seconds, the current setting is 3 seconds, which is too much for one data point. Therefore, merge and judge again. The collector only needs 5 minutes, and the 5 minutes can be set to indicate offline if there is no trajectory, so it is not necessary to judge each one. (5) After merging the files, the specific operation of locking based on the lockkey begins. RouteOnAttribute is used to assign different collectors to 5 sub-queues based on the partitionkey to ensure that messages from the same collector enter the same partition. Before entering critical processing, the Redis interface is called through InvokeHTTP to try to acquire a distributed lock (SETNX + EXPIRE) to ensure that the data of the same collector is processed serially. If the lock is not acquired, the FlowFile is rolled back to the queue and retried later to ensure that there is no out-of-order processing. (6) The user who obtains the lock retrieves the last collection time recorded by the collector using the FetchDistributedMapCache component based on qz_track_lxyj:${userId}. If the last time is not retrieved, the earliest monitoring time of the working hours is retrieved and set as the attribute monitor_starttime. The monitor_starttime and offlineTime are placed in the header, and the flowfile merged in the previous step is placed in the body. The latest collection time and offline early warning data of the collector are generated by calling the offline calculation interface through InvokeHTTP. The process of this interface and the logic of the offline calculation interface are as follows: A. Sort the contents of the merged files in ascending order by createTime; B. Compare the minimum time and the maximum time. If they are within the offlineTime range, directly compare the minimum time with monitor_starttime. If they exceed the offlineTime, generate a warning and add it to the warningList. C. If the minimum and maximum times in the flowfile are greater than offlineTime, the minimum time is generated by comparing the monitor_starttime loop with the contents of the flowfile. If there is data with a time interval greater than offlineTime, an alert is generated and added to warnList; if there is no alert, warnsize=0 and the offline calculation interface returns. (7) After calling the offline interface, insert statement data by parsing the returned data of the interface. The main task is to determine whether warnSize is greater than 0. If it is greater than 0, the warnList is split according to the SplitJson component. Then, the content of the flowfile file is obtained by EvaluateJsonPath and converted into attributes. Then, the SQL for inserting the warning is generated by UpdateAttribute. Then, the SQL is executed by the ExecuteSQL component. In order to ensure that the lock release operation is executed after the warning SQL is executed, the last JSON of the warnList is a special flag of startTime=end. According to RouteOnAttribute, if startTime=end, proceed to the next step; if warnSize=0, proceed to the next step. (8) After the previous step is completed, use AttributesToJSON to put the latest collection time into the flowfile, and then put the latest collection time of the collector into the Redis cache through PutDistributedMapCache, where key= qz_track_lxyj:${userId};value= {"lastTime":"2025-08-2908:10:00"}; finally, reset the Redis information of key=${lockkey} through PutDistributedMapCache, and set ttl=1s to delete the lock after 1 second.
[0032] Figure 2 System deployment topology diagram; Figure 3 A complete flowchart of the offline early warning process for data collectors; Figure 4 Adding locks - NIFI process with 5 queues based on user ID Figure 5 The internal logic of the offline interface; Figure 6 The parsing interface returns data to insert early warning data.
[0033] Example 1 In a municipal environmental inspection project, data collectors use a self-developed app on their mobile phones to report JSON messages containing user IDs, timestamps, and latitude and longitude every 3 seconds. These messages first enter a Kafka message queue, and then are consumed by Apache NiFi and uniformly transformed into a standardized data stream to ensure consistent data format across different devices. The standardized data contains accurate timestamps and location fields, enabling efficient identification and utilization in subsequent processing.
[0034] This method allows the system to access data from hundreds of data collectors in real time and complete standardization processing within milliseconds, avoiding trajectory loss due to inconsistent data formats. Ultimately, it ensures complete recording of personnel trajectories, laying the foundation for subsequent offline detection and early warning.
[0035] Example 2 In enterprise logistics monitoring scenarios, NiFi consumes real-time trajectory messages through ConsumeKafka, extracts fields such as lon, lat, and createTime using EvaluateJsonPath, and validates data validity using RouteOnAttribute. If the location information is empty or the timestamp is outside the working time range, the message is discarded to prevent invalid data from entering the system.
[0036] A rigorous data verification mechanism ensures the authenticity and validity of trajectory data entering the monitoring stage. This prevents misjudgments caused by false location or invalid time information, ensuring the accuracy of subsequent offline detection.
[0037] Example 3 In public safety personnel management, the system uses UpdateAttribute to generate partitionkey and lockkey. The partitionkey is grouped by modulo user ID, dividing the data collectors into 5 sub-queues. The lockkey is a unique key generated by concatenating user IDs. Subsequently, NiFi merges the trajectory data of the same user, setting the rule to form a FlowFile with a minimum of 60 messages or a maximum of 3 minutes.
[0038] This merging method effectively reduces computational overhead and avoids over-judging individual data entries, thereby improving offline detection efficiency. With a trajectory reporting frequency of 3 seconds, merging every 3 minutes ensures sufficient granularity without excessive data latency.
[0039] Example 4 In the urban sanitation attendance system, NiFi distributes the merged trajectory FlowFile across 5 partitions and attempts to acquire a distributed lock by accessing Redis via InvokeHTTP. If a user's lock is already held, the FlowFile will fall back to the queue and retry later; if the lock is successfully acquired, the system will proceed to the critical processing logic.
[0040] By employing a distributed lock mechanism, the trajectory data of the same user is always processed sequentially within the same thread, preventing data disorder and duplicate alerts. This ensures the orderliness and consistency of trajectory data even under multi-threaded concurrent processing.
[0041] Example 5 In the construction site safety monitoring system, the merged trajectory data enters the offline detection interface. The system first sorts the trajectory points by timestamp, and then compares the minimum time with the maximum time. If the entire time span is less than 5 minutes, the minimum time is compared with the monitoring start time to determine if the offline duration has been exceeded; if the span is greater than 5 minutes, the system iterates through the time differences between all points, and if there is an interval exceeding 5 minutes, the system immediately generates an alert.
[0042] This logic can handle both short-term missing reports and long-term interruptions, ensuring that offline personnel alerts are not missed. The alert information recorded by the warnList clearly reflects the time periods when personnel movements are missing.
[0043] Example 6 In railway maintenance projects, the offline detection interface returns a warnList in JSON format, containing a warnSize and multiple warning records. After NiFi parses the returned result, it determines the subsequent processing based on whether the warnSize is greater than 0. If it is greater than 0, it splits the warnList into multiple records using SplitJson and converts them into SQL insert statements to write to the MySQL database.
[0044] After the database write is complete, the system checks the last entry in the `warnList` marked with `startTime=end` to determine if all warnings have been inserted before releasing the distributed lock. This ensures that the lock is released only after all data has been completely written to the database, preventing write loss.
[0045] Example 7 In the large supermarket personnel patrol system, after the early warning data is inserted into the database, the system uses the AttributesToJSON component to write the latest collection time to FlowFile, and calls PutDistributedMapCache to update the user's latest trajectory time to the Redis cache. The key is qz_track_lxyj:userId, and the value is a JSON structure containing lastTime.
[0046] By caching the latest trajectory time in Redis, the system can directly read and compare it on the next detection, reducing redundant calculations. Meanwhile, the lock key's expiration time is set to 1 second, enabling automatic deletion and avoiding blocking issues caused by unreleased locks.
[0047] Example 8 In a smart park monitoring project, the system supports dynamically configuring offline thresholds. Administrators can adjust the offline judgment time from 5 minutes to 10 minutes via the platform interface to adapt to different work scenarios. This configuration is synchronously written to the NiFi process parameters, affecting subsequent trajectory comparison rules.
[0048] This configurable mechanism ensures the flexibility of the early warning system, allowing for rapid switching of detection standards across different scenarios. For example, a shorter offline threshold can be set for positions requiring high-frequency patrols, while a longer threshold can be set for resident positions, improving the system's applicability.
[0049] Example 9 In power line inspection systems, the trajectory early warning function can be linked with a visualization platform. When a new early warning is inserted into the database, the platform front-end will retrieve and highlight the location of the abnormal personnel in real time, allowing managers to immediately pinpoint the last location of that person.
[0050] By integrating with the platform, early warnings go beyond just data and are presented in a more intuitive way, significantly improving the response efficiency of managers. This visualized early warning system can notify managers immediately, reducing potential security risks.
[0051] Example 10 In the emergency response drill, hundreds of data collectors simultaneously reported their travel history. The system processed the data in parallel across five partitions, with an average of 20 users allocated to each partition. Thanks to Redis distributed locks, which ensured sequential processing for the same user, the system was able to stably output alert results even under high concurrency.
[0052] This embodiment verifies that the system can maintain sub-second processing latency and high accuracy even in large-scale scenarios. This demonstrates that the early warning method has good scalability and practical value, and can support high-concurrency trajectory monitoring tasks.
[0053] Evidence related to the technical effects obtained by the embodiments of the present invention.
[0054] 1. Effect Figure 7 Offline early warning data display by data collectors Effect Figure 7 This image showcases a portion of the data interface of the data collector offline early warning system. It displays the data collector's trajectory information, work area, and offline status monitored by the system. By tracking the data collector's behavior in real time, the system automatically triggers an offline early warning once it detects that the collector has failed to report data for a set period. The system interface will then display the offline warning information, helping managers respond quickly.
[0055] Related technical effects: Real-time monitoring: The system can collect and process the trajectory information of the data collectors in real time, ensuring that the status of each data collector is updated in a timely manner.
[0056] Transparency: All data streams and early warning information are clearly displayed, allowing managers to intuitively see the trajectory and work status of each data collector, thus improving the transparency and controllability of early warnings.
[0057] 2. Effects Figure 8 Data collection operator exiting the grid: Early warning data display Effect Figure 8 The system demonstrates a data collector exiting a grid alert. By comparing the data collector's current location with the assigned grid area, the system detects whether the data collector has crossed the designated area. The image shows the location information, work area, and alert status of multiple data collectors (e.g., "within the Sangshu Village grid" or "outside the Shenghu Village grid").
[0058] Related technical effects: High efficiency: Through the system's real-time trajectory processing, it can respond within seconds to whether the data collector has exceeded the grid range.
[0059] Multi-scenario coverage: The system can not only monitor offline status, but also accurately determine whether the collector has crossed the designated area, realizing multi-dimensional abnormal warning and improving the comprehensive monitoring capability of the collector's behavior.
[0060] 3. Effects Figure 9 Display of data collection personnel's stay warning. Effect Figure 9 The system interface for monitoring data collectors' prolonged stays at the same location is displayed, along with alert information. The system detects whether a data collector stays at a location for more than a set time threshold (e.g., 15 minutes) and displays the abnormal status on the interface in real time.
[0061] Related technical effects: Real-time alerts: The loitering alert can detect in real time if a data collector lingers in a non-working area for an extended period of time. The system will automatically generate an alert event to ensure timely response.
[0062] Improved efficiency: This system significantly reduces the workload of traditional manual inspections, and can automatically process and report abnormal states, thereby improving management efficiency.
[0063] 4. Experimental Data and Chart Analysis During the experiment, the real-time personnel trajectory early warning method of this invention was applied to a practical urban governance system and achieved significant technical results. The following are the system test results: Test 1: Offline Early Warning Response Time Test results show that in a real-world environment, the system's response time to offline events by data collectors is 1.2 seconds, which meets the real-time requirement (≤5 seconds).
[0064] Test 2: Early Warning Accuracy By simulating the activity data of data collectors at different time periods, the test results show that the system's early warning accuracy is 98.5% and the false alarm rate is less than 2%, which proves the system's efficiency and accuracy in handling complex scenarios (such as staying or leaving the grid).
[0065] Test 3: System Resource Consumption Even with high-frequency data reporting (multiple data entries per second), the system's CPU and memory resource utilization remained below 10%, demonstrating the high efficiency of this invention under high concurrency conditions.
[0066] Related technical effects: High real-time performance: Experimental data shows that the present invention can maintain real-time response even under high concurrency, meeting the actual needs of urban governance.
[0067] High accuracy: The system ensures high accuracy of early warning through efficient early warning algorithms and data processing mechanisms, avoiding the problems of missed and false alarms in traditional methods.
[0068] It should be noted that embodiments of the present invention can be implemented in hardware, software, or a combination of both. The hardware portion can be implemented using dedicated logic; the software portion can be stored in memory and executed by a suitable instruction execution system, such as a microprocessor or dedicated-design hardware. Those skilled in the art will understand that the above-described devices and methods can be implemented using computer-executable instructions and / or included in processor control code, for example, such code provided on a carrier medium such as a disk, CD, or DVD-ROM, a programmable memory such as read-only memory (firmware), or a data carrier such as an optical or electronic signal carrier. The devices and modules of the present invention can be implemented by hardware circuitry such as very large-scale integrated circuits or gate arrays, semiconductors such as logic chips, transistors, or programmable hardware devices such as field-programmable gate arrays, programmable logic devices, etc., or by software executed by various types of processors, or by a combination of the above-described hardware circuitry and software, such as firmware.
[0069] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any modifications, equivalent substitutions, and improvements made by those skilled in the art within the scope of the technology disclosed in the present invention, and within the spirit and principles of the present invention, should be covered within the scope of protection of the present invention.
Claims
1. A method for real-time early warning of personnel trajectories based on traceable data streams, characterized in that, include: S1: The acquisition terminal reports a message containing a unified ID, timestamp and location information every few seconds, which is then parsed and standardized by Apache NiFi through a Kafka message queue. S2 uses NiFi to stream trajectory data and determines whether the interruption of the trajectory of the data collector exceeds the preset time by using offline detection rules and generates an early warning. S3 writes the early warning information into the database and displays it through the early warning platform.
2. The method according to claim 1, characterized in that, The preset duration of trajectory interruption in S2 is 5 minutes, which can be adjusted by configuration.
3. A method for offline personnel detection based on traceable data streams, characterized in that, include: Use the ConsumeKafka component to consume real-time trajectory data; EvaluateJsonPath is used to extract message fields and convert them into attributes. RouteOnAttribute is used to validate location and time information, and data streams that do not conform to the rules are discarded. The `updateAttribute` is used to supplement the `partitionkey` and `lockkey` attributes, where `partitionkey` is obtained by taking the modulo of the user ID, and `lockkey` is generated based on the user ID. Merge trajectory data of the same user, setting a minimum of 60 data points or a maximum of 3 minutes between merges, and generate a FlowFile.
4. The method according to claim 3, characterized in that, The purpose of the merging operation is to reduce the computational load of judging a single trajectory and improve the efficiency of early warning.
5. A trajectory serialization method based on distributed locks, characterized in that, include: The RouteOnAttribute is used to assign the trajectories of different users to multiple sub-queues; Before critical processing, the Redis interface is called to acquire a distributed lock. If the lock is not acquired, the user is returned to the queue to retry. If the lock is acquired, the user's trajectory is processed in the correct order.
6. The method according to claim 5, characterized in that, The Redis lock is created using the SETNX command and an expiration time is set to prevent deadlock.
7. A method for generating offline early warnings based on historical trajectory time intervals, characterized in that, include: Obtain the minimum and maximum times of the merged trajectories; If the difference between the maximum time and the minimum time is less than the preset duration, the minimum time will be compared with the monitoring start time. If the offline duration is exceeded, an alert will be generated. If the difference between the maximum and minimum time is greater than the preset duration, the trajectory points are compared in chronological order. If there is a time interval that exceeds the offline duration, an alert is generated.
8. The method according to claim 7, characterized in that, The offline warning results are returned in JSON format and include the warnSize and warnList fields.
9. An offline early warning storage method based on database writing, characterized in that, include: The returned warning results are parsed into SQL insert statements; When warnSize is greater than 0, split warnList and generate multiple insert SQL statements, which are then written to the database using the ExecuteSQL component. The distributed lock is released only after the warning is written.
10. The method according to claim 9, characterized in that, The release of the distributed lock is accomplished through the PutDistributedMapCache component, which sets the lock key to expire and be deleted after 1 second.