Added assigned mentors and amount of minimum slots per org
Patch by: Sverre Rabbelier
--- a/app/soc/logic/allocations.py Sat Mar 07 16:06:30 2009 +0000
+++ b/app/soc/logic/allocations.py Sat Mar 07 17:08:23 2009 +0000
@@ -47,13 +47,17 @@
# the convenience of any mathematicians that happen to read this
# piece of code ;).
- def __init__(self, orgs, applications, slots, max_slots_per_org):
+ def __init__(self, orgs, applications, mentors, slots,
+ max_slots_per_org, min_slots_per_org, iterative):
"""Initializes the allocator.
Args:
orgs: a list of all the orgs that need to be allocated
applications: a dictionary with for each org a list of applicants
+ mentors: the amount of assigned mentors per org
slots: the total amount of available slots
+ max_slots_per_org: how many slots an org should get at most
+ min_slots_per_org: how many slots an org should at least get
"""
all_applications = []
@@ -63,14 +67,17 @@
self.locked_slots = {}
self.adjusted_slots = {}
- self.adjusted_orgss = []
+ self.adjusted_orgs = []
self.locked_orgs = []
self.unlocked_applications = []
self.slots = slots
self.max_slots_per_org = max_slots_per_org
+ self.min_slots_per_org = min_slots_per_org
self.orgs = set(orgs)
self.applications = applications
+ self.mentors = mentors
self.all_applications = set(all_applications)
+ self.iterative = iterative
def allocate(self, locked_slots, adjusted_slots):
"""Allocates the slots and returns the result.
@@ -101,7 +108,7 @@
adjusted_orgs = set(adjusted_slots.keys())
# set a' and b'
- # unlocked_orgs = self.orgs.difference(locked_orgs)
+ unlocked_orgs = self.orgs.difference(locked_orgs)
# unadjusted_orgs = self.orgs.difference(adjusted_orgs)
# set a*b and a'*b'
@@ -129,15 +136,19 @@
locked_applications = set(itertools.chain(*locked_slots.keys()))
unlocked_applications = all_applications.difference(locked_applications)
- self.adjusted_orgss = adjusted_orgs
+ self.adjusted_orgs = adjusted_orgs
+ self.unlocked_orgs = unlocked_orgs
self.locked_orgs = locked_orgs
self.unlocked_applications = unlocked_applications
+ popularity = ((k, len(v)) for k, v in self.applications.iteritems())
+ self.popularity = dict(popularity)
+
def iterativeAllocation(self):
"""A simple iterative algorithm.
"""
- adjusted_orgs = self.adjusted_orgss
+ adjusted_orgs = self.adjusted_orgs
adjusted_slots = self.adjusted_slots
locked_orgs = self.locked_orgs
locked_slots = self.locked_slots
@@ -152,6 +163,7 @@
for org in self.orgs:
org_applications = self.applications[org]
org_applications_count = len(org_applications)
+ mentors = self.mentors[org]
if org in locked_orgs:
slots = locked_slots[org]
@@ -163,7 +175,7 @@
slots += adjusted_slots[org]
slots = min(slots, self.max_slots_per_org)
- slots = min(slots, org_applications_count)
+ slots = min(slots, mentors)
slots = min(slots, available_slots)
allocations[org] = slots
--- a/tests/app/soc/logic/test_allocations.py Sat Mar 07 16:06:30 2009 +0000
+++ b/tests/app/soc/logic/test_allocations.py Sat Mar 07 17:08:23 2009 +0000
@@ -64,22 +64,28 @@
self.slots = 60
self.max_slots_per_org = 40
+ self.min_slots_per_org = 2
self.allocated = 0
+ self.iterative = True
- self.applications = {
- 'asf': self.allocate(20),
- 'gcc': self.allocate(15),
- 'git': self.allocate(6),
- 'google': self.allocate(3),
- 'melange': self.allocate(100),
+ apps = {
+ 'asf': self.allocate(20, 20),
+ 'gcc': self.allocate(15, 30),
+ 'git': self.allocate(6, 6),
+ 'google': self.allocate(3, 10),
+ 'melange': self.allocate(100, 3),
}
+ self.applications = dict([(k,a) for k, (m, a) in apps.iteritems()])
+ self.mentors = dict([(k,m) for k, (m, a) in apps.iteritems()])
+
self.orgs = self.applications.keys()
- self.allocater = allocations.Allocator(self.orgs, self.applications,
- self.slots, self.max_slots_per_org)
+ self.allocater = allocations.Allocator(
+ self.orgs, self.applications, self.mentors, self.slots,
+ self.max_slots_per_org, self.min_slots_per_org, self.iterative)
- def allocate(self, count):
+ def allocate(self, count, max):
"""Returns a list with count new student objects.
"""
@@ -87,7 +93,7 @@
j = i + count
self.allocated += count
- return [Student(i) for i in range(i,j)]
+ return max, [Student(i) for i in range(i,j)]
def testAllocate(self):
"""Test that the allocate helper works properly.
@@ -99,16 +105,19 @@
self.allocated = 0
expected = [Student(0), Student(1), Student(2)]
- actual = self.allocate(3)
+ count, actual = self.allocate(3, 0)
self.failUnlessEqual(expected, actual)
+ self.failUnlessEqual(count, 0)
expected = []
- actual = self.allocate(0)
+ count, actual = self.allocate(0, 10)
self.failUnlessEqual(expected, actual)
+ self.failUnlessEqual(count, 10)
expected = [Student(3)]
- actual = self.allocate(1)
+ count, actual = self.allocate(1, 5)
self.failUnlessEqual(expected, actual)
+ self.failUnlessEqual(count, 5)
self.allocated = stash
@@ -206,12 +215,12 @@
"""
locked_slots = {}
- adjusted_slots = {'google': 1}
+ adjusted_slots = {'gcc': 10}
with_adjusting = self.allocater.allocate(locked_slots, adjusted_slots)
without_adjusting = self.allocater.allocate(locked_slots, {})
- expected = without_adjusting['google'] + 1
- actual = with_adjusting['google']
+ expected = without_adjusting['gcc'] + 10
+ actual = with_adjusting['gcc']
self.failUnlessEqual(expected, actual)