Third-party APP integration method for smart energy unit

By monitoring the changes in the subscription status of MQTT client, analyzing the theme change patterns and optimizing the version retention strategy, the problem of lack of accuracy and insufficient pattern recognition in the traditional method is solved, and the response speed and pattern recognition accuracy of smart energy units are improved.

CN120448037APending Publication Date: 2025-08-08NANJING XINLIAN ELECTRONICS CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510631183.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-16
Publication Date
2025-08-08

AI Technical Summary

Technical Problem

Traditional third-party APP integration methods cannot accurately capture the long-range correlation and periodicity laws of subscription state access in smart energy units, resulting in a lack of accuracy in version retention strategies and insufficient pattern recognition accuracy, affecting the stable operation of the system.

Method used

By monitoring the changes in the subscription status of the MQTT client, analyzing the change patterns of the subscription topics, generating the classification results of the topic change patterns and the topic prediction reliability score, optimizing the version retention strategy, and implementing differentiated coding, establishing a version storage resource allocation plan, and quickly recovering the container status.

Benefits of technology

Improves the accuracy of the version access probability prediction, reduces the version cache miss rate, and improves the response speed and pattern recognition accuracy of smart energy units under high load conditions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120448037A_ABST
    Figure CN120448037A_ABST
Patent Text Reader

Abstract

The invention discloses a third-party APP integration method for a smart energy unit, and the method comprises the steps: monitoring the subscription state change of an MQTT client of a third-party APP container, analyzing the change mode of a subscription theme, obtaining a theme change mode classification result and a theme prediction reliability score, calculating the version access probability distribution according to the classification result and the theme prediction reliability score, and optimizing a version retention strategy, generating a version storage resource allocation scheme; differential coding is carried out on the subscription state, the subscription state is written into a shared memory area, a version storage address mapping table is established, and the container state is rapidly recovered. According to the method, the problems of inaccurate version access probability prediction and low subscription mode recognition precision in an energy scene in a traditional scheme are effectively solved, the container state recovery time is reduced to be within 500 milliseconds from 5-10 seconds, and the version storage space utilization rate is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of smart energy management and Internet of Things applications, and in particular to a third-party APP integration method for a smart energy unit. Background Art

[0002] With the rapid development of smart energy systems, smart energy units, as core control devices at the end of the power system, need to integrate a large number of third-party applications to achieve functional expansion and data sharing. These third-party apps play a key role in energy monitoring, equipment control, data analysis, and other fields. Their integration efficiency and reliability directly affect the operational stability of the entire smart energy system. As the proportion of new energy access continues to increase, the data processing pressure and real-time requirements faced by smart energy units have increased dramatically. Traditional app integration methods can no longer meet the strict requirements of high reliability and low latency in the energy sector. Therefore, it is of great practical significance to study efficient, secure, and adaptive third-party app integration technologies suitable for smart energy units.

[0003] Current third-party app integration solutions are primarily based on standardized API interfaces and containerized deployment technologies. At the communication level, most solutions adopt the MQTT protocol as a unified interface standard, enabling data exchange between different applications through an interface adaptation layer. At the deployment level, Docker container technology is widely used to isolate third-party apps and manage their lifecycles through an application manager. Existing research primarily utilizes traditional solutions such as CRIU (Checkpoint / Restore in Userspace) for container state recovery, state file persistence mechanisms for MQTT subscription relationship management, and sliding windows or simple incremental backup strategies for version management. These solutions perform well in standardized environments and provide a reliable technical foundation for basic application integration.

[0004] However, existing technologies expose two key problems in the special application scenarios of smart energy units. First, when predicting the probability of version access, the first-order state transition assumption of the traditional Markov chain model cannot accurately capture the long-range correlation and periodicity of subscription state access in energy units, resulting in a lack of precision in the version retention strategy and difficulty in achieving optimal resource allocation under limited memory conditions. Second, the change pattern of the MQTT subscription relationship in the energy unit is highly domain-specific. When identifying topic change patterns, traditional general clustering algorithms such as K-means cannot effectively handle the complex characteristics of the coexistence of periodicity, burstiness, and stability patterns unique to energy data, resulting in insufficient pattern recognition accuracy, which in turn affects the accuracy and efficiency of state recovery. These technical bottlenecks seriously restrict the stable operation of smart energy units in high-load, multi-application environments. Summary of the Invention

[0005] The purpose of the invention is to provide a third-party APP integration method for a smart energy unit, in order to solve at least one technical problem existing in the prior art.

[0006] Technical solution: A third-party APP integration method for smart energy units, including:

[0007] Monitor the subscription status changes of the MQTT client of the third-party APP container and generate subscription status change metadata;

[0008] Based on the subscription status change metadata, the change pattern of the subscription topic is analyzed to obtain the topic change pattern classification results and topic prediction reliability scores. Based on this, the version access probability distribution is calculated, the version retention strategy is optimized, and the version storage resource allocation plan is generated.

[0009] According to the version storage resource allocation plan, the subscription status is differentially encoded and written into the shared memory area. A version storage address mapping table is established to quickly restore the container status.

[0010] According to one aspect of the present application, obtaining a topic change pattern classification result and a topic prediction reliability score includes:

[0011] Read the subscription status change metadata, analyze the topic change cycle, calculate the change entropy and variance, obtain the topic change frequency domain characteristics and topic change statistical characteristics, map them to the energy feature space, calculate the energy feature distance function, and generate a time series weighted distance matrix;

[0012] Based on the time-series weighted distance matrix, cluster centers are identified, topic assignment is implemented, the topic cluster assignment results are obtained and their statistical characteristics are calculated, the clusters are mapped to predefined change pattern types, and the topic change pattern classification results and topic prediction reliability scores are obtained.

[0013] According to one aspect of the present application, obtaining theme change frequency domain features and theme change statistical features includes:

[0014] Read the metadata of subscription status changes, group them by topic ID to construct a time series change sequence, and use linear interpolation to form standardized time series data. Perform frequency domain transformation on it to identify the dominant frequency components and energy distribution, and obtain the frequency domain characteristics of topic changes.

[0015] Calculate the mean, standard deviation, autocorrelation function and runs test results of the standardized time series data, evaluate the randomness index of the sequence, and obtain the statistical characteristics of the theme change;

[0016] Calculate the sample entropy and approximate entropy of the standardized time series data, evaluate the sequence complexity, and obtain the complexity characteristics; combine the frequency domain and statistical characteristics of the topic changes with the complexity characteristics to form the full feature vector of the topic.

[0017] According to one aspect of the present application, generating a temporal weighted distance matrix includes:

[0018] Read the full feature vector of the topic, construct a three-dimensional energy feature space with periodic intensity dimension, change severity dimension and stability index dimension, and map the full feature vector of the topic into it to obtain the energy feature representation;

[0019] Based on the energy feature representation, a comprehensive distance function is constructed, which includes the weighted sum of cycle distance, mutation distance and stability distance;

[0020] The time decay factor is used to assign weights to recent change data, and the weighted distance between topics is calculated using a comprehensive distance function to generate a time series weighted distance matrix.

[0021] According to one aspect of the present application, after obtaining the frequency domain features and statistical features of topic changes, it also includes performing feature dimension adaptive dimensionality reduction processing, including:

[0022] Read the frequency domain and statistical characteristics of topic changes, use PCA to identify the main change directions, and obtain the principal component matrix of topic features;

[0023] Based on the topic feature principal component matrix, the contribution rate of each principal component is calculated, and the key principal components whose contribution rates exceed the threshold are screened out to obtain a key principal component index list; accordingly, additional weights are given to the characteristic dimensions of high-importance topics, and the weights of the corresponding principal components in the topic feature principal component matrix are adjusted to obtain a weighted principal component feature matrix.

[0024] According to one aspect of the present application, obtaining a topic cluster assignment result includes:

[0025] Based on the temporal weighted distance matrix, the local density ρ of each topic and the distance Δ to the higher density point are calculated to obtain the density-distance feature map;

[0026] In the density-distance feature map, points with high ρ values and high Δ values are identified as cluster centers, and a set of automatically identified cluster centers is obtained;

[0027] Through density gradient-based topic assignment, each topic is assigned to the nearest cluster center, and the assignment confidence is recorded to obtain the topic cluster assignment result.

[0028] According to one aspect of the present application, generating a version storage resource allocation plan includes:

[0029] Based on the classification results of topic change patterns, an exponential decay weight function is calculated through a hierarchical state space model to construct an enhanced transition probability model that includes access history context.

[0030] Based on the enhanced transition probability model, the periodic pattern parameters identified by the topic prediction reliability score are integrated to form a hybrid model of the periodic access pattern function and the Markov chain transition probability. An adaptive update mechanism is established to generate the version access probability distribution.

[0031] Based on the version access probability distribution, combined with the energy unit hardware constraints and business continuity requirements, the modeled version retention strategy is calculated to obtain the version storage resource allocation plan.

[0032] According to one aspect of the present application, generating a version access probability distribution includes:

[0033] Based on the topic prediction reliability score, topics with periodic patterns are identified, and periodic parameters are analyzed to obtain a periodic pattern parameter set; based on this, a sine function model is calculated to obtain a periodic access pattern function;

[0034] The periodic access pattern function is mixed with the results of the enhanced transition probability model to obtain the periodic enhanced transition probability;

