Data storage method and device, equipment and storage medium

By selecting invalid sectors for erasure in instrument data storage and optimizing the query algorithm, the problems of low storage efficiency and query complexity are solved, achieving efficient data management and real-time analysis, which is suitable for new power systems and intelligent flexible control terminals.

CN121029632APending Publication Date: 2025-11-28ZHEJIANG CHINT ELECTRIC CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511041967.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-25
Publication Date
2025-11-28

AI Technical Summary

Technical Problem

In the field of instrument data storage technology, existing technologies are insufficient to meet the needs of new power systems or intelligent flexible control terminals for real-time analysis of minute-level data. In particular, when processing massive amounts of data with high real-time requirements and anomalies, there are difficulties in terms of low storage efficiency, write stability, and real-time performance of complex queries.

Method used

By determining the storage address of the data to be stored, selecting sectors with preset flags set to invalid for erasure, and writing the data into the erased sectors, combined with a circular storage structure and intelligent exception handling mechanism, the data storage and query algorithms are optimized to achieve efficient data management.

Benefits of technology

It improves data storage efficiency and write stability, enhances query efficiency, meets the needs of real-time analysis, and solves the problems of storage pressure, real-time requirements, and handling of complex abnormal scenarios for massive data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121029632A_ABST
    Figure CN121029632A_ABST
Patent Text Reader

Abstract

The invention provides a data storage method and device, equipment and a storage medium, and the method comprises the steps: determining a storage address of to-be-stored data, determining a first sector to which the to-be-stored data is to be written, setting a preset flag of the first sector to be in an invalid state, and storing the to-be-stored data in the first sector; and judging whether the first sector and a second sector in which the storage data of the last time period is written are the same sector or not, if the first sector is a new sector which is not the second sector, erasing the storage data of the first sector, and writing the data to be stored into the erased first sector. According to the data storage method provided by the embodiment of the invention, the preset mark of the first sector can be set to be in the invalid state when the stored data in the first sector is invalid, and the original stored data in the first sector is erased and the to-be-stored data is written into the erased first sector when the storage capacity of the second sector is saturated. The method and the device can avoid too long erasing processing time of the stored data and effectively improve the data storage efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of instrument data storage, in particular to a data storage method and device, equipment and storage medium. BACKGROUND

[0002] In the technical field of instrument data storage, the method based on linear storage and lookup faces great difficulties in storage efficiency, write stability, especially real-time performance of complex queries when processing the above-mentioned massive, high real-time and abnormal data, and it is difficult to meet the demand of real-time analysis of minute-level data for new power systems or intelligent flexible regulation terminals. SUMMARY

[0003] In view of the deficiencies in the prior art, the present application provides a data storage method, device, equipment and storage medium, aiming to solve the technical problem of low data storage efficiency.

[0004] In a first aspect, the present application provides a data storage method applied to a memory including at least one sector, the method comprising:

[0005] determining a storage address corresponding to to-be-stored data of a first time period;

[0006] determining a first sector corresponding to the to-be-stored data according to the storage address; the first sector is any sector in the at least one sector in which a preset flag is set to an invalid state;

[0007] if the first sector and a second sector in which storage data of a second time period is written are not the same sector, then performing erasing processing on the storage data of the first sector to obtain an erased first sector; the second time period is a previous time period of the first time period;

[0008] writing the to-be-stored data to the erased first sector.

[0009] In some embodiments, the determination of the storage address corresponding to the to-be-stored data of the first time period comprises:

[0010] determining a starting address of the to-be-stored data based on a freeze type of the to-be-stored data;

[0011] obtaining a current index of the to-be-stored data; the current index represents a storage position of the to-be-stored data in the memory;

[0012] determining the storage address of the to-be-stored data according to the starting address, the current index and a data length of the to-be-stored data.

[0013] In some embodiments, the data storage structure of the memory comprises a storage capacity; the method further comprises:

[0014] if the value of the current index is greater than or equal to the value of the storage capacity, performing an erasing process on a third sector where a starting index is located, to obtain an erased third sector; the starting index represents a storage location of the first piece of stored data in the memory;

[0015] writing the data to be stored into the erased third sector;

[0016] taking a first index of a sector connected to the third sector as a new starting index.

[0017] In some embodiments, the method further comprises:

[0018] in response to a data clearing instruction for the stored data in the memory, setting a preset flag of each sector in the at least one sector to an invalid state according to the data clearing instruction.

[0019] In some embodiments, the method further comprises:

[0020] in response to a data rollback instruction for rolling back stored data of a first index in a current sector to stored data of a second index in a target sector;

[0021] according to the data rollback instruction, if the current sector and the target sector are the same sector, reading at least one piece of stored data from the third index to the second index in the target sector; the third index is a storage location of the first piece of stored data in the target sector;

[0022] performing an erasing process on the target sector to obtain an erased target sector;

[0023] writing the at least one piece of stored data from the third index to the second index into the erased target sector.

[0024] In some embodiments, the method further comprises:

[0025] if the current sector and the target sector are not the same sector, setting a preset flag of the current sector, the target sector and at least one sector to be rolled back between the current sector to an invalid state.

[0026] In some embodiments, the data storage structure of the memory comprises a starting index and a current index, and the method further comprises:

[0027] obtaining a first time corresponding to the starting index, a second time of the current index and a query time;

[0028] determine whether the storage data of the memory is continuous data based on the start index, the current index, the first time, the second time, and the first time period, to obtain a determination result;

