Hi Monks,
I'm having a very hard time with the execution of weighting. In my code, I have multiple users, but only 2 of them (in this case) have a weighting. Drew, should get half (.5) of the work of the other non-weighted users...And Tim should get double the work. I'm not getting my desired result. Tim ends up getting a lot more than double the work.
#!/usr/bin/env perl my %user_weight = (DREW => .5, TIM => 2,); my $roundup; my $tot_per_user; my $tot_events; my $tot_users; undef %userMax4type; my @tmp; my $tmp=0; my $weight_tot=0; my %USERS; while (<DATA>) { # Stuff data into Hash and get count of total events and users my $aref = [split]; $USERS{$aref->[0]} = $aref->[1]; $tot_events += $aref->[1]; $tot_users++; } foreach ( keys %USERS ) { #check if a User has an assigned weight and perform calculatio +n if ( exists($user_weight{$_}) ) { $tot_per_user = $tot_events/$tot_users * $user_weight{ +$_}; $roundup=sprintf("%.0f", $tot_per_user); print "roundup for $_ is: $roundup\n"; $weight_tot += $roundup; } else { #keep track of those users who do not have a weighting push @tmp, $_; $tmp++; } } #perform calculation on non-weighted users foreach (@tmp) { $tot_per_user = ($tot_events-$weight_tot)/$tmp * 1; $roundup=sprintf("%.0f", $tot_per_user); print "roundup for $_ is: $roundup\n"; } __DATA__ TIM 150 JOE 124 JACK 111 KATE 145 DREW 177
Does anyone know of a better way to redistribute work based on a weighting system
any help is much appreciated
thanks
In reply to Weighted Calculation by dirtdog
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |