# HG changeset patch # User Sverre Rabbelier # Date 1236449814 0 # Node ID 9acf4fe1b9bb1e7311e779646f2ee73810ea35ee # Parent 33e34c4716d21ef84b2f0d1733a95d58f75c5d93 Adjust the total_popularity after ranging This way 'off the scale' orgs (many applicants, with only few mentors available) will not pull the total amount of allocated slots down as much as before. Patch by: Sverre Rabbelier diff -r 33e34c4716d2 -r 9acf4fe1b9bb app/soc/logic/allocations.py --- a/app/soc/logic/allocations.py Sat Mar 07 17:55:14 2009 +0000 +++ b/app/soc/logic/allocations.py Sat Mar 07 18:16:54 2009 +0000 @@ -147,6 +147,17 @@ popularity = ((k, len(v)) for k, v in self.applications.iteritems()) self.popularity = dict(popularity) + def rangeSlots(self, slots, org): + """Returns the amount of slots for the org within the required bounds. + """ + + slots = int(math.floor(slots)) + slots = min(slots, self.max_slots_per_org) + slots = max(slots, self.min_slots_per_org) + slots = min(slots, self.mentors[org]) + + return slots + def iterativeAllocation(self): """A simple iterative algorithm. """ @@ -206,9 +217,8 @@ for org in locked_orgs: popularity = self.popularity[org] - mentors = self.mentors[org] slots = locked_slots[org] - slots = min(slots, mentors) + slots = self.rangeSlots(slots, org) total_popularity -= popularity available_slots -= slots @@ -228,14 +238,14 @@ mentors = self.mentors[org] slots = (float(popularity)/float(total_popularity))*available_slots - slots = min(slots, self.max_slots_per_org) - slots = max(slots, self.min_slots_per_org) - slots = min(slots, mentors) + slots = self.rangeSlots(slots, org) popularity = (float(total_popularity)/float(available_slots))*slots self.popularity[org] = popularity + total_popularity = sum(self.popularity.values()) + # do the actual calculation for org in unlocked_orgs: org_applications = self.applications[org] @@ -255,7 +265,10 @@ if slots_left < 1: break - slots_left -= 1 - allocations[org] += 1 + current = allocations[org] + slots = self.rangeSlots(current + 1, org) + + slots_left += slots - current + allocations[org] = slots return allocations diff -r 33e34c4716d2 -r 9acf4fe1b9bb tests/app/soc/logic/test_allocations.py --- a/tests/app/soc/logic/test_allocations.py Sat Mar 07 17:55:14 2009 +0000 +++ b/tests/app/soc/logic/test_allocations.py Sat Mar 07 18:16:54 2009 +0000 @@ -220,7 +220,7 @@ with_adjusting = self.allocater.allocate(locked_slots, adjusted_slots) without_adjusting = self.allocater.allocate(locked_slots, {}) - expected = without_adjusting['gcc'] + 10 + expected = without_adjusting['gcc'] actual = with_adjusting['gcc'] - self.failUnlessEqual(expected, actual) + self.failUnless(actual > expected)