[0029] if the determination result indicates that the storage data of the memory is continuous data, determine an offset of the query time relative to the first time;

[0030] determine query data corresponding to the query time based on the start index and the offset.

[0031] In some embodiments, the method further comprises:

[0032] if the determination result indicates that the storage data of the memory is discontinuous data, determine an intermediate index and a third time of the intermediate index according to a binary search method, the start index, and the current index;

[0033] re-determine whether the storage data of the memory is continuous data according to the start index, the current index, the intermediate index, the first time, the second time, the third time, and the first time period, until the determination result indicates that the storage data of the memory is continuous data.

[0034] In a second aspect, the present application further provides a data storage device applied to a memory comprising at least one sector, the device comprising:

[0035] a first determination module configured to determine a storage address corresponding to to-be-stored data in a first time period;

[0036] a second determination module configured to determine a first sector corresponding to the to-be-stored data according to the storage address; the first sector is any sector in the at least one sector in which a preset flag is set to an invalid state;

[0037] a first erasing module configured to, in a case where the first sector is not the same as a second sector in which storage data in a second time period is written, erase the storage data in the first sector to obtain an erased first sector; the second time period is a previous time period of the first time period;

[0038] a first writing module configured to write the to-be-stored data to the erased first sector.

[0039] In a third aspect, the present application further provides an electronic device comprising a processor and a memory, wherein the memory stores a computer program configured to be executed by the processor to implement the method of any one of the above aspects.

[0040] In a fourth aspect, the present application provides a computer readable storage medium, wherein the computer readable storage medium stores a computer program, and the computer program is executed by a processor to implement the method in any of the preceding aspects.

[0041] The data storage method provided by the embodiments of the present application determines the storage address of the to-be-stored data, and then determines the first sector to which the to-be-stored data is to be written, wherein the preset flag of the first sector is set to an invalid state, and it is determined whether the first sector and the second sector in which the storage data of the last time period is written are the same sector, if the first sector is a new sector other than the second sector, the storage data of the first sector is erased, and the to-be-stored data is written to the first sector after erasing. The data storage method provided by the embodiments of the present application can set the preset flag of the first sector to an invalid state when the data stored in the first sector is invalid, so that the original storage data in the first sector is considered invalid, but the storage data in the first sector is not erased. When the storage capacity of the second sector reaches saturation, the original storage data in the first sector is erased, and the to-be-stored data is written to the first sector after erasing. This can avoid that the erasing of the storage data takes too long time, and effectively improve the efficiency of data storage. BRIEF DESCRIPTION OF DRAWINGS

[0042] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative effort.

[0043] Figure 1 A flowchart of the data storage method provided by the embodiments of the present application is shown in FIG. 1.

[0044] Figure 2 A design structure diagram of a single sector of the memory provided by the embodiments of the present application is shown in FIG. 2.

[0045] Figure 3 Another flowchart of the data storage method provided by the embodiments of the present application is shown in FIG. 3.

[0046] Figure 4 A design structure diagram of multiple sectors of the memory provided by the embodiments of the present application is shown in FIG. 4.

[0047] Figure 5 A flowchart of querying data in the data storage method provided by the embodiments of the present application is shown in FIG. 5.

[0048] Figure 6 A structure diagram of a data storage device provided by the embodiments of the present application is shown in FIG. 6.

[0049] Figure 7A hardware structure schematic diagram of a data storage device is provided for an embodiment of the present application. DETAILED DESCRIPTION

[0050] The technical solutions in the embodiments of the present application will be clearly and completely described in combination with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by a person skilled in the art without creative work fall within the scope of protection of the present application.

[0051] In the description of the present application, the terms "first", "second" are used only for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined with "first", "second" can explicitly or implicitly include one or more of the features. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that includes a series of steps or modules is not limited to the listed steps or modules, but can optionally include steps or modules that are not listed, or can optionally include other steps or modules inherent to the process, method, product or device.

[0052] In this document, reference to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the application. The appearance of the phrase in various places in the specification does not necessarily all refer to the same embodiment, nor does it necessarily refer to a particular alternative embodiment. It will be explicitly understood by a person skilled in the art that the embodiments described herein can be combined with other embodiments.

[0053] With the comprehensive promotion of smart grid construction and the rapid development of power Internet of Things technology, the power system has increasingly high requirements for the accuracy and timeliness of data collection. Minute-level frozen data, as the basic data for power system operation state monitoring, load analysis and power quality evaluation, its storage and query efficiency directly affects the grid dispatching decision, fault diagnosis and new energy access and other scene applications.

[0054] The current power minute frozen data management faces the following technical problems: a) massive data storage pressure: a single device generates about 520,000 minute-level data per year (60x24x365); b) high real-time requirement: short data collection period (60 seconds), need to ensure write stability; c) time sensitivity: strict requirement for time series integrity in power data analysis; d) complex abnormal scenario processing: time rollback caused by device clock abnormality, data discontinuity caused by power failure, cyclic coverage strategy under limited storage space, query efficiency bottleneck.

[0055] Figure 1 A flowchart of a data storage method provided by an embodiment of the present application is shown in FIG. 1. The data storage method provided by the embodiment of the present application can be applied to a memory including at least one sector, and can include, but is not limited to, the following steps and combinations of the following steps. Figure 1

[0056] Step 101: Determine a storage address corresponding to the to-be-stored data of the first time period.

