in reply to Weighted Calculation
I don't understand why you make a case distinction for users with and without weight. Just assume that that users without one have weight 1.
Also I don't understand if there are any constraints related to how work can be redistributed. If not, simply add all the weights (and 1 for unweighted users), divide the total work units by that sum, and then you have the amount of work a "normal" user has to. Scale it by each users's weight to get the work she has to do.
#!/usr/bin/env perl use 5.010; use strict; use warnings; use List::Util qw/sum/; my %user_weight = (DREW => .5, TIM => 2,); my $total_work; while (<DATA>) { my @cols = split; $user_weight{$cols[0]} //= 1; $total_work += $cols[1]; } my $total_weights = sum values %user_weight; my $work_per_unit = $total_work / $total_weights; for my $u (sort keys %user_weight) { printf "%s: %.2f\n", $u, $work_per_unit * $user_weight{$u}; } __DATA__ TIM 150 JOE 124 JACK 111 KATE 145 DREW 177
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Weighted Calculation
by dirtdog (Monk) on May 01, 2014 at 16:35 UTC | |
by Laurent_R (Canon) on May 01, 2014 at 16:39 UTC | |
by moritz (Cardinal) on May 01, 2014 at 17:00 UTC | |
by tye (Sage) on May 01, 2014 at 18:19 UTC | |
by choroba (Cardinal) on May 01, 2014 at 21:15 UTC | |
by Laurent_R (Canon) on May 01, 2014 at 17:17 UTC | |
by dirtdog (Monk) on May 02, 2014 at 00:04 UTC | |
by 2teez (Vicar) on May 01, 2014 at 19:14 UTC | |
by AnomalousMonk (Archbishop) on May 02, 2014 at 00:21 UTC |
In Section
Seekers of Perl Wisdom