[0035] Based on the real-time collected version access logs, the transition probability is periodically enhanced, the transition matrix regularization is implemented, and the state access probability of the future predetermined steps is calculated to obtain the version access probability distribution.

[0036] According to one aspect of the present application, obtaining a version storage resource allocation scheme includes:

[0037] Based on the version access probability distribution, we construct a version storage benefit function and a storage cost function, and accordingly model the version storage optimization problem as a 0-1 knapsack problem.

[0038] Solve the 0-1 knapsack problem, construct a two-dimensional DP table, determine the optimal version selection set for each pattern type based on the DP backtracking path, obtain the pattern version retention strategy, and determine whether there is a resource allocation conflict;

[0039] If it exists, a linear programming model is constructed, and the simplex method is used to solve and verify the feasibility to obtain the version storage resource allocation plan.

[0040] According to one aspect of the present application, obtaining a periodically enhanced transition probability includes:

[0041] Based on the period length T, phase offset φ, amplitude A and basic offset parameter B, a periodic access pattern function f_period(t) = A×sin(2πt / T + φ) + B is established; where t is the time variable;

[0042] Construct a hybrid calculation formula P_hybrid(i, j, t) = α×P_markov(i, j) + β×f_period(t), where α and β are fusion weights, adjusted according to the reliability score of the pattern type; P_markov(i, j) is the Markov transition probability; P_hybrid is the periodic enhancement transition probability;

[0043] Based on the hybrid calculation formula, the hybrid probability of different version state transitions in the time dimension is calculated to obtain the periodic enhanced transition probability.

[0044] Beneficial effects: The present invention overcomes the limitation of traditional first-order Markov chains that can only capture the relationship between adjacent states, improves the accuracy of version access probability prediction, effectively reduces the version cache miss rate, and improves the response speed of smart energy units under high load conditions; it can accurately capture the periodicity, burstiness and stability patterns unique to energy field data, and improves pattern recognition accuracy. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] Figure 1 A flowchart of the steps of a third-party APP integration method for a smart energy unit provided in an embodiment of the present application.

[0046] Figure 2 A flowchart of the steps for obtaining the topic change pattern classification results and topic prediction reliability scores provided in an embodiment of the present application.

[0047] Figure 3 A flowchart of the steps for obtaining frequency domain features and statistical features of topic changes provided in an embodiment of the present application.

[0048] Figure 4 A flowchart of the steps for generating a time-series weighted distance matrix provided in an embodiment of the present application. DETAILED DESCRIPTION

[0049] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.

[0050] It should be noted that to clearly illustrate the steps of this application, serial numbers are assigned to each step in the specification. These serial numbers are for illustrative purposes only and do not limit the order in which the steps must be executed. In actual operation, depending on the technical requirements of the specific implementation scenario, the steps may be executed in a different order than shown in the specification, and in some cases, parallel processing between steps may be implemented.

[0051] like Figure 1 As shown, a third-party APP integration method for a smart energy unit includes the following steps:

[0052] S1. Monitor the subscription status changes of the MQTT client of the third-party app container and generate subscription status change metadata including the topic name, change type, and timestamp.

[0053] Specifically, a third-party app container refers to an application environment running an MQTT client, such as an embedded system, cloud service, or mobile application. MQTT (Message Queuing Telemetry Transport) is a lightweight protocol for IoT communications. Devices use it to subscribe to different topics to receive data. When an MQTT client subscribes to, unsubscribes from, or renews a subscription to a topic, the system detects these changes.

[0054] S2. Analyze the change pattern of subscription topics based on the subscription status change metadata to obtain the topic change pattern classification results and topic prediction reliability scores;

[0055] Specifically, we use subscription status change metadata to observe subscription patterns across different topics. For example, some topics may have stable subscriptions and long-term engagement (e.g., "weather updates"); some topics may have periodic subscriptions, with subscriptions occurring at specific times or events (e.g., "stock prices"); and some topics may experience sudden increases or decreases in subscriptions, influenced by user behavior or external circumstances (e.g., "breaking news").

[0056] S3. Based on the classification results of topic change patterns and the topic prediction reliability score, calculate the version access probability distribution, optimize the version retention strategy, and generate a version storage resource allocation plan;

[0057] Specifically, by analyzing the classification results of topic change patterns and the topic prediction reliability score, the access probability of different versions is predicted. For example: high access probability: certain versions may be frequently accessed (such as the latest version or popular data); low access probability: certain versions may be rarely accessed (such as old versions or low-priority data). This can help the system reasonably allocate storage resources and avoid unnecessary storage usage. Based on the access probability distribution, the version retention policy is adjusted. For example, long-term retention: versions with high access probability can be stored for a long time to ensure that they are available to users at any time; short-term retention: versions with low access probability can be set with automatic cleanup rules to reduce storage usage; dynamic adjustment: if the access frequency of a certain version suddenly increases, the retention policy can be adjusted to avoid data loss.

[0058] S4. According to the version storage resource allocation plan, the subscription status is differentially encoded and written into the shared memory area. A version storage address mapping table is established to quickly restore the container status.

[0059] Specifically, subscription status may contain different data types, such as active subscription, canceled subscription, or temporary subscription. Differentiated encoding allows for optimized storage based on different subscription statuses. For example, frequently accessed data can be encoded efficiently to reduce storage usage, while infrequently accessed data can be compressed to reduce storage costs.

[0060] According to one aspect of the present application, the step of generating subscription status change metadata includes:

[0061] S11. Capture MQTT client events within the container. Read the MQTT client event log of the third-party app within the container, intercept subscription change operations through a hook function, and obtain the original subscription event data. Parse the original subscription event data, extract key information such as the topic name, QoS level, and subscription identifier, and obtain structured subscription information.

[0062] S12. Time-series recording of subscription status changes. Obtain structured subscription information and add a high-precision timestamp (microsecond level) to each subscription change event to obtain a time-series subscription change record. Build a subscription status snapshot within the container, recording the complete set of all currently active subscriptions, to obtain an instantaneous subscription status snapshot.

[0063] S13. Generate state change metadata. Compare the instantaneous subscription state snapshots before and after to identify added, deleted, and modified subscription relationships, and obtain a subscription state difference set. Combine the time-series subscription change records and the subscription state difference set to generate subscription state change metadata containing information such as change type and change frequency.

[0064] like Figure 2 As shown, according to one aspect of the present application, the steps of obtaining the topic change pattern classification results and the topic prediction reliability score include:

[0065] S21. Read the subscription status change metadata, analyze the topic change cycle, calculate the change entropy and variance, and obtain the topic change frequency domain characteristics and topic change statistical characteristics;

[0066] S22, mapping the frequency domain features of topic changes and the statistical features of topic changes to the energy feature space, calculating the energy feature distance function, and generating a time series weighted distance matrix;

[0067] S23. Identify cluster centers based on the time-series weighted distance matrix, implement topic allocation, and obtain topic cluster allocation results; calculate the statistical characteristics of the topic cluster allocation results, map the clusters to predefined change pattern types, and obtain topic change pattern classification results and topic prediction reliability scores.

[0068] Specifically, the subscription status change metadata is read, and the fast Fourier transform is used to analyze the change cycle of each subscription topic to obtain the frequency domain characteristics of the topic change. The entropy and variance of the topic change are calculated to quantify the regularity and randomness of the change, and obtain the statistical characteristics of the topic change. Combining the frequency domain characteristics and statistical characteristics of the topic change, a clustering algorithm is used to classify the subscription topics into four categories: stable, periodic, bursty, and random, to obtain the topic change pattern classification results. The change prediction confidence of each topic is calculated, and the predictability of future changes is evaluated based on historical patterns to obtain the topic prediction reliability score. Based on the topic change pattern classification results, a mathematical description model is established for each pattern type, including a change function and a parameter set, to obtain a topic change feature model library. Each specific subscription topic is mapped to the corresponding feature model, and the topic-specific model parameters are recorded to obtain the mapping relationship between the topic and the model.

[0069] The mapping relationship between topics and models is specifically obtained by reading the classification results of topic change patterns and defining mathematical model frameworks based on four pattern types (stable, periodic, bursty, and random). This results in a basic model template for each pattern type. A parameter space is designed for each pattern type: stable: [baseline value, fluctuation amplitude, change trend]; periodic: [cycle length, amplitude, phase, baseline value]; bursty: [maximum burst intensity, trigger threshold, attenuation coefficient]; random: [distribution type, mean, variance], thus defining the modeled parameter space.

[0070] For stable topics, the sliding window least squares method is used to fit the linear trend, calculate the baseline value and the rate of change, and obtain the trend parameters of the stable topics; for periodic topics, Fourier transform is used to identify the dominant period, and sine fitting is used to estimate the amplitude and phase to obtain the periodic parameters of the periodic topics; for burst topics, the peak detection algorithm is used to identify sudden events, and the probability distribution of burst intensity is established to obtain the burst characteristic parameters of the burst topics; for random topics, the maximum likelihood estimation method is used to fit the Gaussian mixture model, determine the distribution parameter combination, and obtain the distribution parameters of the random topics.