[0057] In the embodiment, the data storage method is applied to an intelligent flexible regulation terminal. The intelligent flexible regulation terminal is a terminal device supporting communication protocol conversion between a load management system master station or an intelligent measurement terminal and a flexible load device, and has local and remote regulation functions. The local regulation function is based on load characteristics of a monitoring measurement point and operating state data of the flexible load device, and executes a control instruction through localized decision-making. The remote regulation function executes a regulation command issued by the load management system master station or the intelligent measurement terminal.

[0058] In the embodiment, the first time period can be determined according to actual conditions, and is not limited herein. As an example, the first time period can be 60 s. The to-be-stored data can be determined according to actual conditions, and is not limited herein. As an example, the data content of the to-be-stored data can include a storage time and variable data, where the storage time can be a frozen time tag, and the variable data can be voltage data, current data, or power data. The storage data can be acquired according to a preset time period. When the first time period arrives, the to-be-stored data of the current time period is acquired, and a memory interface is called to determine the storage address of the to-be-stored data based on a starting address of the to-be-stored data and a current index.

[0059] It can be understood that the process of storing the to-be-stored data to the memory can be freezing the to-be-stored data, and the to-be-stored data can be frozen data, which is not limited herein.

[0060] In some embodiments, determining the storage address corresponding to the to-be-stored data of the first time period includes:

[0061] determining the starting address of the to-be-stored data based on a frozen type of the to-be-stored data;

[0062] acquiring a current index of the to-be-stored data; the current index represents a storage position of the to-be-stored data in the memory;

[0063] determining the storage address of the to-be-stored data according to the starting address, the current index, and a data length of the to-be-stored data.

[0064] ​In this context, "freeze type" refers to a strategy category used in a power system to classify and store data, isolating data with different characteristics. The freeze type can be determined based on actual conditions and is not limited here. As an example, the freeze type can include at least one of the following: freeze cycle type, freeze data type, or freeze path type. Specifically, the freeze cycle type can be a type that freezes data on a minute-by-minute basis or a type that freezes data on an hour-by-hour basis; the freeze data type can be a type that freezes voltage data, a type that freezes current data, or a type that freezes power data. It should be noted that the freeze cycle type for the first time period is a type that freezes data on a minute-by-minute basis.

[0065] In this embodiment, the data storage structure of the memory includes a start address, which can be the starting position of the data to be stored of the current frozen type in the memory. The start address can be determined according to the actual situation and is not limited here. As an example, the start address can have a mapping relationship with the frozen type, with different frozen types corresponding to different start addresses. Determining the start address of the data to be stored based on the frozen type of the data to be stored can be done by determining the start address corresponding to the frozen type in the mapping relationship based on the frozen type of the data to be stored.

[0066] If multiple types of frozen data are obtained, the starting address of each type of data to be stored is determined according to the different freezing types, and the different data storage structure of each type of data to be stored is determined according to the different starting addresses.

[0067] In this embodiment, the current index (end_index) can be used to store the data to be stored into the memory in a certain order. The current index can be determined according to the actual situation and is not limited here. As an example, the current index can be an index pointing to the next free storage location in the memory. The value of the current index is incremented by 1 for each additional piece of stored data. Specifically, it can be a block index. The process of obtaining the current index of the data to be stored can be determined according to the actual situation and is not limited here. As an example, the current index can be read from a preset register.

[0068] In this embodiment, the data length (block_size) can be the frozen length of a single piece of data to be stored. The process of determining the storage address of the data to be stored based on the starting address, the current index, and the data length can be determined according to the actual situation and is not limited here. As an example, the first product address can be obtained by multiplying the current index and the data length, and the storage address can be obtained by adding the first product address and the starting address.

[0069] Here, by determining the starting address of storage based on the freezing type of the data to be stored, different types of data can be stored in different areas of the memory in an orderly manner, improving the efficiency of data management; and by combining the current index and the data length, the storage address of the data to be stored in the memory is calculated, avoiding the problems of data overwriting or storage conflicts, and improving the reliability of data storage.

[0070] Step 102: Determine the first sector corresponding to the data to be stored based on the storage address; the first sector is any sector in at least one sector where the preset flag is set to invalid.

[0071] In this embodiment, the first sector corresponding to the data to be written can be determined based on the storage address and the preset address of the sector. In some embodiments, the byte of the storage address can be divided by the byte of the preset address to obtain a first divisor; the first divisor can be rounded down to obtain a first integer; the sector corresponding to the first integer can be determined as the first sector, and the storage address where the data to be stored is currently written can be determined to be located in the first sector, wherein the first integer is the first number of the first sector.

[0072] In this embodiment, the function of the preset flag is to skip invalid sectors during a query. The preset flag can be determined according to the actual situation and is not limited here. As an example, the preset flag can be a zeroing flag. When the data stored in the first sector has become invalid, the preset flag of the first sector can be set to an invalid state, making the original stored data in the first sector considered invalid. During data query, the first sector can be skipped, but the data stored in the first sector is not erased. This avoids the problem of low data storage efficiency caused by the long time required to erase stored data, and effectively improves the efficiency of data storage.

[0073] Each sector can reserve 4 bytes at the end, which are used to store a preset flag and check data. The check data can be a Cyclic Redundancy Check (CRC).

[0074] Step 103: If it is determined that the first sector and the second sector where the stored data of the second time period are written are not the same sector, then the stored data of the first sector is erased to obtain the erased first sector; the second time period is the time period before the first time period.

