On Tue, Dec 1, 2009 at 3:36 PM, David Schmidt <[email protected]> wrote:
[snip]
>
> The actual problem is:
> All the visitors have to be put in one of 4 groups. So for the first
> 10 minutes visitors go to group #1, next 10 minutes to group #2,
> ...when all 4 groups have been treated I want to calculate the new
> "online" times of each group by looking at how many visitors are in
> each one. If a group has very few visitors it gets a bigger share of
> the next 40 minutes and so on.
>
> What I am looking for now is a way to trigger this recalculation code
> after the first 40 minutes. (I am not alternating groups after each
> visitor for another reason)
>
> *** at program start
> my $timeslices = {
>              1 => 10,
>              2 => 10,
>              3 => 10,
>              4 => 10,
> };
>
> *** after 40 minutes, group 1 had the fewest visitors
> my $timeslices = {
>              1 => 5,
>              2 => 10,
>              3 => 10,
>              4 => 15,
> };
> ...and so on


my approach would be something like the following:

my $start =  time;
my $interval = 600;
my %offset = ( 1 => 0, 2 => 0, 3 => 0, 4 => 0 );
my %group = ();

while ( 1==1 ) { # or whatever

    while ( time() < ($start + $interval + $offset{'1'}) ) {
       do_something() && ++$group{'1'};
    }
    while ( time() < ($start + $interval + $offset{'2'}) ) {
       do_something() && ++$group{'2'};
    }
    while ( time() < ($start + $interval + $offset{'3'}) ) {
       do_something() && ++$group{'3'};
    }
    while ( time() < ($start + $interval + $offset{'4'}) ) {
       do_something() && ++$group{'4'};
    }

   reassess_offset();
   %group = ();
   $start = time;

}

HTH,

-- jay
--------------------------------------------------
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.downloadsquad.com  http://www.engatiki.org

values of β will give rise to dom!

--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to