arrays - Algorithm to count occurance in a consecutive amount of time -
I have a set of data that tells me the current / closed status of a component in the form of time data Looks like:
0 1 120 1 240 0 360 0 480 1 600 1 720 1 840 0 960 0 1080 0 1200 1 1320 1 1440 0 1560 0 1680 1 1800 1 1920 1 < / Code> The first column shows in the second time and the second column displays the position (1 is on, 0 is closed).
I have to know what is 600 seconds with the maximum of 1. For example, in 0-600, 3 × 120s are so 360 seconds where the component is turned on. But in 120-720 there are 4 etc ... This means that it is not only 0-600, 600-1200, it can do any 600 seconds. The hard thing is that it is a cycle, which means that the worst time can be from 1920 to 480 (Note that this cycle 2040 means the time of 2040 is also time 0). The phase of time is not always the same, in this case it is a constant 120, but it can be a mixture of 120 and 150 for example.
The only thing I can think is scan the file from 0-600, the time to check is on 120-720, 240-840 etc. ... but it takes a lot of time. Especially since I can file a lot.
The program is in Perl, but I only need algorithms (if present). Do any one of you know what will be the best way?
Thank you
It is not absolutely clear what value to calculate But your main problem seems to be an algorithm for obtaining samples in each sliding 600 window. Sliding windows can be applied as an array. Finally add new samples and purify the old specimens to keep the old sizes & lt; = 600s is only accounting 2040 for difficult part time values.
Use strict; Use warnings; Use Data: Dump QW (PP); my window; While (my $ line = & lt; data & gt;) {chomp $ line; Mine ($ t, $ current) = partition / + /, $ line; # Add a sample to slide the window pushing windows, {t = & gt; $ T, at = & gt; $ At}; # Segment window size for 600 while (1) {last if @windo600) {# clear old specimen from window shift @window; } Else {last; }} Do something with #WindoPP \ @Wandow; } __DATA__ 0 1 120 1 240 0 360 0 480 1 600 1 720 1 840 0 960 0 1080 0 1200 1 1320 1 1440 0 1560 0 1680 1 1800 1 1920 1 120 1 240 0 360 0
@windowlook like this:# Do not wrap [[on = & gt; 1, t = & gt; 0}, at {on => 1, t = & gt; 120}, {at => 0, t = & gt; 240}, {to = on> 0, t = & gt; 360}, {on = & gt; 1, t = & gt; 480}, {to = on> 1, t = & gt; 600},] # with wrapping [= on & gt; 0, t = & gt; 1560}, {at => 1, t = & gt; 1680}, {at = & gt; 0, t = & gt; 1800}, {at = & gt; 1, t = & gt; 1920}, {to = on> 1, t = & gt; 0}, at {on => 1, t = & gt; 120},]
Comments
Post a Comment