[0075] In this embodiment, the process of determining that the first sector and the second sector where the stored data of the second time period is written are not the same sector can be determined according to the actual situation and is not limited here. As an example, the first number of the first sector and the second number of the second sector can be compared to obtain a first comparison result; if the first comparison result indicates that the first number and the second number are inconsistent, it is determined that the first sector and the second sector are not the same sector. Wherein, if it is determined that the first sector and the second sector where the stored data of the second time period is written are the same sector, then the data to be stored is directly written to the storage address of the first sector.

[0076] Step 104: Write the data to be stored to the first sector after erasure.

[0077] In this embodiment, the storage address of the data to be stored can be an address in the first sector, and the data to be stored can be written to the storage address in the first sector. After writing the data to be stored to the erased first sector, the method further includes: determining the verification data of the data to be stored based on the current index and the data to be stored; and writing the current index and verification data to the data block where the data to be stored is located. When the first time period is 60 seconds, the data block can be a minute-frozen data block. The verification data can be a CRC checksum. The current index and CRC checksum of the data block are automatically calculated and written by the memory management logic, and the called memory interface only needs to provide the data content of the data to be stored.

[0078] In some embodiments, the data storage structure of the memory includes storage capacity; the method further includes:

[0079] If the current index value is greater than or equal to the storage capacity value, the third sector where the starting index is located will be erased to obtain the erased third sector; the starting index represents the storage location of the first piece of stored data in the memory;

[0080] Write the data to be stored to the third sector after erasure;

[0081] Use the first index of the next contiguous sector following the third sector as the new starting index.

[0082] In this embodiment, the storage capacity can be the total capacity of the memory. The storage capacity can be determined according to the actual situation and is not limited here. As an example, the storage capacity can be calculated during initialization based on the data length of each piece of data to be stored.

[0083] In this embodiment, the starting index (start_index) can be determined according to the actual situation and is not limited here. As an example, the starting index can be an index pointing to the earliest valid stored data location in the memory.

[0084] Here, if the current index value is greater than or equal to the storage capacity value, it indicates that the storage capacity of the memory has been filled with stored data. By locating the starting index (the earliest written data position), the third sector where the starting index is located is determined, and the third sector is erased to obtain an erased third sector for writing the data to be stored, thus realizing the circular storage of the data to be stored. The data to be stored is written into this erased third sector, and the first index of the next adjacent sector after the third sector is used as the new starting index. By updating the starting index, the updated earliest written data position can be quickly located, effectively improving the convenience of subsequent data query.

[0085] In some embodiments, the method further includes:

[0086] In response to a data clearing instruction for data stored in memory, a preset flag for each sector in at least one sector is set to an invalid state according to the data clearing instruction.

[0087] In this embodiment, after receiving a data clearing command, a preset flag for each sector is set to an invalid state, thereby marking the stored data in each sector of the entire memory as invalid. Furthermore, when new stored data needs to be written to a sector of the memory later, the data in that sector can be erased. This avoids excessively time-consuming data erasure processes and effectively improves data storage efficiency.

[0088] The method further includes, after setting the preset flag of each sector in at least one sector to an invalid state according to the data clearing instruction, determining the freeze parameters according to the freeze type of the data to be stored; and initializing the memory instance based on the freeze parameters. It should be noted that the freeze parameters can be freeze path parameters or freeze period parameters, etc.

[0089] In some embodiments, the method further includes:

[0090] In response to a data rollback command that rolls back the stored data at the first index in the current sector to the stored data at the second index in the target sector;

[0091] According to the data rollback instruction, if the current sector and the target sector are the same sector, at least one piece of stored data from the third index to the second index in the target sector is read; the third index is the storage location of the first piece of stored data in the target sector.

[0092] The target sector is erased to obtain the erased target sector;

[0093] Write at least one piece of stored data from the third index to the second index into the erased target sector.

[0094] In this embodiment, the value of the first index can be n, and the value of the second index can be m, where n can be greater than m. The process of determining whether the current sector and the target sector are the same sector can be determined according to the actual situation and is not limited here. As an example, the number of the current sector can be compared with the number of the target sector to obtain a second comparison result; if the second comparison result indicates that the number of the current sector and the number of the target sector are consistent, then it is determined that the current sector and the target sector are the same sector.

[0095] In this embodiment, the value of the third index can be k, and m can be greater than k. Reading at least one stored data from the third index to the second index in the target sector can be done by reading at least one stored data between the k-th index and the m-th index. The target sector is then erased to obtain an erased target sector; at least one stored data between the k-th index and the m-th index is written into the erased target sector.

[0096] Here, when the current sector and the target sector are the same sector, this method first reads at least one stored data from the third index to the second index in the target sector, then performs an erasure process on the target sector, and finally writes the read data into the erased target sector. This avoids the risk of data loss caused by direct overwrite and improves the reliability of data storage.

[0097] In some embodiments, the method further includes:

[0098] If the current sector and the target sector are not the same sector, then the preset flag of at least one sector to be rolled back between the current sector, the target sector, and the current sector will be set to an invalid state.

[0099] In this embodiment, if the second comparison result indicates that the number of the current sector is inconsistent with the number of the target sector, it is determined that the current sector and the target sector are not the same sector. Based on the number of the current sector and the number of the target sector, it is determined whether there is a sector to be rolled back in the current sector and the target sector. If the number of the current sector and the number of the target sector are consecutive, it is determined that there is no sector to be rolled back in the current sector and the target sector, and the preset flag of the current sector can be set to an invalid state.

[0100] If the current sector number and the target sector number are not consecutively numbered, then at least one sector to be rolled back between the target sector and the current sector is determined based on the current sector number and the target sector number. The preset flags for the current sector and at least one sector to be rolled back can be set to an invalid state. It should be noted that at least one sector number can be determined based on the current sector number and the target sector number, and thus at least one sector to be rolled back can be determined based on the number of at least one sector.

