Power grid historical data management method and system
Technical Field
The invention relates to the technical field of power grid information communication, in particular to a power grid historical data management method and a power grid historical data management system.
Background
At present, most of services need to analyze the power grid in real time by analyzing the power grid resources in an operating state. One understanding of the grid is also based on the existing operating grid in the production environment. In the power grid GIS platform, the storage of the power grid resources is only the power grid resources in the existing operation state, does not have the time dynamics for processing data, and only describes the instantaneous state of the data. When data changes, the old data is replaced by the new data, the system becomes another transient state, and the old data does not exist. In today's big data age, the discarding of these old data is undoubtedly a loss of the grid information system.
Disclosure of Invention
The technical problem to be solved by the invention is as follows: the historical data management method and the historical data management system for the power grid are provided, and historical section data at any time point can be quickly inquired.
In order to solve the technical problems, the invention adopts the technical scheme that: a power grid historical data management method comprises the following steps:
creating a base version data table and a corresponding historical data table;
adding a first time field in the base version data table, and adding a second time field and a death field in the historical data table, wherein the first time field is used for recording the time of the latest edition;
if one piece of data in the base data table is edited, recording the piece of data before editing into a historical data table corresponding to the base data table, recording time recorded in a first time field of the piece of data before editing into a second time field corresponding to the piece of data in the historical data table, and writing the editing time of the editing operation into a corresponding extinction field;
if the corresponding base version data table at a time point is required to be inquired, acquiring data of which the time recorded in the first time field is earlier than or equal to the time point from the base version data table;
acquiring data of which the time recorded in the second time field is earlier than or equal to the time point and the time recorded in the death field is later than the time point from a historical data table;
and merging the data acquired from the base data table and the data acquired from the historical data table.
The invention also relates to a power grid historical data management system, which comprises:
the first establishing module is used for establishing a base version data table and a corresponding historical data table;
the adding module is used for adding a first time field in the base version data table, adding a second time field and a death field in the historical data table, and the first time field is used for recording the latest editing time;
the recording module is used for recording the data before editing into a historical data table corresponding to the base data table if the editing operation is carried out on the data in the base data table, recording the time recorded in a first time field of the data before editing into a second time field corresponding to the data in the historical data table, and writing the editing time of the editing operation into a corresponding extinction field;
the first obtaining module is used for obtaining data of which the time recorded in the first time field is earlier than or equal to a time point from the base version data table if the corresponding base version data table at the time point is required to be inquired;
the second acquisition module is used for acquiring data, recorded in the second time field, of which the time is earlier than or equal to the time point and the recorded in the death field is later than the time point from the historical data table;
and the merging module is used for merging the data acquired from the base version data table and the data acquired from the historical data table.
The invention has the beneficial effects that: only the deleted and modified data in the base data table are stored in the historical data table, so that the data quantity of the historical data table can be reduced, and the storage space of the historical data table is saved; the latest editing time is recorded in the base data table, the last editing time and the last editing time of the edited data are recorded in the historical data table, and the historical data are managed based on the data superposition mode of the base data table and the historical data table, so that the historical data at the appointed time point can be accurately extracted, and the effective retention of the historical data is realized.
Drawings
FIG. 1 is a flow chart of a power grid historical data management method of the present invention;
fig. 2 is a schematic diagram of a power grid data flow according to a first embodiment of the present invention;
FIG. 3 is a flowchart of a method according to a first embodiment of the present invention;
FIG. 4 is a flowchart of a method according to a second embodiment of the present invention;
FIG. 5 is a schematic diagram of a power grid historical data management system according to the present invention;
fig. 6 is a schematic structural diagram of a system according to a fourth embodiment of the present invention.
Description of reference numerals:
1. a first creation module; 2. adding a module; 3. a recording module; 4. a first acquisition module;
5. a second acquisition module; 6. a merging module; 7. a second creation module; 8. a correlation module;
31. a first recording unit; 32. a second recording unit; 33. a write unit;
41. a first acquisition unit; 42. a second acquisition unit; 43. and a third acquisition unit.
Detailed Description
In order to explain technical contents, objects and effects of the present invention in detail, the following detailed description is given with reference to the accompanying drawings in conjunction with the embodiments.
The most key concept of the invention is as follows: the history data is managed based on a data superposition manner of the base version data table and the history data table.
Referring to fig. 1, a method for managing historical data of a power grid includes:
creating a base version data table and a corresponding historical data table;
adding a first time field in the base version data table, and adding a second time field and a death field in the historical data table, wherein the first time field is used for recording the time of the latest edition;
if one piece of data in the base data table is edited, recording the piece of data before editing into a historical data table corresponding to the base data table, recording time recorded in a first time field of the piece of data before editing into a second time field corresponding to the piece of data in the historical data table, and writing the editing time of the editing operation into a corresponding extinction field;
if the corresponding base version data table at a time point is required to be inquired, acquiring data of which the time recorded in the first time field is earlier than or equal to the time point from the base version data table;
acquiring data of which the time recorded in the second time field is earlier than or equal to the time point and the time recorded in the death field is later than the time point from a historical data table;
and merging the data acquired from the base data table and the data acquired from the historical data table.
From the above description, the beneficial effects of the present invention are: the data volume of the historical data table can be reduced, the storage space of the historical data table is saved, and the historical section data at any time point can be quickly inquired.
Further, before the step of creating the base version data table and the corresponding history data table, the step of:
and creating a batch number sequence, wherein the batch numbers in the batch number sequence are sequentially ordered from small to large.
Further, after "adding the first time field in the base version data table", the method further includes:
and according to the time sequence of the editing operation, associating the time under the first time field with the batch numbers sequentially taken out from the batch number sequence.
Further, if an edit operation is performed on a piece of data in the base data table, recording the piece of data before editing in a history data table corresponding to the base data table, recording time recorded in a first time field of the piece of data before editing in a second time field corresponding to the piece of data in the history data table, and writing edit time of the edit operation in a corresponding extinction field specifically:
if one data in the base data table is edited, recording the data before editing into a historical data table corresponding to the base data table;
recording the batch number recorded in the first time field of the data before editing into a second time field corresponding to the data in the historical data table;
and writing the batch number corresponding to the editing time of the editing operation into the corresponding extinction field.
Further, if the corresponding base version data table at a time point is to be queried, acquiring data recorded in the first time field from the base version data table, where the time is earlier than or equal to the time point; the specific steps of obtaining, from the historical data table, data that the time recorded in the second time field is earlier than or equal to the time point and the time recorded in the death field is later than the time point are:
if a corresponding base plate data table at a time point needs to be inquired, acquiring a batch number corresponding to the time point;
acquiring data of a batch number recorded in a first time field, which is less than or equal to a batch number corresponding to the time point, from a base data table;
and acquiring data that the batch number recorded in the second time field is less than or equal to the batch number corresponding to the time point and the batch number recorded in the extinction field is greater than the batch number corresponding to the time point from the historical data table.
Further, after the step of obtaining the batch number corresponding to the time point, the method further includes:
and if the time point has no corresponding batch number, acquiring a batch number which is adjacent to the time point and is corresponding to the editing time earlier than the time point from the association relationship between the editing time and the batch number as the batch number corresponding to the time point.
According to the description, the batch numbers sequenced from small to large are used for replacing the editing time, so that the storage space is further saved, and the power grid management personnel can visually know the editing sequence.
Referring to fig. 5, the present invention further provides a power grid historical data management system, including:
the first establishing module is used for establishing a base version data table and a corresponding historical data table;
the adding module is used for adding a first time field in the base version data table, adding a second time field and a death field in the historical data table, and the first time field is used for recording the latest editing time;
the recording module is used for recording the data before editing into a historical data table corresponding to the base data table if the editing operation is carried out on the data in the base data table, recording the time recorded in a first time field of the data before editing into a second time field corresponding to the data in the historical data table, and writing the editing time of the editing operation into a corresponding extinction field;
the first obtaining module is used for obtaining data of which the time recorded in the first time field is earlier than or equal to a time point from the base version data table if the corresponding base version data table at the time point is required to be inquired;
the second acquisition module is used for acquiring data, recorded in the second time field, of which the time is earlier than or equal to the time point and the recorded in the death field is later than the time point from the historical data table;
and the merging module is used for merging the data acquired from the base version data table and the data acquired from the historical data table.
Further, still include:
and the second creating module is used for creating a batch number sequence, and the batch numbers in the batch number sequence are sequentially ordered from small to large.
Further, still include:
and the association module is used for associating the time under the first time field with the batch numbers sequentially taken out from the batch number sequence according to the time sequence of the editing operation.
Further, the recording module includes:
the device comprises a first recording unit, a second recording unit and a third recording unit, wherein the first recording unit is used for recording a piece of data before editing into a historical data table corresponding to a base data table if the editing operation is carried out on the piece of data in the base data table;
the second recording unit is used for recording the batch number recorded in the first time field of the data before editing into a second time field corresponding to the data in the historical data table;
and the writing unit is used for writing the batch number corresponding to the editing time of the editing operation into the corresponding extinction field.
Further, the first obtaining module comprises:
the first obtaining unit is used for obtaining a batch number corresponding to a time point if a corresponding base plate data table at the time point needs to be inquired;
the second obtaining unit is used for obtaining data of the batch number recorded in the first time field, which is less than or equal to the batch number corresponding to the time point, from the base data table;
the second obtaining module is specifically configured to obtain, from the historical data table, data in which the batch number recorded in the second time field is less than or equal to the batch number corresponding to the time point, and the batch number recorded in the extinction field is greater than the batch number corresponding to the time point.
Further, the first obtaining module further includes:
and a third obtaining unit, configured to, if there is no corresponding batch number at the time point, obtain, in the association relationship between the editing time and the batch number, a batch number that is adjacent to the time point and that corresponds to an editing time that is earlier than the time point, as the batch number corresponding to the time point.
Example one
The first embodiment of the invention is as follows: a power grid historical data management method; in the invention, the power grid resource data (including graphic data and equipment ledger data) are stored and managed in three states of an operation state, an editing state and a history state. The three states of the running state, the editing state and the historical state of the power grid resource data are stored by three sets of data tables which are respectively a base plate data table, a version data table and a historical data table.
The operation state is as follows: the current grid rack data, and the ledger data of all equipment, including equipment left in transit, return transit, and on-site.
And (3) editing state: the modification process of the graph and the equipment standing book is managed through a task management mechanism, the graph and the equipment standing book data modified in the tasks are stored in an editing state, and the running state data can be influenced only by modifying the data after the tasks are issued. The editing state plays a role in isolation from the running state, and the controllability, the order and the safety of the change process of the running state resource data are ensured.
History state: the historical state data of the power grid and the equipment account are stored, and the complete change modification process of the data of the power grid and the equipment account is recorded, so that the functions of a power grid GIS multi-temporal version and an equipment account section are realized, and browsing and checking of a historical power grid network frame and the equipment account are realized.
The power grid data flow diagram is shown in fig. 2. The equipment can be edited by the graphical modeling client under the editing state of the GIS through adding or changing the equipment in the planning and construction processes of the power grid. And the change of the equipment enters a version data table of the space-time power grid model, and is verified and released, so that the change of the equipment is transferred from the version data table to a base version data table. The base data table stores the operating state power grid data. In the operation state, the state of the equipment can be directly modified by the specialties of scheduling, marketing, communication and the like, namely the data of the base version data table is changed. Any data change occurring on the base version data table can archive the data before change to the historical data table, and the historical data can be inquired and counted later. When all the equipment data of a certain historical time point are inquired and counted, one part of data is not changed until now, the other part of data is changed in the current base version data table, the past data is stored in the historical data table, and the two parts are combined to obtain all the data of the historical time point.
As shown in fig. 3, the method comprises the steps of:
s1: and creating a base version data table and a corresponding historical data table.
S2: adding a first time field in the base version data table, and adding a second time field and a death field in the historical data table; the first time field is used for recording the time of the latest edition. The structure of the base data table is shown in table 1, and the structure of the history data table is shown in table 2.
TABLE 1
TABLE 2
S3: and if the editing operation is carried out on one data in the base data table, recording the data before editing into a historical data table corresponding to the base data table. It can be seen that the historical data table only records the deleted and modified data in the base version data table, and the historical data table does not record when data is newly added in the base version data table.
S4: recording the time recorded in the first time field of the data before editing into the second time field corresponding to the data in the historical data table, and writing the editing time of the editing operation into the corresponding extinction field. That is, the second time field in the history data table records the last editing time of the data, and the death field records the current editing time, that is, the latest editing time. If one datum in the base data table is edited for multiple times, multiple records are recorded in the historical data table.
S5: and if the corresponding base version data table at a time point is required to be inquired, acquiring the data of which the time recorded in the first time field is earlier than or equal to the time point from the base version data table.
S6: and acquiring data of which the time recorded in the second time field is earlier than or equal to the time point and the time recorded in the death field is later than the time point from the historical data table.
S7: and combining the data acquired from the base plate data table and the data acquired from the historical data table to obtain the base plate data table corresponding to the time point, namely the historical section data of the time point.
In the embodiment, only the deleted and modified data in the base version data table are stored in the historical data table, so that the data volume of the historical data table can be reduced, and the storage space of the historical data table is saved; the latest editing time is recorded in the base data table, the last editing time and the last editing time of the edited data are recorded in the historical data table, and the historical data are managed based on the data superposition mode of the base data table and the historical data table, so that the historical data at the appointed time point can be accurately extracted, and the effective retention of the historical data is realized.
Example two
Referring to fig. 4, the present embodiment is a further development of the first embodiment. If the time is directly recorded, the recorded data is too long, a large storage space needs to be occupied, and for the power grid data, the data needs to be edited frequently, so that the occupied space is further increased, and therefore batch numbers which are ordered from small to large are adopted to replace the editing time, which is specifically described below.
The step S1 is preceded by:
s11: and creating a batch number sequence, wherein the batch numbers in the batch number sequence are sequentially ordered from small to large. Preferably, the sequence of lot numbers may be an increasing natural number sequence, such as 0, 1, 2 … …
The step S2 is followed by:
s22: according to the time sequence of the editing operation, associating the time under the first time field with the batch numbers sequentially taken out from the batch number sequence, and replacing the time recorded under the first time field with the corresponding batch numbers; that is, when editing, the editing time is associated with the sequentially taken lot numbers, and the lot numbers are stored in the association relationship, and then written in the first time field.
The step S4 specifically includes:
s44: recording the batch number recorded in the first time field of the data before editing into a second time field corresponding to the data in the historical data table; and writing the batch number corresponding to the editing time of the editing operation into the corresponding extinction field.
The steps S5-S6 are specifically:
s551: and if the corresponding base plate data table at a time point needs to be inquired, acquiring the batch number corresponding to the time point. Further, if there is no corresponding batch number at the time point, a batch number corresponding to an editing time adjacent to and earlier than the time point is obtained in the association relationship between the editing time and the batch number as the batch number corresponding to the time point.
S552: and acquiring data of the batch number recorded in the first time field, which is less than or equal to the batch number corresponding to the time point, from the base data table.
S66: and acquiring data that the batch number recorded in the second time field is less than or equal to the batch number corresponding to the time point and the batch number recorded in the extinction field is greater than the batch number corresponding to the time point from the historical data table.
According to the embodiment, the batch numbers sequenced from small to large are used for replacing the editing time, so that the storage space is further saved, and the power grid management personnel can visually know the sequence of editing.
EXAMPLE III
The present embodiment is a specific application scenario corresponding to the above embodiment.
Assuming that a base version data table a exists, six new pieces of data are added as shown in table 3, and the corresponding history data table a _ HIS is shown in table 4.
TABLE 3
TABLE 4
If the data with the ID of 3 is modified later, the Fld1 is modified into Fld 1', before the base version data table A is modified, the data with the ID of 3 is copied to the historical data table A _ HIS, the second time field is the data of the first time field before modification, and then the batch number corresponding to the modification time is written into the death field ENDTIMEID; after the copying is completed, the data with the ID of 3 in the base version data table A is modified. After the modification is completed, the base version data table is shown in table 5, and the history data table is shown in table 6.
TABLE 5
TABLE 6
If the data with the ID of 3 and the data with the ID of 4 are deleted later, copying the data with the ID of 3 and the data with the ID of 4 to a historical data table A _ HIS before deleting the base version data table A, and writing the batch number corresponding to the deletion time into a deletion field ENDTIMEID; after the copying is completed, the data with the ID of 3 and the ID of 4 in the base data table a is deleted. After the deletion is completed, the base version data table is shown in table 7, and the history data table is shown in table 8.
TABLE 7
TABLE 8
At this time, if data at the time point corresponding to the batch number 101 is to be searched, data with a TIMEID1 being less than or equal to 101 is searched in the base data table, data with a TIMEID2 being less than or equal to 101and a TIMEID ENDTIMEID being greater than 101 is searched in the historical data table, and the data at the time point can be obtained by superposing and merging the two pieces of data.
Specifically, the SQL statement may be: select id, name, fldname1, …, timeid, … from A where select id1< (101 units all), name, fldname1, …, stated, … from A _ HIS where select 2< (101) and end >101
Example four
Referring to fig. 6, the present embodiment is a power grid historical data management system corresponding to the foregoing embodiment, including:
the first creating module 1 is used for creating a base version data table and a corresponding historical data table;
the adding module 2 is used for adding a first time field in the base version data table, adding a second time field and a death field in the historical data table, wherein the first time field is used for recording the time of the latest edition;
the recording module 3 is configured to record, if an editing operation is performed on data in a base data table, the data before editing into a historical data table corresponding to the base data table, record time recorded in a first time field of the data before editing into a second time field corresponding to the data in the historical data table, and write editing time of the editing operation into a corresponding extinction field;
a first obtaining module 4, configured to obtain, from a base data table, data at a time point when the time recorded in a first time field is earlier than or equal to a time point if a corresponding base data table at the time point is to be queried;
a second obtaining module 5, configured to obtain, from the historical data table, data in which the time recorded in the second time field is earlier than or equal to the time point and the time recorded in the death field is later than the time point;
and the merging module 6 is used for merging the data acquired from the base version data table and the data acquired from the historical data table.
Further, still include:
and the second creating module 7 is used for creating a batch number sequence, and the batch numbers in the batch number sequence are sequentially sorted from small to large.
Further, still include:
and the association module 8 is used for associating the time in the first time field with the batch numbers sequentially taken out from the batch number sequence according to the time sequence of the editing operation.
Further, the recording module 3 includes:
a first recording unit 31, configured to record, if an editing operation is performed on one data in a base data table, the one data before being edited into a history data table corresponding to the base data table;
a second recording unit 32, configured to record the batch number recorded in the first time field of the piece of data before editing into a second time field corresponding to the piece of data in the history data table;
a writing unit 33, configured to write the batch number corresponding to the editing time of the editing operation into the corresponding extinction field.
Further, the first obtaining module 4 includes:
a first obtaining unit 41, configured to obtain a batch number corresponding to a time point if a corresponding base version data table at the time point is to be queried;
a second obtaining unit 42, configured to obtain, from the base data table, data of a batch number recorded in the first time field, which is less than or equal to a batch number corresponding to the time point;
the second obtaining module 5 is specifically configured to obtain, from the historical data table, data in which the batch number recorded in the second time field is less than or equal to the batch number corresponding to the time point, and the batch number recorded in the extinction field is greater than the batch number corresponding to the time point.
Further, the first obtaining module 4 further includes:
a third obtaining unit 43, configured to, if there is no corresponding batch number at the time point, obtain, in the association relationship between the editing time and the batch number, a batch number corresponding to the editing time that is adjacent to and earlier than the time point as the batch number corresponding to the time point.
In summary, according to the power grid historical data management method and the power grid historical data management system, only the deleted and modified data in the base version data table are stored in the historical data table, so that the data amount of the historical data table can be reduced, and the storage space of the historical data table can be saved; the latest editing time is recorded in the base data table, the last editing time and the last editing time of the edited data are recorded in the historical data table, and the historical data are managed based on the data superposition mode of the base data table and the historical data table, so that the historical data at the appointed time point can be accurately extracted, and the effective retention of the historical data is realized. By replacing the editing time with the batch numbers sequenced from small to large, the storage space is further saved, and the power grid management personnel can intuitively know the sequence of editing.
The above description is only an embodiment of the present invention, and not intended to limit the scope of the present invention, and all equivalent changes made by using the contents of the present specification and the drawings, or applied directly or indirectly to the related technical fields, are included in the scope of the present invention.