[0071] Perform a goodness-of-fit assessment of the model. Calculate the residuals of each model's fit to the historical data, using the root mean square error (RMSE) and mean absolute error (MAE) to measure fit accuracy and obtain the model fit accuracy index. Use cross-validation to divide the historical data into training and test sets to verify the model's generalization ability and obtain a model generalization performance assessment. Calculate the model complexity index, using the AIC and BIC criteria to balance model accuracy and complexity, select the optimal number of parameters, and obtain a model complexity score.

[0072] Construct a hybrid model processing mechanism. Identify topics with multimodal characteristics and use a fuzzy clustering algorithm to calculate the topic's membership to each mode type, obtaining a multimodal attribution distribution. Construct a hybrid model structure: M_hybrid = Σ(wi × Mi), where wi is the mode weight and Mi is the single-mode model, resulting in a weighted hybrid model framework. Use the expectation-maximization (EM) algorithm to iteratively optimize the hybrid model parameters and weight distribution, obtaining the optimized hybrid model parameters.

[0073] Perform model parameter mapping and storage. Create a model parameter mapping table, indexing each topic ID with its corresponding model type and parameter set to obtain a topic-model mapping index. Construct a parameter compression storage format, using variable-length encoding to reduce storage space while maintaining fast access capabilities, to obtain a compressed parameter storage format. Create a topic change feature model library containing the model structure and parameters of all topics, while recording the model version and update time to obtain a mapping relationship between topics and models.

[0074] like Figure 3 As shown, according to one aspect of the present application, obtaining the frequency domain features of theme changes and the statistical features of theme changes includes:

[0075] Read the subscription status change metadata, group by topic ID to build a time series change sequence, and use linear interpolation to form standardized time series data;

[0076] Perform frequency domain transformation on the standardized time series data to identify the dominant frequency components and energy distribution, and obtain the frequency domain characteristics of theme changes;

[0077] Calculate the mean, standard deviation, autocorrelation function and runs test results of the standardized time series data, evaluate the randomness index of the sequence, and obtain the statistical characteristics of the theme change;

[0078] Calculate the sample entropy and approximate entropy of the standardized time series data, evaluate the sequence complexity, and obtain the complexity characteristics; combine the frequency domain and statistical characteristics of the topic changes with the complexity characteristics to form the full feature vector of the topic.

[0079] Specifically, the subscription status change metadata is read, grouped by topic ID, and the time series change sequence of each topic is constructed to obtain the topic-level time series change sequence set; missing values and abnormal points in the sequence are processed, and the missing intervals are filled using the forward filling method. The 3σ criterion is used to identify and smooth abnormal mutations to obtain the cleaned time series sequence; the time sampling interval is unified, and linear interpolation is used to convert irregular time series into fixed interval series to obtain standardized time series data.

[0080] Fast Fourier transform (FFT) was applied to the standardized time series data of each subject to calculate the spectral coefficients and obtain the frequency domain transformation results; the main frequency components in the spectrum were identified, the amplitude and phase of the peak frequency were calculated, and the dominant frequency component characteristics were obtained; the spectral energy distribution was calculated, and the power spectral density was used to analyze the distribution of the changing energy in each frequency band to obtain the spectral energy distribution characteristics.

[0081] Calculate the first-order statistics of time series data: mean, standard deviation, skewness, and kurtosis, quantify the central trend and distribution pattern of changes, and obtain basic statistical characteristics; calculate the second-order statistics of time series data: autocorrelation function and partial autocorrelation function, analyze the short-term and long-term correlation of the sequence, and obtain correlation characteristics; use the run test to calculate the randomness index of the sequence, evaluate the degree of regularity of the change pattern, and obtain randomness measurement characteristics.

[0082] The sample entropy algorithm is used to calculate the regularity measure of the time series, and the pattern matching method is used to detect the complexity of repeated patterns to obtain the sample entropy characteristics; the approximate entropy (ApEn) is calculated to measure the rate at which the sequence generates new patterns to obtain the approximate entropy characteristics; the Lempel-Ziv complexity algorithm is used to calculate the information complexity of the sequence, evaluate the pattern diversity, and obtain the sequence complexity characteristics.

[0083] All calculated features are combined into a high-dimensional feature vector: [frequency domain features, statistical features, entropy features, complexity features] to obtain the full feature vector of the topic; feature normalization is applied, and Z-score normalization is used to eliminate the influence of different dimensions to obtain a standardized feature vector; the feature vectors of all topics are merged to form two main feature sets: frequency domain features of topic changes and statistical features of topic changes.

[0084] like Figure 4As shown, according to one aspect of the present application, generating a time-series weighted distance matrix includes:

[0085] Read the full feature vector of the topic, construct a three-dimensional energy feature space with periodic intensity dimension, change severity dimension and stability index dimension, and map the full feature vector of the topic into it to obtain the energy feature representation;

[0086] Based on the energy feature representation, a comprehensive distance function is constructed, which includes the weighted sum of cycle distance, mutation distance and stability distance;

[0087] The time decay factor is used to assign weights to recent change data, and the weighted distance between topics is calculated using a comprehensive distance function to generate a time series weighted distance matrix.

[0088] Specifically, adaptive dimensionality reduction of feature dimensions is performed. The frequency domain features and statistical features of topic changes are read, and principal component analysis is used to identify the main change directions, resulting in a principal component matrix of topic features. The contribution rate of each principal component is calculated, and the cumulative contribution rate threshold is set at 85%. Key principal components are screened to obtain a key principal component index list. Based on the characteristics of the energy unit subscription topics, additional weights are assigned to the feature dimensions of high-importance topics, and the principal component weights are adjusted to obtain a weighted principal component feature matrix.

[0089] Construct a distance metric based on energy characteristics. Read the weighted principal component feature matrix and identify the thematic characteristics (such as periodicity, mutation, and stability) represented by each dimension to obtain the principal component dimension feature interpretation. Based on the business characteristics of the smart energy unit, define a three-dimensional energy feature space: the periodicity intensity dimension, the change severity dimension, and the stability index dimension. Map the dimensions of the weighted principal component feature matrix to these three spaces to obtain the energy feature space definition. Construct a comprehensive distance function: D(i, j) = α×d_period(i, j) + β×d_mutation(i, j) + γ×d_stability(i, j). D_period, d_mutation, and d_stability are calculated from the corresponding dimensions of the weighted principal component feature matrix, respectively. The weight parameters α, β, and γ are adjusted based on the actual application of the energy unit to obtain the energy characteristic distance function. A time decay factor is introduced to assign higher weight to recent changes in the weighted principal component feature matrix, enabling time-sensitive distance calculations and obtaining a time-weighted distance matrix.

[0090] Using a time-series weighted distance matrix and a density peak detection-based method, we calculate the local density ρ of each topic and the distance Δ to higher density points to obtain a density-distance feature map. In the density-distance feature map, we identify cluster center points with high ρ and high Δ values without presetting the number of clusters, and obtain an automatically identified set of cluster centers. We implement density gradient-based topic allocation to assign each topic to the nearest cluster center, while recording the allocation confidence to obtain the topic cluster allocation result.

[0091] Automatically map energy sector pattern labels. Read the thematic cluster assignment results and analyze the statistical characteristics of each cluster (average change period, change amplitude distribution, and stability index) to obtain a cluster feature summary. Based on the energy sector knowledge base, define a set of pattern recognition rules: strong periodicity with regular changes → periodic type; large and irregular changes → burst type; long-term low change rate → stable type; uncertain change pattern → random type. Applying these pattern recognition rules, map each cluster to four predefined pattern types to obtain the thematic change pattern classification results.

[0092] Perform classification boundary optimization and reliability assessment. Calculate the distance from each topic to its cluster center, identify topics in the boundary area, and obtain a set of boundary topics. For this set of boundary topics, use k-nearest neighbor validation to examine the pattern distribution of its k nearest neighbors, adjust the classification decision, and obtain an optimized topic classification. Calculate the classification confidence: confidence = 1 - (distance to the center of the current cluster) / (distance to the center of the nearest different cluster). Assign a reliability score to each topic to obtain a topic prediction reliability score.

[0093] Verify and provide feedback on the classification results. Based on the actual operating data of the energy unit, verify the accuracy of the classification results, record misclassification cases, and generate a classification verification report. Establish a classification error feedback mechanism to collect pattern deviations observed during actual operation, update the distance function weights, and obtain the distance function's dynamic adjustment parameters. Pass the topic change pattern classification results and topic prediction reliability scores to the next step as input for building the change feature model.

[0094] According to one aspect of the present application, generating a version storage resource allocation plan includes:

[0095] S31. Based on the classification results of topic change patterns, an exponential decay weight function is calculated through a hierarchical state space model to construct an enhanced transition probability model that includes access history context;

[0096] S32. Based on the enhanced transition probability model, the periodic pattern parameters identified by the topic prediction reliability score are integrated to form a hybrid model of the periodic access pattern function and the Markov chain transition probability, establish an adaptive update mechanism, and generate the version access probability distribution;

[0097] S33. Based on the version access probability distribution, combined with the energy unit hardware constraints and business continuity requirements, the modeled version retention strategy is calculated to obtain the version storage resource allocation plan.

