http://qs1969.pair.com?node_id=1084640


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