My question is related to this one: Convert a number range to another range, maintaining ratio.
I have a model, Contest
, which contains many Teams
, which accrue points by doing activities over time. The teams are of different size, and I am calculating a handicap factor for each one, in order to adjust the points relative to the team size:
Team.rb:
def handicap_factor
return (contest.total_users / contest.teams.count.to_f) / self.total_users
end
This returns a decimal value which I multiply against the team's total points to get a weighted points score:
Team.rb:
def adjusted_points
return (points * handicap_factor).ceil
end
Here are some sample handicap factors:
team1.handicap_factor: 1.73125
team2.handicap_factor: 0.6925
team3.handicap_factor: 1.08203125
team4.handicap_factor: 0.721354
Now, I want to convert the range of the handicap factors so that the lowest value is 1 (so that even for the team with the lowest handicap factor, an action results in at least one point), while maintaining the ratio of difference between them.
I am unsure what the correct architecture of this would be between the Contest
and the Team
models. I guess that I could add a method on Contest.rb
to return the multiplication factor required to shift the lowest team.handicap_factor to 1, and then add a method to Team.rb
to multiply team.handicap_factor by this.
Is that a reasonable way to approach this problem? Or, is there a more efficient way of handling this?