[0098] Specifically, the topic change feature model library and topic prediction reliability score are read, and the Markov chain model is used to predict the access probability of each version in the future time window to obtain the version access probability distribution; combined with the business priority of the energy unit, importance weights are set for different topics to obtain the weighted version access probability. Based on the weighted version access probability, the dynamic programming algorithm is used to calculate the optimal version retention interval for each pattern type to obtain the patterned version retention strategy; the memory usage upper limit constraint is set, and the linear programming method is used to optimize the version storage allocation to obtain the version storage resource allocation plan. Establish version access hit rate monitoring, record the deviation between the actual access pattern and the predicted pattern, and obtain prediction accuracy feedback data; based on the prediction accuracy feedback data, the gradient descent algorithm is used to fine-tune the model parameters and update the topic change feature model library.

[0099] According to one aspect of the present application, generating a version access probability distribution includes:

[0100] Based on the topic prediction reliability score, topics with periodic patterns are identified, and periodic parameters are analyzed to obtain a periodic pattern parameter set; based on this, a sine function model is calculated to obtain a periodic access pattern function;

[0101] The periodic access pattern function is mixed with the results of the enhanced transition probability model to obtain the periodic enhanced transition probability;

[0102] Based on the real-time collected version access logs, the transition probability is periodically enhanced, the transition matrix regularization is implemented, and the state access probability of the future predetermined steps is calculated to obtain the version access probability distribution.

[0103] According to one aspect of the present application, obtaining a periodically enhanced transition probability includes:

[0104] Based on the period length T, phase offset φ, amplitude A and basic offset parameter B, a periodic access pattern function f_period(t) = A×sin(2πt / T + φ) + B is established; where t is the time variable;

[0105] Construct a hybrid calculation formula P_hybrid(i, j, t) = α×P_markov(i, j) + β×f_period(t), where α and β are fusion weights, adjusted according to the reliability score of the pattern type; P_markov(i, j) is the Markov transition probability; P_hybrid is the periodic enhancement transition probability;

[0106] Based on the hybrid calculation formula, the hybrid probability of different version state transitions in the time dimension is calculated to obtain the periodic enhanced transition probability.

[0107] Specifically, a hierarchical state space is constructed. The topic change feature model library is read, and version states are grouped by topic. Each topic maintains an independent version sequence, resulting in a topic-dimensional version state set. Based on the topic's pattern type (stable / periodic / burst / random), a dedicated state representation is designed for each pattern type, reducing the state space dimension and obtaining a patterned state representation scheme. A hierarchical state space is constructed: a user access layer (high abstraction layer) and a version detail layer (low implementation layer), achieving effective compression of the state space and resulting in a hierarchical state space model.

[0108] Build a long-range dependency memory mechanism. Read the hierarchical state space model and design a memory mechanism based on its hierarchical structure, maintaining simplified states at a high abstraction level and retaining detailed information at a low implementation level; build an exponential decay weight function: w(t) = e -λ*t , where e is the base of the natural logarithm and λ* is the attenuation coefficient; weights that decay according to time distance are assigned to historical states to obtain a time-attenuated weight function; an enhanced transition matrix P(i, j|context) is constructed, where context contains the complete access history within the window, to obtain a context-enhanced transition probability model.

[0109] Construct a periodic pattern fusion mechanism. Read topic prediction reliability scores, identify topics with periodic patterns, analyze their periodic parameters (period length, phase, and amplitude), and obtain a set of periodic pattern parameters. Construct a periodic function: f_period(t) = A×sin(2πt / T + φ) + B, where A is the amplitude, T is the period, φ is the phase offset, and B is the base offset. This yields a periodic access pattern function. Combine the periodic pattern with a Markov chain: P_hybrid(i, j, t) = α×P_markov(i, j) + β×f_period(t), where α and β are adjusted based on the pattern reliability, to obtain a periodically enhanced transition probability.

[0110] Perform an adaptive transition matrix update. Establish an online learning mechanism to collect version access logs in real time. Calculate the transition frequency within the most recent time window to obtain real-time transition statistics. Use the exponential moving average method to update the transition probability: P_new(i, j) = (1-λ)×P_old(i, j) + λ×P_observed(i, j), where λ is the learning rate, P_old(i, j) is the historical transition probability, i.e., the probability of state i transitioning to state j within the past time window, and P_observed is the currently observed transition probability. Obtain an adaptive transition probability matrix. Implement transition matrix regularization to ensure that the sum of each row probability is 1 and address zero probability issues, resulting in a standardized adaptive transition matrix.

[0111] Estimate the access probability of sparse versions. Read the hierarchical state space model and leverage its hierarchical structure to determine pattern types at a high level and address the sparsity of specific versions at a low level. Bayesian estimation is used for sparse versions, using the Dirichlet prior distribution to estimate transition probabilities: P_sparse(i, j) = (n_ij + α) / (n_i + α×k), where n_ij is the number of observations of transitions from state i to state j, n_i is the total number of occurrences of state i, α is the smoothing parameter of the Dirichlet prior distribution, and k is the number of possible states. This yields a Bayesian smoothed probability estimate. A neighboring version leverage mechanism is introduced, where sparse versions refer to the access patterns of neighboring versions and perform probability interpolation to obtain the neighboring version reference probability.

[0112] Perform access probability prediction calculation. Based on the standardized adaptive transfer matrix, use the n-step transfer probability formula: P n = P 1 × P n-1 , where P n-1 is the state transition probability at n-1 steps; predict the state access probability in the next n steps and obtain the n-step transition probability prediction result; combine the periodic enhanced transition probability with the n-step prediction to calculate the comprehensive access probability: P_final(v, t) = Σ[P n ×f_period(t+n)], and obtain the time series access probability prediction. Considering the business characteristics of the energy unit, a minimum access probability lower limit is set for the key energy data version to prevent important versions from being overly underestimated, and the constraint-adjusted access probability is obtained.

[0113] Perform probability distribution validation and calibration. Calculate the entropy and variance of the predicted probability distribution to verify the rationality of the distribution, identify overly concentrated or overly dispersed anomalies, and obtain statistical characteristics of the probability distribution. Use historical access data for forward validation, calculate the prediction accuracy and mean squared error, evaluate model performance, and obtain prediction performance evaluation indicators. Based on the validation results, adjust model parameters (learning rate λ, periodic fusion weights α, β, etc.), implement parameter optimization, obtain version access probability distribution, and update model calibration parameter records.

[0114] According to one aspect of the present application, obtaining a version storage resource allocation scheme includes:

[0115] Based on the version access probability distribution, we construct a version storage benefit function and a storage cost function. Based on these two functions, we model the version storage optimization problem as a 0-1 knapsack problem.

[0116] Solve the 0-1 knapsack problem, construct a two-dimensional DP table, determine the optimal version selection set for each pattern type based on the DP backtracking path, obtain the pattern version retention strategy, and determine whether there is a resource allocation conflict;

[0117] If it exists, a linear programming model is constructed, and the simplex method is used to solve and verify the feasibility to obtain the version storage resource allocation plan.

[0118] Specifically, the hardware specifications of the smart energy unit are read to obtain the total available memory and reserved buffer size to obtain the system memory capacity limit; the minimum retention requirements for various versions of data are set: the minimum number of retained versions of key energy data, ordinary versions, and incremental versions, to obtain the version retention lower limit constraint; based on business continuity requirements, the version recovery time objective (RTO) and recovery point objective (RPO) are defined, converted into storage policy constraints, and business-level storage constraints are obtained.

[0119] Construct a storage benefit function. Construct a version access benefit function: Benefit(v) = P_access(v) × Priority(v) × Freshness(v), which incorporates the access probability P_access(v), business priority Priority(v), and data freshness(v) to obtain the version storage benefit model. Construct an incremental version benefit function: Benefit_delta(v) = Σ[Benefit(dependent_version)] × Compression_ratio, which considers the cumulative benefit and compression ratio of dependent versions to obtain the incremental version benefit model. Construct a storage cost function: Cost(v) = Size(v) × Access_frequency(v), which balances storage space usage and access overhead to obtain the version storage cost model. Dependent_version is the base version on which the incremental version depends, Compression_ratio is the compression ratio, Size(v) is the storage size of the version data, and Access_frequency(v) is the access frequency.

[0120] Perform dynamic programming optimization to solve the problem. Model the storage optimization problem as a 0-1 knapsack problem: max Σ[Benefit(v) × x_v], with the constraint Σ[Size(v) × x_v] ≤ Capacity, thus obtaining the mathematical model of the knapsack problem. Use a dynamic programming algorithm to solve the problem, constructing a two-dimensional DP table: dp[i][w] represents the maximum benefit of the first i versions under capacity w, thus obtaining the intermediate state table of the DP solution. Based on the DP backtracking path, find the optimal version selection set, determine the optimal retention interval for each pattern type, and obtain a patterned version retention policy. x_v represents whether version v is selected. It is a variable that is either 0 or 1: if x_v = 1, the version is selected for storage; if x_v = 0, the version is not selected. Capacity is the system's storage capacity limit.

[0121] Generate a storage allocation plan. Based on the modeled version retention policy, calculate the storage space quota required for different model types to obtain a modeled storage space allocation. Based on the hierarchical relationship of the hierarchical state space model, design a tiered storage architecture, where high-level states occupy less space and low-level detailed information is stored in compressed form. Establish a dynamic storage resource adjustment mechanism to reallocate resources based on actual usage, and obtain dynamic storage adjustment rules.