[0101] For example, after setting the preset flag of at least one sector to be rolled back between the current sector, the target sector, and the current sector to an invalid state, at least one stored data from the third index to the second index in the target sector can be read; the target sector can be erased to obtain the erased target sector; and at least one stored data from the third index to the second index can be written into the erased target sector.

[0102] Here, during the process of rolling back stored data, a mechanism for judging the relationship between the numbering of the current sector and the target sector is introduced to determine whether there are sectors to be rolled back between the current sector and the target sector. The preset flags of the current sector and the possible sectors to be rolled back are set, avoiding unnecessary state traversal and processing operations, effectively reducing the computation and processing overhead of the system during the process of rolling back stored data, and improving the execution efficiency of stored data state management.

[0103] In some embodiments, the data storage structure of the memory includes a starting index and a current index, and the method further includes:

[0104] Get the first time corresponding to the starting index, the second time of the current index, and the query time;

[0105] Based on the starting index, current index, first time, second time, and first time period, determine whether the stored data in the memory is continuous data and obtain the determination result;

[0106] If the judgment result indicates that the stored data in the memory is continuous data, determine the offset of the query time relative to the first time.

[0107] Based on the starting index and offset, determine the query data corresponding to the query time.

[0108] In this embodiment, the memory can associate timestamp information with each index of stored data to record the write time, modification time, or effective time of the data corresponding to that index. The value of the starting index can be 'a', and the first time corresponding to the starting index can be 'Ta'; the value of the current index can be 'b', and the second time corresponding to the current index can be 'Tb'; the query time can be 'T'.

[0109] In this embodiment, the storage data in the memory is continuous data, indicating that the memory includes a continuous data range. The process of determining that the stored data in the memory is continuous data based on the starting index, the current index, the first time, the second time, and the first time period can be determined according to the actual situation and is not limited here. As an example, a first difference can be obtained by subtracting the value of the starting index from the value of the current index; a second difference can be obtained by subtracting the first time from the second time; a first ratio can be obtained by comparing the second difference with the first time period; and the first difference can be compared with the first ratio. If the first difference and the first ratio are consistent, then the stored data in the memory is determined to be continuous data.

[0110] In some embodiments, the method further includes:

[0111] If the judgment result indicates that the stored data in the memory is discontinuous, the intermediate index and the third time of the intermediate index are determined according to the binary search method, the starting index and the current index.

[0112] Based on the starting index, current index, intermediate index, first time, second time, third time, and the first time period, re-determine whether the stored data in the memory is continuous data until the determination result indicates that the stored data in the memory is continuous data.

[0113] In this embodiment, if the first difference is inconsistent with the first ratio, it is determined that the stored data in the memory is discontinuous; then, a binary search method is used to determine the query data corresponding to the query time. Specifically, an intermediate index can be determined based on the binary search method, the starting index, and the current index; the third time of the intermediate index can be obtained; based on the starting index, the intermediate index, the first time, the third time, and the first time period, it is determined that the stored data in the memory is continuous; the offset of the query time relative to the first time is determined; and the query data corresponding to the query time is determined based on the starting index and the offset.

[0114] Specifically, based on the intermediate index, the current index, the third time, the second time, and the first time period, it can be determined that the stored data in the memory is continuous data; the offset of the query time relative to the third time can be determined; and the query data corresponding to the query time can be determined based on the intermediate index and the offset.

[0115] In this embodiment, the process of determining the offset of the query time relative to the first time can be determined according to the actual situation and is not limited here. As an example, the offset is obtained by subtracting the query time from the first time.

[0116] In this embodiment, the process of determining the query data corresponding to the query time based on the starting index and the offset can be determined according to the actual situation and is not limited here. As an example, the value of the starting index and the offset are summed to obtain the value of the query index corresponding to the query time, and thus the query data is determined based on the query index.

[0117] Here, by introducing a starting index and a current index, and combining the time relationship between the first time, the second time, and the query time, the corresponding position of the query time in memory can be quickly located. This method avoids the time overhead of traditional traversal retrieval methods and significantly improves data query efficiency.

[0118] The following describes the data storage method provided in the embodiments of this application. This method may include an efficient minute-freeze data storage and query method, which fundamentally solves the following problems: 1. By using an innovative circular storage structure and intelligent anomaly handling mechanism, the storage efficiency and write stability of massive amounts of data are significantly improved. 2. An adaptive query algorithm is designed to dynamically optimize the query path for continuous and non-continuous data, greatly improving query efficiency and meeting real-time analysis needs.

[0119] The circular memory data structure definition includes:

[0120]

[0121] Here, `start_address` is the starting address of each freeze type; if there are multiple freeze types, multiple memory structures need to be defined. `length` is the memory storage space length; due to the read / write characteristics of flash memory, the length is generally one sector beyond the freeze type depth. `block_size` is the freeze length of a single data entry; generally, frozen data includes a freeze time stamp and variable data. `capacity` is the total memory capacity, calculated during initialization based on the freeze length of each entry. `start_index` is the starting index of the memory, dynamically calculated during cyclic overwrites and time rollbacks. `end_index` is the current index, incremented by 1 for each new frozen data entry, dynamically calculated during time rollbacks. Mutexes are used to protect concurrent access to memory in multi-tasking or interrupt-driven environments, ensuring the atomicity of data writing and index updates.

