On Jul 10, 2013, at 5:26 AM, shawn wilson wrote:

> I'm trying to figure out how to group things that occure more
> frequently in a rolling time frame (given a minimum event group). I'd
> like some type of ranking and the medium time.
> 
> So, for instance, if I had something like this:
> $time = [
>    10:00,
>    10:01,
>    10:15,
>    10:10,
>    10:25,
>    10:17,
>    10:09,
>    09:59,
>    09:50,
>    09:15,
>    09:10,
>    09:08,
>    09:05,
> ];
> 
> For a minimum group of 5, should reveal that 9 events happened around
> 10:09 with a max gap of 9 minutes (a group of 4 would return 4 events
> happened 09:09.with a max gap of 9 minutes).
> 
> Probably easiest to return a 13 groups of 1 with the time, 13 groups
> of 2 with the closest partner (09:06, 09:09, 09:09, 09:12....). But
> then when I look for groups of 5 events, I'd get events with 09:50
> skewing the earlier 09:00 times.
> 
> I deal with time in epoch, so any number grouping solution would be
> what I'm looking for.

One approach would be to select a minimum time interval for separating groups. 
Sort the times, and group any times where the difference between successive 
times is less than this interval.

For example, given your sample data, if you select a time interval of :05 and 
require strictly less than (rather than less than or equal to), your groups 
become:

 09:05, 09:08, 09:10
 09:15
 09:50
 09:59, 10:00, 10:01
 10:09, 10:10
 10:15, 10:17
 10:25

If you use less than or equal to, then the groups become:

 09:05, 09:08, 09:10, 09:15
 09:50
 09:59, 10:00, 10:01
 10:09, 10:10, 10:15, 10:17
 10:25


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to