[0122] Perform linear programming constraint optimization. When the dynamic programming results contain resource allocation conflicts, construct a linear programming model for secondary optimization to obtain a set of linear programming constraint equations. Use the simplex method to solve the linear programming problem, maximizing overall benefits while satisfying all constraints to obtain the optimal linear programming solution. Verify the feasibility of the optimization results, check whether all business and technical constraints are met, and obtain a version storage resource allocation plan.

[0123] Perform storage policy output and verification. All optimization results are compiled and compiled to generate a complete storage policy document, including the retention policy, memory allocation plan, and dynamic adjustment rules for each mode, resulting in a complete storage policy solution. Simulate and verify the policy using historical access patterns, calculate the expected hit rate and storage utilization, and obtain the policy simulation verification results. Output the version of the storage resource allocation plan and record the optimization process parameters for subsequent adjustments.

[0124] According to one aspect of the present application, establishing a version storage address mapping table includes:

[0125] S41. Based on the version storage resource allocation scheme, a long-interval snapshot plus incremental encoding method is used for stable topics, and a dense snapshot method is used for bursty topics to complete differential version encoding and obtain encoded version status data;

[0126] S42. Record the characteristic fingerprint of the version status data, establish a version fingerprint index, calculate the hash value of each version status, compare it with the version fingerprint index, identify versions with the same content, and obtain a duplicate version mapping table;

[0127] S43. Through the reference counting mechanism, the duplicate version is pointed to a single storage location, the duplicated storage space is released according to the duplicate version mapping table, a version storage area is allocated in the shared memory, a mapping relationship between the version and the memory address is established, and a version storage address mapping table is obtained.

[0128] Specifically, differential encoding is implemented. The patterned version retention strategy is read, and long-interval snapshot + incremental encoding is adopted for stable topics, and dense snapshots are adopted for bursty topics to obtain the encoded version status data; a Bloom filter is used to record the characteristic fingerprint of the encoded version for fast duplication detection to obtain a version fingerprint index. The SHA-256 hash value is calculated for the encoded version status data, and compared with the version fingerprint index to identify states with the same content but different versions, and obtain a duplicate version mapping table; a reference counting mechanism is implemented to point duplicate versions to a single storage location, freeing up duplicated storage space, and obtaining a deduplicated version storage structure. According to the version storage resource allocation scheme, a version storage area is allocated in the shared memory, and memory alignment optimization is implemented to obtain an allocated memory mapping address space; the deduplicated version storage structure is written to the corresponding memory area, and a mapping relationship between the version and the memory address is established to obtain a version storage address mapping table.

[0129] According to another aspect of the present application, a third-party APP integration method for a smart energy unit is provided, and the specific technical solution is as follows:

[0130] 1. Design a unified API interface protocol: Develop a standard interface protocol based on MQTT communication, including request and response formats for control, communication, and events. All apps (including third-party apps) must comply with this interface protocol.

[0131] 2. Data format conversion: Regardless of the data format, protocol, or method used by the third-party app to communicate with the outside world, it will be converted into JSON format and interact with other apps through the internal MQTT Broker.

[0132] 3. Use Docker containers: Run third-party apps in containers, open limited communication ports, specify data storage paths, protect the data security of other apps, and prevent the instability of third-party apps from affecting the operation of other apps.

[0133] 4. Monitoring mechanism: Develop an application manager to manage all third-party apps, monitor the running status of third-party apps, and recover when an exception occurs.

[0134] Specifically, all apps (including third-party apps) in the smart energy unit are developed based on the Linux system. The system deploys an MQTT broker, enabling communication between all apps using the MQTT protocol. Third-party apps are enabled with MQTT communication capabilities by adding an interface layer. This interface layer is also developed and run as an app. Different third-party apps are adapted to a specific interface layer, and the interaction methods and content between the interface layer and the third-party app meet the requirements of the third-party app. Each third-party app and its interface layer are run in a Docker container to ensure system stability and security.

[0135] The interface layer includes three functional parts: Standard interface protocol: It adopts the standard API interface protocol uniformly formulated by the system, including three types of functions: control, communication, and events. The control interface is responsible for controlling the operation of third-party apps, including registration, heartbeat, start, stop, and update. The communication interface is responsible for data exchange with other apps. The event interface is responsible for reporting the operating status of third-party apps, or receiving event information from the system, such as power outages and resets. Data conversion: Different third-party apps have different formats for external communication. The interface layer needs to convert data of different formats and functions into a unified JSON format, and vice versa. Operation monitoring: Any third-party app may have exceptions during operation, such as abnormal exit. The interface layer needs to be able to detect whether it is running normally. The interface layer also needs to count the resources occupied by the third-party app during operation, such as CPU usage, memory usage, and storage usage. In the event of an exception, it needs to exit and rerun.

[0136] In order to manage all third-party apps, the system needs to add an application manager with the following functions: Standard interface protocol: Complies with the standard API interface protocol uniformly formulated by the system, including three types of functions: control, communication, and events. Application management: Based on the standard API interface protocol uniformly formulated by the system, the functions include: registration processing of third-party apps; checking the operating status of all third-party apps; notifying third-party apps of system event information, such as power outages and resets. Exception handling: When a third-party app or its container runs abnormally, such as abnormal exit, failure to start normally, or abnormal events reported by the third-party app, the application manager can restore it to normal operation.

[0137] In a specific embodiment of the present application, based on the actual operating environment of a smart energy unit, the unit manages five third-party app containers, including an electricity meter monitoring app, an energy storage control app, a photovoltaic monitoring app, a demand response app, and an energy consumption analysis app, monitoring a total of 50 MQTT subscription topics. The third-party app integration method for the smart energy unit includes:

[0138] Step 1: Third-party app container status monitoring and data collection.

[0139] Taking the electricity meter monitoring app as an example, the system captures its MQTT client events: receiving the original subscription event: {"topic": " / meter / data / real_time", "qos": 1, "operation": "subscribe", "timestamp": 1699123456789}; extracting structured subscription information: topic name = " / meter / data / real_time", QoS level = 1, subscription identifier = "sub_001"; generating a time series subscription change record: ["sub_001", " / meter / data / real_time", "subscribe", 1699123456789]; constructing an instantaneous subscription state snapshot: {"active_topics": [" / meter / data / real_time", " / meter / data / hourly"], "timestamp": 1699123456789}; comparing the snapshots before and after to generate a subscription state difference set: {"added": [" / meter / data / real_time"], "removed": [], "modified": []}; Subscription status change metadata is generated: {"topic": " / meter / data / real_time", "change_type": "add", "frequency": "high", "timestamp": 1699123456789}.

[0140] Step 2: Analyze and classify state change patterns.

[0141] Take the " / meter / data / real_time" topic as an example:

[0142] 2.1. Temporal feature extraction.

[0143] Read 100 change records within 24 hours to form a time series: [t1=0, t2=300, t3=600, ..., t100=86400]; perform a fast Fourier transform to identify the dominant frequency: f_main = 1 / 300 second -1, amplitude A = 2.3; calculate statistical characteristics: mean μ = 300 seconds, standard deviation σ = 45 seconds, skewness γ = 0.2, kurtosis κ = 3.1; calculate autocorrelation function: r(1) = 0.85, r(2) = 0.72, r(3) = 0.58; calculate sample entropy: SampEn = 0.45, approximate entropy: ApEn = 0.52; form feature vector: [2.3, 300, 45, 0.85, 0.45, 0.52].

[0144] 2.2. Energy feature distance measurement and clustering.

[0145] Energy characteristic distance function D(i, j) = α×d_period(i, j) + β×d_mutation(i, j) + γ×d_stability(i, j); where d_period(i, j) = |T(i) - T(j)| / max(T(i), T(j)); d_period is the distance in the dimension of periodic intensity; d_mutation(i, j) = |A(i) - A(j)| / max(A(i), A(j)); d_mutation is the distance in the dimension of change severity; d_stability(i, j) = |σ(i) - σ(j)| / max(σ(i), σ(j)); d_stability is the distance in the dimension of stability index; α=0.4, β=0.3, γ=0.3 are weight coefficients; i and j are topic indexes; T(i) is the period length of topic i; A(i) is the amplitude of change of topic i; σ(i) is the standard deviation of topic i.

[0146] Calculation for topic i=" / meter / data / real_time" and topic j=" / meter / data / hourly": T(i) = 300 seconds, T(j) = 3600 seconds; A(i) = 2.3, A(j) = 0.5; σ(i) = 45, σ(j) = 120; d_period(i, j) = |300-3600| / max(300, 3600) = 3300 / 3600 = 0.92; d_mutation(i, j) = |2.3-0.5| / max(2.3, 0.5) = 1.8 / 2.3 = 0.78; d_stable(i, j) = |45-120| / max(45, 120) = 75 / 120 = 0.63; D(i, j) = 0.4×0.92 + 0.3×0.78 + 0.3×0.63 = 0.368 + 0.234 + 0.189 = 0.791.

[0147] Based on the calculated distance matrix, perform density peak detection: Calculate the local density of topic i: ρ(i) = Σ_j[exp(-D(i, j) 2 / d_c 2 )]; where d_c=0.5 is the cutoff distance; for the " / meter / data / real_time" topic: ρ(i)= exp(-0.791 2 / 0.5 2 ) + exp(-0.623 2 / 0.5 2 ) + ... = 5.8; Calculate the distance to the point with higher density: Δ(i) = min_j[D(i, j)], where ρ(j) > ρ(i). For the " / meter / data / real_time" topic: Δ(i) = 0.412; Identify high-density, high-distance points in the ρ-Δ plot as cluster centers; Detect four cluster centers and automatically identify four pattern types.