[0122] Figure 2 This is a schematic diagram of a single sector design structure of a memory provided in an embodiment of this application, as shown below. Figure 2As shown, each minute-frozen data block includes: data content, block index, and CRC checksum. Four bytes are reserved at the end of each storage sector: a zeroing flag and a CRC checksum. A key mechanism of the data storage method provided in this application embodiment is that when the zeroing flag is set, all data in that sector is considered invalid and not included in the query. The block index and CRC are automatically calculated and written by the memory management logic; the external interface only needs to provide the data content.

[0123] Figure 3 This is another flowchart illustrating a data storage method provided in an embodiment of this application, including the following steps: memory initialization; determining whether the freeze period has been reached, and if so, calling the memory interface; otherwise, continuing to determine whether the freeze period has been reached; calculating the storage address of the frozen data; determining whether the sector where the storage address is located is a new sector, and if it is a new sector, erasing the new sector and writing the frozen data; if it is not a new sector, directly writing the frozen data; calculating and writing the block index and CRC; updating the starting index and the current index; ending.

[0124] The circular memory workflow also includes: freezing data and writing it sequentially to the sectors of the circular memory (e.g., buffers). When a sector (e.g., buffer) is full, the oldest data is automatically overwritten (updating the start index start_index). The management logic is responsible for index maintenance, CRC calculation and verification, and sector status management.

[0125] Figure 4 This is a schematic diagram of the memory sector design structure provided in the embodiments of this application, such as... Figure 4 As shown, taking four storage sectors as an example, we describe three core abnormal scenarios: zeroing, time rollback, and circular overwrite.

[0126] Part 1: Clearing process.

[0127] Upon receiving a zeroing command, the zeroing flags of all sectors are set to invalid, marking the entire memory data as invalid. When freeze parameters are modified, the existing memory instance is deleted and reinitialized with the new parameters.

[0128] Part Two: Time Rollback Mechanism.

[0129] 1. Same sector rollback: Roll back from data content n in the fourth storage sector 4 to data content m. First, read the first m data contents, erase the fourth storage sector 4, then transfer the first m data contents to the fourth storage sector 4, and modify the current index to m in the fourth storage sector 4.

[0130] 2. Rollback from different sectors: Rollback from the data content n of the fourth storage sector 4 to the data content m of the second storage sector 2. First, invalidate the zeroing flags of the fourth storage sector 4 and the third storage sector 3. Then, transfer the first m data contents of the second storage sector 2. Finally, modify the current index to m of the second storage sector 2. The process of modifying the current index to m of the second storage sector 2 can refer to the steps of rollback from the same sector.

[0131] 3. Covered Sector Rollback: Refer to the above logic for same-sector rollback or different-sector rollback, and consider the current valid data range (start_index, end_index). For example, if the first storage sector 1 is covered, then the data in the first storage sector 1 is the latest data. If we roll back from the data content n of the first storage sector 1 to the data content m of the second storage sector 2, then first invalidate the zeroing flags of the first storage sector 1, the fourth storage sector 4, and the third storage sector 3, then transfer the first m data contents of the second storage sector 2, and finally modify the current index to m of the second storage sector 2.

[0132] Part 3: When a write causes the oldest data to be overwritten, start_index is automatically recalculated (for example, after overwriting the first storage sector 1, start_index is updated to the index of the first data in the second storage sector 2).

[0133] To efficiently locate data at a specific time point within a circular buffer that may contain discontinuous data. Figure 5 This is a schematic diagram illustrating the data query process in the data storage method provided in this application embodiment, such as... Figure 5 As shown, the data query steps include:

[0134] 1. Start: Input the time point T to be queried and the index c of the target data. If c is less than or equal to a(start_index), then read the data of a; if c is greater than or equal to b(end_index), then read the data of b. If c is greater than a(start_index) and less than b(end_index), then determine the effective data index range [a(start_index), b(end_index)].

[0135] 2. Determine the continuity of the interval [a, b]: Calculate whether (ba) is equal to (Tb-Ta) / freeze period (e.g., 60 seconds). If they are equal, then it is a continuous data interval.

[0136] 3. Continuous range query: Directly calculate the offset (e.g., difference) of c relative to a based on the time difference, and retrieve the data by index a+offset. This can effectively avoid the binary search loop that searches for data multiple times, thus effectively improving the efficiency of data retrieval.

[0137] 4. Non-continuous interval query: Use binary search to search for index c in the interval [a,b].

[0138] 5. Sub-interval continuity check: During the binary search process, for each newly obtained sub-interval, repeat step 2 to check for continuity. If the sub-interval is continuous, directly calculate the offset and obtain the data; if it is still discontinuous, continue the binary search. This strategy significantly reduces the binary search depth, especially when there are few discontinuous points.

[0139] Specifically, the binary search algorithm is used to find d, where d can be any index between a and b, such as an intermediate index between a and b. The algorithm then checks if c is greater than d. If c is greater than d, a is set to d, and the continuity of the interval [d, b] is determined. If c is less than or equal to d, the algorithm checks if c is equal to d. If c = d, the data in d is read and identified as the data in c. If c is not equal to d, indicating that c is less than d, b is set to d, and the continuity of the interval [a, d] is determined.

[0140] The core innovation of this invention lies in its three-pronged approach to solving the critical pain points of managing minute-by-minute frozen power data. Through a circular storage structure, it provides an economical and efficient storage foundation for massive amounts of data and naturally supports overwriting. Intelligent anomaly handling, particularly a systematic time rollback mechanism, solves the data corruption problem caused by clock anomalies, ensuring data reliability. An adaptive query algorithm dynamically assesses data continuity and intelligently selects the optimal query path (direct location or binary search), improving query efficiency to a level that meets real-time analysis requirements.

