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
--- 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
--- 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)