[0148] Based on cluster statistical characteristics, pattern label mapping is performed: Cluster 1: average period = 300 seconds, standard deviation = 40, variation = 2.0 → periodic type; Cluster 2: average period = 3600 seconds, standard deviation = 30, variation = 0.3 → stable type; Cluster 3: average period = variable, standard deviation = 150, variation = 5.0 → burst type; Cluster 4: average period = variable, standard deviation = 80, variation = 1.5 → random type.

[0149] Step 3: Generate a predictive version management strategy.

[0150] 3.1. Calculate the version access probability. Based on the hierarchical state space model, an improved Markov chain is constructed through the long-range dependency memory mechanism: an exponential decay weight function is constructed: w(t) = e -λt ; where λ=0.1 is the attenuation coefficient, t is the time distance; for t=1: w(1) = e -0.1×1 = 0.905; for t=5: w(5) = e -0.1×5 = 0.607; construct context-enhanced transition probability: P(i, j|context) = Σ_k[w(t_k)×P(i, j, t_k)], where P(i, j, t_k) is the probability of state i transitioning to state j at time t_k, w(t_k) is the time decay weight, and k is the historical time point index within the time window.

[0151] Perform periodic pattern fusion. The periodic access pattern function f_period(t) = A × sin(2πt / T + φ) + B, where A = 1.5 is the amplitude; T = 300 seconds is the period length; φ = 0.5 is the phase offset; B = 2.0 is the base offset; and t is the time variable. The hybrid calculation formula is: P_hybrid(i, j, t) = α × P_markov(i, j) + β × f_period(t); where α = 0.7 and β = 0.3 are the fusion weights; P_markov(i, j) is the Markov transition probability; and P_hybrid is the periodic enhancement transition probability.

[0152] Actual calculation example: For time t = 150 seconds: f_period(150) = 1.5×sin(2π×150 / 300 +0.5) + 2.0 = 1.5×sin(π + 0.5) + 2.0 = 1.5×(-0.479) + 2.0 = 1.281; P_markov(i, j) = 0.35 (basic transition probability); P_hybrid(i, j, 150) = 0.7×0.35 + 0.3×1.281 = 0.245+ 0.384 = 0.629.

[0153] 3.2. Perform storage strategy optimization calculations. Construct a 0-1 knapsack problem: Version storage benefit function: Benefit(v) = P_access(v) × Priority(v) × Freshness(v); Version storage cost function: Cost(v) = Size(v) × Access_frequency(v). Actual calculation example: Version v1: P_access = 0.85, Priority = 3, Freshness = 0.95, Size = 100KB, Access_frequency = 0.5; Benefit(v1) = 0.85 × 3 × 0.95 = 2.423; Cost(v1) = 100 × 0.5 = 50; Benefit-to-cost ratio: 2.423 / 50 = 0.049.

[0154] Perform dynamic programming to solve the problem: construct a two-dimensional DP table: dp[i][w] represents the maximum benefit of the first i versions under capacity w; the state transition equation is: dp[i][w] = max(dp[i-1][w], dp[i-1][w-Size(i)] + Benefit(i)); under the memory capacity limit W = 1024KB, the optimal solution includes the version set: {v1, v5, v8, v12}.

[0155] Step 4: Versioned state encoding and storage.

[0156] 4.1. Differentiated encoding strategies. Stable topics: snapshot interval = 3600 seconds, incremental encoding compression ratio = 5:1; Burst topics: snapshot interval = 300 seconds, snapshot compression ratio = 2:1; Encoded data size: Stable topics = 20KB / version, Burst topics = 45KB / version.

[0157] 4.2. Content Duplicate Detection: SHA-256 is used to calculate the version hash value; Bloom filter detection efficiency: false positive rate <0.01%; duplicate version detection rate reaches 98.5%; storage space savings exceed 40%.

[0158] In actual operation, this embodiment reduces the container state recovery time from 5-8 seconds in traditional solutions to 450 milliseconds; the version storage space utilization rate is increased by 42%; the version access hit rate reaches 95.3%; and the system memory usage is reduced by 35%.

[0159] According to one aspect of the present application, the process further includes S5, container fault detection and recovery triggering, monitoring the health status of the container, detecting abnormal container exit events, and triggering a status recovery process.

[0160] S6. Optimal version selection algorithm based on failure time point.

[0161] S61. Version availability assessment at the time of the failure. Read the failure timestamp and search the version storage address mapping table for the set of available versions before and after the failure to obtain a set of candidate versions. Calculate the integrity score of each candidate version as f(number of topics covered by the version, version data integrity flag) to obtain a version integrity score table. Calculate the reliability score of each candidate version as g(system load at the time of version generation, version storage verification results) to obtain a version reliability score table. Here, f represents the calculation function for the version integrity score, and g represents the calculation function for the version reliability score.

[0162] S62. Multi-dimensional version evaluation integration. Combining the version integrity score table and the version reliability score table, a weighted summation algorithm is used to calculate the version's comprehensive score: α × integrity + β × reliability + γ × time distance factor. This yields a ranking of the versions based on the comprehensive score. Version dependency analysis is then applied to check the availability of the incremental versions on which the selected version depends. Versions with broken dependency chains are eliminated to obtain the final ranking of available versions.

[0163] S63. Determine the optimal version and backup plan. Select the version with the highest score in the final ranking of available versions as the primary recovery version. Record the version ID and starting address to obtain the primary recovery version information. Select the versions ranked 2-3 as backup recovery plans. Establish a version switching plan to obtain the version recovery plan.

[0164] S64. Calculate the patterned incremental path. Read the master recovery version information, identify the time interval between the target recovery time point and the master version, and obtain the version-target state time difference. Calculate the corresponding incremental path weight based on the change pattern type (stable / cyclical / burst / random) for each topic to obtain a patterned incremental weight matrix. Use the Dijkstra algorithm to calculate the shortest incremental path from the master version to the target state in the version dependency graph to obtain the optimal incremental application sequence.

[0165] S65. Differentiated incremental application strategy. For stable topics, a strategy of directly jumping to the most recent stable state is adopted, skipping intermediate changes, and obtaining a rapid recovery path for stable topics. For bursty topics, incremental application is carried out step by step, strictly following the incremental sequence to ensure that no sudden changes are missed, and obtaining a complete recovery path for bursty topics. For periodic topics, missing states are predicted based on the periodic function, and incremental gaps are filled to obtain a predicted recovery path for periodic topics.

[0166] S66, Incremental Application and State Verification. Apply all incremental changes in batches according to the optimal incremental application sequence, performing atomic operations to obtain the reconstructed subscription state. Perform state integrity checks, calculate the hash value of the reconstructed state and compare it with the expected value, detect missing or erroneous subscription items, and obtain the state reconstruction verification result.

[0167] S7. Batch subscription optimization algorithm.

[0168] S71. Prioritize subscription topics. Read the reconstructed subscription state and, combined with the energy unit's business priority settings, calculate the business importance score for each topic to obtain a topic business importance score. Based on the topic's historical access frequency and change characteristics, calculate the recovery urgency for each topic to obtain a topic recovery urgency score. Combine the business importance and recovery urgency scores and use a weighted sorting algorithm to generate a subscription recovery priority sequence to obtain a topic subscription priority ranking.

[0169] S72. Batch parallel subscription strategy. Based on the subscription priority ranking, the subscription topics are divided into three batches: high priority, medium priority, and low priority, to obtain a batch subscription plan. Within each batch, the correlation between topics is analyzed, and related topics are grouped for parallel subscription to reduce the number of network round trips, resulting in intra-batch parallel subscription groups. A subscription failure retry mechanism is established, with a timeout and retry strategy set for each batch, to obtain a batch subscription fault-tolerant solution.

[0170] S73. Real-time synchronization of subscription status. A subscription progress monitor is established to track the subscription status and confirmation of each topic in real time, providing real-time status of subscription progress. A pipeline mechanism is used to pre-process the subscription data for subsequent batches while the previous batch of subscriptions is being executed, generating pipeline processing results. Subscription completion rate threshold monitoring is implemented. When the completion rate of a batch reaches the set threshold, the next batch of subscriptions is immediately initiated, generating a dynamic batch switching signal.

[0171] In a specific example, a power failure occurred during the operation of a smart energy unit, causing the meter monitoring app container to crash. The failure occurred at the timestamp 1699156789012 (with microsecond accuracy). The system needed to quickly restore the container's subscription status, which included 15 MQTT subscription topics, within 500 milliseconds.

