I'm still not getting it. Technically, I don't even want a static average - if a group is 5,6,7, I'd like to see it the same as 8,10,12,14,16 but probably have the later rank higher based on $distance/$numbers. As it is, I can't even get this to work, so...
use strict; use warnings; use Data::Dumper; my $arr = [ 10, 7, 5, 10, 50, 70, 75, 72, 79, 80 ]; my $avg; foreach my $i ($#$arr) { $avg = ($i + ($avg ? $avg : $i)) / 2; } print "avg [$avg]\n"; @$arr = sort {$a <=> $b} @$arr; my $store; foreach my $i (0 .. $#$arr) { $store->[$i]{num} = $arr->[$i]; $store->[$i]{thresh} = $avg; foreach my $store_i (0 .. $#$store) { if (abs($arr->[$i] - $store->[$store_i]{num}) <= $store->[$i]{thresh}) { push @{$store->[$i]{group}}, $arr->[$i]; } } } print Dumper($store); On Wed, Jul 10, 2013 at 10:31 AM, Jim Gibson <jimsgib...@gmail.com> wrote: > > 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/ > > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/