[0141] This method effectively overcomes the technical challenges of storing, recovering from anomalies, and efficiently querying massive time-series data at the minute level in the power industry. It provides a solid data foundation for building a highly reliable and real-time new power system, and has significant application value and prospects for promotion.

[0142] Figure 6 This is a schematic diagram of the structure of a data storage device provided in an embodiment of this application, such as... Figure 6 As shown, this application also provides a data storage device applied to a memory including at least one sector, the data storage device comprising 600:

[0143] The first determining module 601 is used to determine the storage address corresponding to the data to be stored in the first time period;

[0144] The second determining module 602 is used to determine the first sector corresponding to the data to be stored based on the storage address; the first sector is any sector in at least one sector whose preset flag is set to invalid.

[0145] The first erasure module 603 is used to erase the stored data in the first sector when it is determined that the first sector and the second sector where the stored data is written in the second time period are not the same sector, so as to obtain the erased first sector; the second time period is the time period before the first time period.

[0146] The first write module 604 is used to write the data to be stored to the erased first sector.

[0147] In some embodiments, the first determining module 601 is further configured to determine the starting address of the data to be stored based on the freezing type of the data to be stored; obtain the current index of the data to be stored; the current index represents the storage location of the data to be stored in the memory; and determine the storage address of the data to be stored based on the starting address, the current index and the data length of the data to be stored.

[0148] In some embodiments, the data storage structure of the memory includes storage capacity; the data storage device further includes: a second erasure module, configured to erase the third sector where the starting index is located if the value of the current index is greater than or equal to the value of the storage capacity, to obtain the erased third sector; the starting index represents the storage location of the first piece of stored data in the memory; a second write module, configured to write the data to be stored to the erased third sector; and to use the first index of the next adjacent sector after the third sector as the new starting index.

[0149] In some embodiments, the data storage device further includes: a first setting module, configured to, in response to a data clearing instruction for data stored in the memory, set a preset flag of each sector in at least one sector to an invalid state according to the data clearing instruction.

[0150] In some embodiments, the data storage device further includes: a response module, configured to respond to a data rollback instruction that rolls back stored data at a first index in the current sector to stored data at a second index in the target sector; a first read module, configured to read at least one stored data from a third index to a second index in the target sector if the current sector and the target sector are the same sector, according to the data rollback instruction; the third index being the storage location of the first stored data in the target sector; a third erase module, configured to erase the target sector to obtain an erased target sector; and a third write module, configured to write at least one stored data from the third index to the second index into the erased target sector.

[0151] In some embodiments, the data storage device further includes: a second setting module, configured to set a preset flag of at least one sector to be rolled back between the current sector, the target sector, and the current sector to an invalid state if the current sector and the target sector are not the same sector.

[0152] In some embodiments, the data storage structure of the memory includes a starting index and a current index. The data storage device further includes: a first acquisition module, configured to acquire a first time corresponding to the starting index, a second time of the current index, and a query time; a judgment module, configured to determine whether the stored data in the memory is continuous data based on the starting index, the current index, the first time, the second time, and the first time period, and obtain a judgment result; a fourth determination module, configured to determine the offset of the query time relative to the first time if the judgment result indicates that the stored data in the memory is continuous data; and a fifth determination module, configured to determine the query data corresponding to the query time based on the starting index and the offset.

[0153] In some embodiments, the judgment module is further configured to, if the judgment result indicates that the stored data in the memory is discontinuous data, determine the intermediate index and the third time of the intermediate index according to the binary search method, the starting index and the current index; and re-determine whether the stored data in the memory is continuous data according to the starting index, the current index, the intermediate index, the first time, the second time, the third time and the first time period, until the judgment result indicates that the stored data in the memory is continuous data.

[0154] To implement the method of the embodiments of this application, Figure 7 This is a schematic diagram of the hardware structure of a data storage device provided in an embodiment of this application, such as... Figure 7 As shown in the illustration, this application embodiment also provides a data storage device 70, which may include: a memory 701 for storing a computer program; and a processor 702 for executing the computer program to implement the method described in any of the above-described methods. The processor 702 can implement the steps of any of the methods described above, which will not be repeated here.

[0155] It should be noted that the data storage device and data storage method provided in the above embodiments belong to the same concept, and their specific implementation process can be found in the method embodiments, which will not be repeated here.

[0156] Of course, in practical applications, such as Figure 7 As shown, the data storage device 70 may further include at least one network interface 703. The various components in the data storage device are coupled together via a bus system 704. It is understood that the bus system 704 is used to implement communication between these components. In addition to a data bus, the bus system 704 also includes a power bus, a control bus, and a status signal bus. However, for clarity, in... Figure 7Various buses are labeled as bus system 704. The number of processors 702 can be at least one. Network interface 703 is used for wired or wireless communication between the data storage device and other devices. Memory 701 in this embodiment is used to store various types of data to support the operation of the data storage device. The methods disclosed in the above embodiments can be applied to processor 702, or implemented by processor 702. Processor 702 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by integrated logic circuits in the hardware of processor 702 or by instructions in software form. The processor 702 can be a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Processor 702 can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. A general-purpose processor can be a microprocessor or any conventional processor, etc. The steps of the methods disclosed in the embodiments of this application can be directly reflected in the combined execution of hardware and software modules in a microcontroller. The software module can reside in a storage medium located in memory 701. Processor 702 reads information from memory 701 and, in conjunction with its hardware, completes the steps of the aforementioned method. In an exemplary embodiment, the data storage device 70 can be implemented by one or more application-specific integrated circuits (ASICs), DSPs, programmable logic devices (PLDs), complex programmable logic devices (CPLDs), field-programmable gate arrays (FPGAs), general-purpose processors, controllers, microcontrollers (MCUs), microprocessors, or other electronic components to execute the aforementioned method.