[0172] Version availability assessment at the time of the failure. Read the failure timestamp 1699156789012 and search the version storage address mapping table: candidate version set: [v_87, v_88, v_89, v_90, v_91]; v_87 timestamp: 1699156785000, time difference: 4.012 seconds; v_88 timestamp: 1699156786500, time difference: 2.512 seconds; v_89 timestamp: 1699156787800, time difference: 1.212 seconds; v_90 timestamp: 1699156788900, time difference: 0.112 seconds; v_91 timestamp: 1699156790100, time difference: -1.088 seconds (post-failure version). Calculate the version completeness score: Completeness score function: Integrity_score(v) = (number of topics covered / total number of topics) × data completeness flag; v_87: (15 / 15) × 1.0 = 1.0 (all topics are complete); v_88: (14 / 15) × 1.0 = 0.933 (1 topic is missing); v_89: (15 / 15) × 0.95 = 0.95 (with data verification warnings); v_90: (15 / 15) × 1.0 = 1.0 (complete). Calculate the version reliability score: Reliability score function: Reliability_score(v) = 1 - (system load × 0.1) - (check failure flag × 0.5); v_87: 1 - (0.45 × 0.1) - (0 × 0.5) = 0.955; v_88: 1 - (0.78 × 0.1) - (0 × 0.5) = 0.922; v_89: 1 - (0.68 × 0.1) - (0 × 0.5) = 0.932; v_90: 1 - (0.35 × 0.1) - (0 × 0.5) = 0.965.

[0173] Multi-dimensional version evaluation fusion. Version comprehensive score = α×Integrity_score + β×Reliability_score + γ×Time_proximity_factor; where α=0.4 is the integrity weight; β=0.3 is the reliability weight; γ=0.3 is the time correlation weight; Time_proximity_factor = e -|time_diff| / 1000 is the time distance factor, time_diff is the time distance of the version data. Calculate the comprehensive score of each version: Time_proximity_factor(v_87) = e -4.012 / 1000= 0.996; Time_proximity_factor(v_90) = e -0.112 / 1000 = 0.999; v_87 comprehensive score = 0.4×1.0 + 0.3×0.955 + 0.3×0.996 = 0.4 + 0.287 + 0.299 = 0.986; v_90 comprehensive score = 0.4×1.0 + 0.3×0.965 + 0.3×0.999 = 0.4 + 0.290 +0.300 = 0.990. Check version dependencies: v_90 depends on incremental version: [Δ_89_90], status: Available; v_90 has no broken dependency chains and can be used as the primary recovery version.

[0174] Determining the optimal version and back-up plans. Ranking by comprehensive score: v_90: score 0.990 (primary recovery version); v_87: score 0.986 (backup version 1); v_89: score 0.966 (backup version 2). Primary recovery version information: Version ID: v_90; Starting address: 0x7FA8C000; Version size: 156KB; Incremental dependencies: [Δ_89_90]. Version recovery plans: Primary plan: Recover directly from v_90; Plan 1: Recover from v_87 + increments [Δ_87_88, Δ_88_89, Δ_89_90]; Plan 2: Recover from v_89 + increments [Δ_89_90].

[0175] Calculate a patterned incremental path. Read the primary recovery version v_90, and the time difference between the failure time and the version is 0.112 seconds. Analyze the incremental state to be applied: recovery is required from the v_90 state to the failure time. Calculate incremental weights based on topic change patterns: 5 periodic topics: weight 0.7 (regular, predictable changes); 3 bursty topics: weight 1.0 (complete state required); 6 stable topics: weight 0.3 (small changes, skippable); 1 random topic: weight 0.8 (recent state required). Construct an incremental path weight matrix: Path 1 (direct): v_90 → failure time, weight = 0.95; Path 2 (via incremental): v_89 → Δ_89_90 → failure time, weight = 0.88. Use the Dijkstra algorithm to select the optimal path: The optimal incremental application sequence: [direct recovery from v_90, application of a predicted incremental of 0.112 seconds].

[0176] Different strategies are adopted for topics with different patterns: For stable topics, the fast recovery path is as follows: the topic " / meter / data / hourly" directly jumps to the most recent state, skipping six intermediate changes; the topic " / energy / daily_report" maintains the v_90 state without updating. For bursty topics, the complete recovery path is as follows: the topic " / alarm / fault_detect" applies all increments [Δ_88_89, Δ_89_90, Δ_90_fault]; the topic " / control / emergency" verifies the integrity of each increment. For periodic topics, the predictive recovery path is as follows: the topic " / meter / data / real_time" predicts the state at the time of the fault based on a periodic function; the prediction formula is: State_predict = State_v90 + ΔState × (time_diff / period); ΔState = 2.3 × sin(2π × 0.112 / 300) = 0.016; State_predict = 45.2 + 0.016 = 45.216. Where State_predict represents the predicted state value at the time of failure, State_v90 is the state value of version v_90, ΔState is the state change, and period is the period length.

[0177] Incremental application and state verification. Recovery was performed according to the optimal incremental application sequence: v_90 base state was loaded from address 0x7FA8C000; predicted incremental processing of topics with different modes was applied; and subscription state tables were batch updated. Atomic operations were performed: state updates were atomically guaranteed using memory transactions; transaction start time: 1699156789015; state updates for 15 topics were applied; transaction commit time: 1699156789087 (72 milliseconds). State integrity verification: The reconstructed state SHA-256 hash was calculated: 0x4B7A...C9F1; comparison with the expected hash yielded a 99.8% match; 0 lost subscriptions were detected; 0 incorrect subscriptions were detected. State reconstruction verification results: Integrity score: 1.0; Consistency score: 0.998; Recovery time: 124 milliseconds; Verification passed.

[0178] Prioritize subscription topics. Read the 15 reconstructed subscription topics and calculate their priority scores: Topic Priority Score = ω1 × Business_importance + ω2 × Recovery_urgency; where ω1 = 0.6 is the business importance weight; ω2 = 0.4 is the recovery urgency weight; Business_importance is the business importance score (0-1); and Recovery_urgency is the recovery urgency score (0-1). Calculation examples: " / meter / data / real_time": Business_importance = 0.9, Recovery_urgency = 1.0; Priority Score = 0.6 × 0.9 + 0.4 × 1.0 = 0.54 + 0.4 = 0.94; " / energy / daily_report": Business_importance = 0.5, Recovery_urgency = 0.3; Priority Score = 0.6 × 0.5 + 0.4 × 0.3 = 0.3 + 0.12 = 0.42. Topic subscription priority sorting: high priority batch (5 topics): score > 0.8; medium priority batch (6 topics): score 0.5-0.8; low priority batch (4 topics): score < 0.5.

[0179] A batch-based parallel subscription strategy was implemented. The following topics were analyzed for correlation within high-priority batches: Correlation Group 1: [" / meter / data / real_time", " / meter / status", " / meter / quality"] (meter-related); Correlation Group 2: [" / control / power_limit", " / control / emergency"] (control-related). Parallel subscriptions within a batch were grouped: Group 1 subscribed to three meter topics in parallel, with an estimated time of 15 milliseconds; Group 2 subscribed to two control topics in parallel, with an estimated time of 10 milliseconds. Subscriptions between groups were executed serially to avoid overloading the MQTT broker. Batch subscription fault tolerance scheme: 200 milliseconds per batch timeout; exponential backoff with an initial interval of 50 milliseconds; maximum number of retries: 3; and a failure threshold: a failure rate of >20% for topics within a batch triggers a fallback.

[0180] Subscription status is synchronized in real time. Subscription progress monitoring is established, with monitoring metrics including [number of subscription confirmations, number of subscription failures, current batch, and completion progress]. High-priority batches: 5 / 5 confirmed, 0 / 5 failed, 100% progress; medium-priority batches: 4 / 6 confirmed, 0 / 6 failed, 67% progress. Pipeline processing is implemented as follows: 0ms: High-priority batch subscription begins; 25ms: High-priority batch completes, medium-priority batch begins; 35ms: Low-priority batch data preprocessing begins; 85ms: Medium-priority batch completes, low-priority batch begins. Dynamic batch switching strategy: Completion rate threshold: 80%; High-priority batches immediately start the next batch when the completion rate reaches 100%; Medium-priority batches begin preprocessing the next batch when the completion rate reaches 83% (5 / 6).

[0181] In this embodiment, the version selection calculation time is 12 milliseconds; the incremental application time is 124 milliseconds; the state verification time is 36 milliseconds; the total batch subscription time is 168 milliseconds; and the overall recovery time is 340 milliseconds. The overall recovery time of the traditional single-version solution is 5200 milliseconds. In comparison, this embodiment improves performance by 93.5%, and reliability increases from 92.5% to 99.8%.

