Embodiment
Below in conjunction with the accompanying drawing in the embodiment of the present invention, the technical scheme in the embodiment of the present invention is clearly and completely described, obviously, described embodiment is only the present invention's part embodiment, rather than whole embodiment.Based on the embodiment in the present invention, those of ordinary skills belong to the scope of protection of the invention not making the every other embodiment that obtains under the creative work prerequisite.
The embodiment of the present invention provides a kind of method of obtaining online hours in section seclected time, wherein, seclected time, section can be interior any a period of time of time range of state recording table record, can select according to the actual requirements and arbitrarily, as shown in Figure 1, described method comprises:
101, the state record table in traversal described seclected time of section, to obtain with the last time is recorded the record of comparing the generation state variation before, the record of described generation state variation comprises variable condition and transformation period point, and described variable condition is included in line states or broken string state.
Wherein, state record table be put down in writing online or broken string state and with the tables of data of the described online or time point that state that break is corresponding.State record table is just recorded the state of current online or broken string at regular intervals, and when recording current state, state record table also can record time point corresponding to each state.
In this step, travel through the interior state record table of described section seclected time, the state of the online or broken string that namely records in the ergodic state record sheet, thus obtain with the last time is recorded the record of comparing the generation state variation before.
For example, state record table is just recorded current state every 5 milliseconds, being recorded as in one section special time internal state record sheet: online, online, online, online, broken string, broken string.When recording current state, state record table also can record time point corresponding to each state and be respectively t1, t2, t3, t4, t5, t6.The state record table that travels through in this special time compares to obtain with the last record before the record that state variation occurs, and namely gets state broken string corresponding to time point t5 and is variable condition, and time point t5 is the transformation period point.
Concrete, adopt in embodiments of the present invention the storing process of vernier to obtain the record that state variation occurs.Vernier is the ergodic state record sheet in chronological order, in the process of traversal, at first store first state, second state that then will travel through compares with first state that obtains, if state is identical, do not obtain second state, continue the 3rd state of traversal, until traverse the state different from first state, it is retrieved as variable condition, simultaneously the record transformation period point corresponding with variable condition.Certainly, also can adopt the method except the vernier storing process to obtain the record that state variation occurs, to this, the embodiment of the present invention is not construed as limiting.
102, when exist recording of generation state variation described seclected time in section, the time interval sum of the transformation period point that to obtain each described variable condition be the broken string state and regulation reference time point, and the time interval sum put of each described variable condition transformation period point that is presence and described regulation reference time.
Because the time point data can have multiple expression mode, and some expression mode inconvenience directly sums up computing, for example time point data 14: 24: 40 on the 27th September in 2011 and time point data 09: 05: 30 on the 28th September in 2011.Therefore, in the embodiment of the present invention, be provided with regulation reference time point, obtain each time point to the time interval of regulation reference time point, thereby the time point data that can not directly sum up computing be converted into the time interval that facilitates computing.For example, in above-mentioned example, it is 00: 00: 00 on the 27th September in 2011 that regulation reference time point is set, and time point data 14: 24: 40 on the 27th September in 2011 and time point data 09: 05: 30 on the 28th September in 2011 and regulation reference time time interval of putting was respectively 14 hours 24 minutes 40 seconds and 33 hours 05 minute 30 seconds.
Regulation reference time point facilitates the time interval of computing to propose in order to obtain, and can be arbitrary time point, need to prove, in the process of the online hours in obtaining section seclected time, regulation reference time point is changeless.
Preferably, for the time interval that makes acquisition is nonnegative number, described regulation reference time point for any point before described seclected time section or seclected time section start time point.Certainly, also can select in section seclected time or the section seclected time reference time of any point afterwards for stipulating, the embodiment of the present invention does not limit this, also carries out as required the selection of regulation reference time point.
Optionally, adopt the Datediff function to obtain the described time interval in the present embodiment, adopt the Sum function when time interval of obtaining is sued for peace.Certainly, also can adopt as required other functions that can obtain the described time interval or method and can acquisition time other functions or the method for interval sum, the embodiment of the present invention is not construed as limiting this.
103, according to the time interval sum of time interval sum and each described variable condition of described each described variable condition transformation period point that is the broken string state and the regulation reference time point transformation period point that is presence with described regulation reference time point, obtain the interior online hours of described section seclected time.
Concrete, in the method that the embodiment of the present invention provides, described according to the time interval sum of time interval sum and each described variable condition of described each described variable condition transformation period point that is the broken string state and the regulation reference time point transformation period point that is presence with described regulation reference time point, obtain the interior online hours of described section seclected time and comprise:
First variable condition in described seclected time section is broken string, and last variable condition in described seclected time section is during for broken string, obtains online hours T in described seclected time of section by following formula one;
Formula one: T=Toff-(Ton+ST)
First variable condition in described seclected time section is broken string, when last variable condition in described seclected time section is online, obtains online hours T in described seclected time of section by following formula two;
Formula two: T=(Toff+ET)-(Ton+ST)
First variable condition in described seclected time section is online, and last variable condition in described seclected time section is during for broken string, obtains online hours T in described seclected time of section by following formula three;
Formula three: T=Toff-Ton
First variable condition in described seclected time section is online, when last variable condition in described seclected time section is online, obtains online hours T in described seclected time of section by following formula four;
Formula four: T=(Toff+ET)-Ton
Wherein: the time interval sum that Toff put for each described variable condition transformation period point that is the broken string state and regulation reference time; The time interval sum that Ton put for each described variable condition transformation period point that is presence and described regulation reference time; ST be described seclected time section start time point and the time interval of point of described regulation reference time; ET is time interval of termination time point and described regulation reference time point of described seclected time of section.Adopt Datediff function acquisition time interval ST and ET in the present embodiment, also can adopt as required other functions or the method that can obtain the described time interval, the embodiment of the present invention is not construed as limiting this.
The method of obtaining online hours in section seclected time that the embodiment of the present invention provides, by the state record table in traversal section seclected time, only obtain the record that state variation occurs, and obtain online hours in section seclected time according to the time interval sum that the transformation period point of the time interval sum of the transformation period point of each presence in record and regulation reference time point and each broken string state and regulation reference time put.Compared with prior art, do not need every section online hours in the seclected time section are asked respectively duration, can obtain easy, fast the online hours in section seclected time.When particularly being applied in report making software, can be good at utilizing the advantage of SQL aspect summation.Select before section seclected time any point or seclected time section initial reference point be the regulation reference time, making the time interval is nonnegative number, has further simplified the acquisition process of online hours.
Further, the method that provides of the embodiment of the present invention also comprises:
When do not exist recording of generation state variation described seclected time in section:
When the state of the last time record before described seclected time section when being online, obtain online hours in described seclected time of section and be the time span of described seclected time of section;
When the state of described section seclected time the last time record before was broken string, obtaining the interior online hours of described section seclected time was 0.
Do not have the record that state variation occurs seclected time in section, illustrate, be all state online or broken string seclected time in section., illustrate to be presence in section seclected time when being online when the state of the last time record before described seclected time section so, therefore obtain the interior online hours of section seclected time and be the time span of described seclected time of section.And when the state of described section seclected time the last time record before is broken string, the state that is broken string in section seclected time is described, therefore obtaining the interior online hours of section seclected time is 0.
Do not exist in section in seclected time when the recording of state variation occurs, state by the last record before the seclected time section be online or broken string determines that accordingly the state in section seclected time is all online or breaks, and then the online hours that obtain in the seclected time section are the duration or 0 of section seclected time, the online hours in the time of can obtaining easy, fast in the section seclected time existence change records not.
Further, the method that provides in an alternative embodiment of the invention also comprises:
When do not exist recording of generation state variation described seclected time in section:
When the variable condition of the last time before described seclected time section when being online, obtain online hours in described seclected time of section and be the time span of described seclected time of section;
When the variable condition of described section the last time before seclected time was broken string, obtaining the interior online hours of described section seclected time was 0.
Do not have the record that state variation occurs seclected time in section, illustrate, be all state online or broken string seclected time in section., illustrate to be presence in section seclected time when being online when the variable condition of the last time record before described seclected time section so, therefore obtain the interior online hours of section seclected time and be the duration of described seclected time of section.And when the variable condition of described section seclected time the last time record before is broken string, the state that is broken string in section seclected time is described, therefore obtaining the interior online hours of section seclected time is 0.
Do not exist in section in seclected time when the recording of state variation occurs, variable condition by the last record before the seclected time section be online or broken string determines that accordingly the state in section seclected time is all online or breaks, and then the online hours that obtain in the seclected time section are the duration or 0 of section seclected time, the online hours in the time of can obtaining easy, fast in the section seclected time existence change records not.
Optionally, in another embodiment of the present invention, described according to the time interval sum of time interval sum and each described variable condition of described each described variable condition transformation period point that is the broken string state and the regulation reference time point transformation period point that is presence with described regulation reference time point, obtain the interior online hours of described section seclected time and comprise:
Obtain online hours T in described seclected time of section by formula five;
Formula five: T=Toff-Ton
Wherein: the time interval sum that Toff put for each described variable condition transformation period point that is the broken string state and regulation reference time; The time interval sum that Ton put for each described variable condition transformation period point that is presence and described regulation reference time.Adopt Sum function acquisition time interval sum Toff and Ton in the present embodiment.Also can adopt as required other functions or the method that can obtain described time interval sum, this is not construed as limiting.
Longer in time interval that section is crossed over seclected time, when in the seclected time section, the accuracy of online hours is less demanding, the approximation that calculates the interior online hours of section seclected time that the obtain manner of this online hours can be very quick and easy.
Corresponding with said method, the embodiment of the present invention provides a kind of device that obtains online hours in section seclected time, as shown in Figure 2, comprising:
Query unit 21, be used for traveling through the interior state record table of described section seclected time, compare to obtain with the last record before the record that state variation occurs, the record of described generation state variation comprises variable condition and transformation period point, and described variable condition is included in line states or broken string state.
Concrete, query unit 21 adopts the storing process of vernier to obtain the record that state variation occurs in embodiments of the present invention.Vernier is the ergodic state record sheet in chronological order, in the process of traversal, at first store first state, second state that then will travel through compares with first state that obtains, if state is identical, do not obtain second state, continue the 3rd state of traversal, until traverse the state different from first state, it is retrieved as variable condition, simultaneously the record transformation period point corresponding with variable condition.Certainly, query unit 21 also can adopt the method except the vernier storing process to obtain the record that state variation occurs, and to this, the embodiment of the present invention is not construed as limiting.
Acquiring unit 22, be used for when exist recording of generation state variation described seclected time in section, the time interval sum of the transformation period point that to obtain each described variable condition be the broken string state and regulation reference time point, and the time interval sum put of each described variable condition transformation period point that is presence and described regulation reference time.
Preferably, for the time interval that makes acquisition is nonnegative number, described regulation reference time point for any point before described seclected time section or seclected time section start time point.Certainly, also can select in section seclected time or the section seclected time reference time of any point afterwards for stipulating, the embodiment of the present invention does not limit this, also carries out as required the selection of regulation reference time point.
Optionally, adopt the Datediff function to obtain the described time interval in the present embodiment, adopt the Sum function when time interval of obtaining is sued for peace.Certainly, also can adopt as required other functions that can obtain the described time interval or method and can acquisition time other functions or the method for interval sum, the embodiment of the present invention is not construed as limiting this.
Computing unit 23, the time interval sum that the transformation period point that the transformation period point that to be used for according to described each described variable condition be the broken string state and time interval sum and each described variable condition of regulation reference time point are presence and described regulation reference time put is obtained the interior online hours of described section seclected time.
The computing unit 23 of the device that optionally, provides in the embodiment of the present invention specifically is used for:
First variable condition in described seclected time section is broken string, and last variable condition in described seclected time section is during for broken string, obtains online hours T in described seclected time of section by following formula one;
Formula one: T=Toff-(Ton+ST)
First variable condition in described seclected time section is broken string, when last variable condition in described seclected time section is online, obtains online hours T in described seclected time of section by following formula two;
Formula two: T=(Toff+ET)-(Ton+ST)
First variable condition in described seclected time section is online, and last variable condition in described seclected time section is during for broken string, obtains online hours T in described seclected time of section by following formula three;
Formula three: T=Toff-Ton
First variable condition in described seclected time section is online, when last variable condition in described seclected time section is online, obtains online hours T in described seclected time of section by following formula four;
Formula four: T=(Toff+ET)-Ton
Wherein: the time interval sum that Toff put for each described variable condition transformation period point that is the broken string state and regulation reference time; The time interval sum that Ton put for each described variable condition transformation period point that is presence and described regulation reference time; ST be described seclected time section start time point and the time interval of point of described regulation reference time; ET is time interval of termination time point and described regulation reference time point of described seclected time of section.Adopt Datediff function acquisition time interval ST and ET in the present embodiment.Also can adopt as required other functions or the method that can obtain the described time interval, the embodiment of the present invention is not construed as limiting this.
The device that obtains online hours in section seclected time that the embodiment of the present invention provides, by the state record table in query unit 21 traversal sections seclected time, only obtain the record that state variation occurs, the time interval sum put of the transformation period point of the transformation period point of each presence that computing unit 23 obtains according to the acquiring unit 22 in record and the time interval sum of regulation reference time point and each broken string state and regulation reference time is obtained the online hours in section seclected time.Compared with prior art, do not need every section online hours in the seclected time section are asked respectively duration, can obtain easy, fast the online hours in section seclected time.When particularly being applied in report making software, can be good at utilizing the advantage of SQL aspect summation.Select before section seclected time any point or seclected time section start time point be the regulation reference time, making the time interval is nonnegative number, has further simplified the acquisition process of online hours.
Further, the computing unit 23 of the device that provides of the embodiment of the present invention also is used for:
Do not exist in section when the recording of state variation occurs when described seclected time: when the state of the last time record before described seclected time section when being online, obtain online hours in described seclected time of section and be the time span of described seclected time of section; When the state of described section seclected time the last time record before was broken string, obtaining the interior online hours of described section seclected time was 0.
Do not have the record that state variation occurs seclected time in section, illustrate, be all state online or broken string seclected time in section., illustrate to be presence in section seclected time when being online when the state of the last time record before described seclected time section so, therefore obtain the interior online hours of section seclected time and be the time span of described seclected time of section.And when the state of described section seclected time the last time record before is broken string, the state that is broken string in section seclected time is described, therefore obtaining the interior online hours of section seclected time is 0.
Do not exist in section in seclected time when the recording of state variation occurs, state by the last record before the seclected time section be online or broken string determines that accordingly the state in section seclected time is all online or breaks, and then the online hours that computing unit 23 obtains in the seclected time section are the duration or 0 of section seclected time, the online hours in the time of can obtaining easy, fast in the section seclected time existence change records not.
Further, the computing unit 23 of the device that provides of an alternative embodiment of the invention also is used for:
Do not exist in section when the recording of state variation occurs when described seclected time: when the variable condition of the last time before described seclected time section when being online, obtain online hours in described seclected time of section and be the time span of described seclected time of section; When the variable condition of described section the last time before seclected time was broken string, obtaining the interior online hours of described section seclected time was 0.
Do not have the record that state variation occurs seclected time in section, illustrate, be all state online or broken string seclected time in section., illustrate to be presence in section seclected time when being online when the variable condition of the last time record before described seclected time section so, therefore obtain the interior online hours of section seclected time and be the duration of described seclected time of section.And when the variable condition of described section seclected time the last time record before is broken string, the state that is broken string in section seclected time is described, therefore obtaining the interior online hours of section seclected time is 0.
Do not exist in section in seclected time when the recording of state variation occurs, variable condition by the last record before the seclected time section be online or broken string determines that accordingly the state in section seclected time is all online or breaks, and then the online hours that computing unit 23 obtains in the seclected time section are the duration or 0 of section seclected time, the online hours in the time of can obtaining easy, fast in the section seclected time existence change records not.
Optionally, in another embodiment of the present invention, computing unit 23 specifically is used for:
Obtain online hours T in described seclected time of section by formula five;
Formula five: T=Toff-Ton
Wherein: the time interval sum that Toff put for each described variable condition transformation period point that is the broken string state and regulation reference time; The time interval sum that Ton put for each described variable condition transformation period point that is presence and described regulation reference time.Adopt Sum function acquisition time interval sum Toff and Ton in the present embodiment.Also can adopt as required other functions or the method that can obtain described time interval sum, this is not construed as limiting.
Longer in time interval that section is crossed over seclected time, when in the seclected time section, the accuracy of online hours is less demanding, the approximation that calculates the interior online hours of section seclected time that the obtain manner of this online hours can be very quick and easy.
Through the above description of the embodiments, the those skilled in the art can be well understood to the present invention and can realize by the mode that software adds essential common hardware, can certainly pass through hardware, but in a lot of situation, the former is better execution mode.Based on such understanding, the part that technical scheme of the present invention contributes to prior art in essence in other words can embody with the form of software product, this computer software product is stored in the storage medium that can read, floppy disk as computer, hard disk or CD etc., comprise some instructions with so that computer equipment (can be personal computer, server, the perhaps network equipment etc.) carry out the described method of each embodiment of the present invention.
The above; be only the specific embodiment of the present invention, but protection scope of the present invention is not limited to this, anyly is familiar with those skilled in the art in the technical scope that the present invention discloses; can expect easily changing or replacing, within all should being encompassed in protection scope of the present invention.Therefore, protection scope of the present invention should be as the criterion with the protection range of described claim.