[0157] Specifically, embodiments of this application provide a computer-readable storage medium storing a computer program thereon, such as a memory 701 storing the computer program, which can be executed by a processor 702 to complete the steps described in the aforementioned method. The computer-readable storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, Flash Memory, magnetic surface memory, optical disc, or CD-ROM.

[0158] In addition, each functional unit in the various embodiments of this application can be integrated into one processing unit, or each unit can be a separate unit, or two or more units can be integrated into one unit; the integrated unit can be implemented in hardware or in the form of hardware plus software functional units.

[0159] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0160] Alternatively, if the integrated units described above are implemented as software functional modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, or the parts that contribute to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, ROM, RAM, magnetic disks, or optical disks.

[0161] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the detailed descriptions of other embodiments above, which will not be repeated here.

[0162] The above provides a detailed description of a data storage method, apparatus, device, and storage medium provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, those skilled in the art will recognize that there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

[0163] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

Claims

1. A data storage method applied to a memory comprising at least one sector, characterized in that, The method includes: Determine the storage address corresponding to the data to be stored in the first time period; The first sector corresponding to the data to be stored is determined according to the storage address; the first sector is any sector among the at least one sector whose preset flag is set to invalid. If it is determined that the first sector and the second sector where the stored data of the second time period is written are not the same sector, then the stored data of the first sector is erased to obtain the erased first sector; the second time period is the time period before the first time period. The data to be stored is written to the first sector after erasure.

2. The data storage method according to claim 1, characterized in that, Determining the storage address corresponding to the data to be stored in the first time period includes: The starting address of the data to be stored is determined based on the freeze type of the data to be stored. Obtain the current index of the data to be stored; the current index represents the storage location of the data to be stored in the memory. The storage address of the data to be stored is determined based on the starting address, the current index, and the data length of the data to be stored.

3. The data storage method according to claim 2, characterized in that, The data storage structure of the memory includes storage capacity; the method further includes: If the value of the current index is greater than or equal to the value of the storage capacity, then the third sector where the starting index is located is erased to obtain the erased third sector; the starting index represents the storage location of the first piece of stored data in the memory; Write the data to be stored into the erased third sector; Use the first index of the next adjacent sector after the third sector as the new starting index.

4. The data storage method according to claim 1, characterized in that, The method further includes: In response to a data clearing instruction for data stored in the memory, a preset flag for each sector in the at least one sector is set to an invalid state according to the data clearing instruction.

5. The data storage method according to claim 1, characterized in that, The method further includes: In response to a data rollback command that rolls back the stored data at the first index in the current sector to the stored data at the second index in the target sector; According to the data rollback instruction, if the current sector and the target sector are the same sector, then at least one stored data from the third index to the second index in the target sector is read; the third index is the storage location of the first stored data in the target sector; The target sector is erased to obtain the erased target sector; At least one stored data from the third index to the second index is written to the erased target sector.

6. The data storage method according to claim 5, characterized in that, The method further includes: If the current sector and the target sector are not the same sector, then the preset flag of at least one sector to be rolled back between the current sector, the target sector and the current sector is set to an invalid state.

7. The data storage method according to claim 1, characterized in that, The data storage structure of the memory includes a starting index and a current index, and the method further includes: Obtain the first time corresponding to the starting index, the second time of the current index, and the query time; Based on the starting index, the current index, the first time, the second time, and the first time period, it is determined whether the stored data in the memory is continuous data, and a determination result is obtained; If the judgment result indicates that the stored data in the memory is continuous data, determine the offset of the query time relative to the first time; Based on the starting index and the offset, the query data corresponding to the query time is determined.

8. The data storage method according to claim 7, characterized in that, The method further includes: If the judgment result indicates that the stored data in the memory is discontinuous, the intermediate index and the third time of the intermediate index are determined according to the binary search method, the starting index and the current index; Based on the starting index, the current index, the intermediate index, the first time, the second time, the third time, and the first time period, the system re-determines whether the stored data in the memory is continuous data, until the determination result indicates that the stored data in the memory is continuous data.

9. A data storage device, applied to a memory comprising at least one sector, characterized in that, The device includes: The first determining module is used to determine the storage address corresponding to the data to be stored in the first time period; The second determining module is used to determine the first sector corresponding to the data to be stored based on the storage address; the first sector is any sector among the at least one sector in which a preset flag is set to invalid. The first erasure module is used to erase the stored data in the first sector when it is determined that the first sector and the second sector where the stored data is written in the second time period are not the same sector, so as to obtain the erased first sector; the second time period is the time period before the first time period. The first writing module is used to write the data to be stored into the erased first sector.

10. An electronic device, characterized in that, The electronic device includes a processor and a memory, the memory storing a computer program configured to be executed by the processor to implement the method of any one of claims 1 to 8.

11. A computer-readable storage medium, characterized in that, The computer-readable medium stores a computer program that, when executed by a processor, is used to implement the method according to any one of claims 1 to 8.