[0182] The present invention constructs an energy feature distance measurement function to map the change characteristics of subscription topics to a three-dimensional energy feature space with periodic intensity dimension, change severity dimension and stability index dimension, and uses a weighted distance function to calculate the similarity between topics. It can accurately capture the periodicity, suddenness and stability patterns unique to energy field data. Compared with traditional general clustering algorithms such as K-means, the pattern recognition accuracy is improved from 67% to 93%. In particular, in identifying periodic changes in power demand and sudden failure events, the accuracy is improved to 94% and 98% respectively, providing more accurate basic data for subsequent version management, and fundamentally solving the problem that existing technologies cannot effectively distinguish complex change patterns of energy data. By constructing a hierarchical state space model and designing a long-range dependency memory mechanism, maintaining a patterned state representation at a high level, retaining version detail information at a low level, and using an exponential decay weight function to weight historical states, the prediction algorithm can consider both short-term changes and long-term patterns, overcoming the limitation of traditional first-order Markov chains that can only capture the relationship between adjacent states. The accuracy of version access probability prediction is improved from 71% to 89%, and the version access prediction accuracy during energy peak and trough periods reaches 92% and 87% respectively, effectively reducing the version cache miss rate. The system's memory utilization efficiency is increased by 40% when processing complex energy data access patterns, improving the response speed of smart energy units under high load conditions. By designing a periodic pattern fusion mechanism, the periodic access pattern based on the sine function is mixed with the Markov chain transition probability for calculation, which can simultaneously capture the randomness and periodic laws of energy data. Compared with traditional solutions based solely on historical access frequency, the version access prediction accuracy during peak power load periods and low power consumption periods is improved by 32% and 28% respectively. In particular, when processing daily / weekly / seasonal energy consumption patterns, the version hit rate is increased from 76% to 94%, effectively reducing the overhead of repeated version loading. When facing data access with strong periodic characteristics in the energy field, the system's response time is reduced by 43%, providing reliable protection for the stable operation of smart energy units. By adopting the density peak detection algorithm to automatically identify cluster centers, calculate the local density of each topic and the distance to higher density points, and identify points with high density and high distance values in the graph as cluster centers, there is no need to preset the number of clusters. It can adaptively identify the true pattern distribution of energy subscription topics. Compared with traditional K-means and other algorithms that require a preset number of clusters, when dealing with scenarios where the number of subscription topics in energy units changes dynamically, the clustering accuracy is improved from 73% to 91%. In particular, when identifying the subscription patterns of newly connected energy devices and abnormal subscription behaviors, the detection rates reach 95% and 97% respectively, effectively avoiding pattern recognition errors caused by improper setting of the number of clusters, making version management strategies more accurate, and improving the overall system performance by 35%.By designing a version selection algorithm based on the failure time point, adopting a multi-dimensional evaluation fusion mechanism, calculating the version integrity score, reliability score and time correlation score, and using a weighted formula for the comprehensive score, it is possible to quickly locate the most suitable recovery version during failure recovery. Compared with the traditional fixed-interval version backup solution, the failure recovery time is reduced from 5-10 seconds to 340 milliseconds, and the recovery success rate is increased from 92.5% to 99.8%. Especially when dealing with frequent state changes and irregular failure modes of energy units, it can accurately select the optimal recovery point, avoiding data loss or inconsistency caused by restoring to an outdated version, providing key guarantees for the high-reliability operation of smart energy systems. By implementing patterned incremental state reconstruction, differentiated recovery strategies are adopted for subscription topics of different pattern types. Stable topics use a jumping mechanism to directly recover to the most recent state, bursty topics strictly apply all increments in sequence, and periodic topics predict missing states based on periodic functions, enabling the system to intelligently optimize the state recovery path. Compared with traditional full recovery or fixed incremental solutions, recovery efficiency is improved by 67%, and data consistency verification time is reduced from the original 2 seconds to 36 milliseconds. In particular, when dealing with mixed scenarios containing a large number of stable subscriptions and a small number of bursty subscriptions, the recovery path calculation time is reduced by 78%, and the overall fault recovery time is reduced from an average of 6 seconds to 340 milliseconds, providing efficient and reliable technical support for the rapid fault recovery of energy units in complex operating environments.

[0183] The preferred embodiments of the present invention are described in detail above. However, the present invention is not limited to the specific details in the above embodiments. Within the technical concept of the present invention, various equivalent transformations can be made to the technical solutions of the present invention, and these equivalent transformations all fall within the scope of protection of the present invention.

Claims

1. A third-party APP integration method for a smart energy unit, characterized in that: include: Monitor the subscription status changes of the MQTT client of the third-party APP container and generate subscription status change metadata; Based on the subscription status change metadata, the change pattern of the subscription topic is analyzed to obtain the topic change pattern classification results and topic prediction reliability scores. Based on this, the version access probability distribution is calculated, the version retention strategy is optimized, and the version storage resource allocation plan is generated. According to the version storage resource allocation plan, the subscription status is differentially encoded and written into the shared memory area. A version storage address mapping table is established to quickly restore the container status.

2. The method according to claim 1, characterized in that Obtain topic change pattern classification results and topic prediction reliability scores, including: Read the subscription status change metadata, analyze the topic change cycle, calculate the change entropy and variance, obtain the topic change frequency domain characteristics and topic change statistical characteristics, map them to the energy feature space, calculate the energy feature distance function, and generate a time series weighted distance matrix; Based on the time-series weighted distance matrix, cluster centers are identified, topic assignment is implemented, the topic cluster assignment results are obtained and their statistical characteristics are calculated, the clusters are mapped to predefined change pattern types, and the topic change pattern classification results and topic prediction reliability scores are obtained.

3. The method according to claim 2, characterized in that Obtain the frequency domain features and statistical features of topic changes, including: Read the metadata of subscription status changes, group them by topic ID to construct a time series change sequence, and use linear interpolation to form standardized time series data. Perform frequency domain transformation on it to identify the dominant frequency components and energy distribution, and obtain the frequency domain characteristics of topic changes. Calculate the mean, standard deviation, autocorrelation function and runs test results of the standardized time series data, evaluate the randomness index of the sequence, and obtain the statistical characteristics of the theme change; Calculate the sample entropy and approximate entropy of the standardized time series data, evaluate the sequence complexity, and obtain the complexity characteristics; combine the frequency domain and statistical characteristics of the topic changes with the complexity characteristics to form the full feature vector of the topic.

4. The method according to claim 3, characterized in that Generate a time-weighted distance matrix, including: Read the full feature vector of the topic, construct a three-dimensional energy feature space with periodic intensity dimension, change severity dimension and stability index dimension, and map the full feature vector of the topic into it to obtain the energy feature representation; Based on the energy feature representation, a comprehensive distance function is constructed, which includes the weighted sum of cycle distance, mutation distance and stability distance; The time decay factor is used to assign weights to recent change data, and the weighted distance between topics is calculated using a comprehensive distance function to generate a time series weighted distance matrix.

5. The method according to claim 3, characterized in that After obtaining the frequency domain features and statistical features of topic changes, feature dimension adaptive dimensionality reduction processing is also performed, including: Read the frequency domain and statistical characteristics of topic changes, use PCA to identify the main change directions, and obtain the principal component matrix of topic features; Based on the topic feature principal component matrix, the contribution rate of each principal component is calculated, and the key principal components whose contribution rates exceed the threshold are screened out to obtain a key principal component index list; accordingly, additional weights are given to the characteristic dimensions of high-importance topics, and the weights of the corresponding principal components in the topic feature principal component matrix are adjusted to obtain a weighted principal component feature matrix.

6. The method according to claim 2, characterized in that Get the topic cluster assignment results, including: Based on the temporal weighted distance matrix, the local density ρ of each topic and the distance Δ to the higher density point are calculated to obtain the density-distance feature map; In the density-distance feature map, points with high ρ values and high Δ values are identified as cluster centers, and a set of automatically identified cluster centers is obtained; Through density gradient-based topic assignment, each topic is assigned to the nearest cluster center, and the assignment confidence is recorded to obtain the topic cluster assignment result.

7. The method according to claim 1, characterized in that Generate a version store resource allocation plan, including: Based on the classification results of topic change patterns, an exponential decay weight function is calculated through a hierarchical state space model to construct an enhanced transition probability model that includes access history context. Based on the enhanced transition probability model, the periodic pattern parameters identified by the topic prediction reliability score are integrated to form a hybrid model of the periodic access pattern function and the Markov chain transition probability. An adaptive update mechanism is established to generate the version access probability distribution. Based on the version access probability distribution, combined with the energy unit hardware constraints and business continuity requirements, the modeled version retention strategy is calculated to obtain the version storage resource allocation plan.

8. The method according to claim 7, characterized in that Generate version access probability distribution, including: Based on the topic prediction reliability score, topics with periodic patterns are identified, and periodic parameters are analyzed to obtain a periodic pattern parameter set; based on this, a sine function model is calculated to obtain a periodic access pattern function; The periodic access pattern function is mixed with the results of the enhanced transition probability model to obtain the periodic enhanced transition probability; Based on the real-time collected version access logs, the transition probability is periodically enhanced, the transition matrix regularization is implemented, and the state access probability of the future predetermined steps is calculated to obtain the version access probability distribution.

9. The method according to claim 7, characterized in that Get the version storage resource allocation plan, including: Based on the version access probability distribution, we construct a version storage benefit function and a storage cost function, and accordingly model the version storage optimization problem as a 0-1 knapsack problem. Solve the 0-1 knapsack problem, construct a two-dimensional DP table, determine the optimal version selection set for each pattern type based on the DP backtracking path, obtain the pattern version retention strategy, and determine whether there is a resource allocation conflict; If it exists, a linear programming model is constructed, and the simplex method is used to solve and verify the feasibility to obtain the version storage resource allocation plan.

10. The method according to claim 8, characterized in that The periodic enhanced transition probability is obtained, including: Based on the period length T, phase offset φ, amplitude A and basic offset parameter B, a periodic access pattern function f_period(t) = A×sin(2πt / T + φ) + B is established; where t is the time variable; Construct a hybrid calculation formula P_hybrid(i, j, t) = α×P_markov(i, j) + β×f_period(t), where α and β are fusion weights, adjusted according to the reliability score of the pattern type; P_markov(i, j) is the Markov transition probability; P_hybrid is the periodic enhancement transition probability; Based on the hybrid calculation formula, the hybrid probability of different version state transitions in the time dimension is calculated to obtain the periodic enhanced transition probability.