Drop the 'adjustement' part of slots allocation
authorSverre Rabbelier <srabbelier@gmail.com>
Wed, 08 Apr 2009 22:20:33 +0000
changeset 2130 83f4fab7c556
parent 2129 f6ca1647bff7
child 2131 1d27ec29f1c7
Drop the 'adjustement' part of slots allocation Also cap the max slots at slots_desired (and name it 'max' rather than 'mentors', which is a more accurate name anyway). Patch by: Sverre Rabbelier
app/soc/logic/allocations.py
app/soc/views/models/program.py
tests/app/soc/logic/test_allocations.py
--- a/app/soc/logic/allocations.py	Wed Apr 08 22:20:00 2009 +0000
+++ b/app/soc/logic/allocations.py	Wed Apr 08 22:20:33 2009 +0000
@@ -46,7 +46,7 @@
   # the convenience of any mathematicians that happen to read this
   # piece of code ;).
 
-  def __init__(self, orgs, popularity, mentors, slots,
+  def __init__(self, orgs, popularity, max, slots,
                max_slots_per_org, min_slots_per_org, iterative):
     """Initializes the allocator.
 
@@ -72,10 +72,10 @@
     self.popularity = None
     self.total_popularity = None
     self.initial_popularity = popularity
-    self.mentors = mentors
+    self.max = max
     self.iterative = iterative
 
-  def allocate(self, locked_slots, adjusted_slots):
+  def allocate(self, locked_slots):
     """Allocates the slots and returns the result.
 
     Args:
@@ -84,11 +84,10 @@
     """
 
     self.locked_slots = locked_slots
-    self.adjusted_slots = adjusted_slots
 
     self.buildSets()
 
-    if not sum(self.popularity.values()) or not sum(self.mentors.values()):
+    if not sum(self.popularity.values()) or not sum(self.max.values()):
       return self.popularity
 
     if self.iterative:
@@ -104,37 +103,22 @@
 
     # set s
     locked_slots = self.locked_slots
-    adjusted_slots = self.adjusted_slots
 
     # set a and b
     locked_orgs = set(locked_slots.keys())
-    adjusted_orgs = set(adjusted_slots.keys())
 
     # set a' and b'
     unlocked_orgs = self.orgs.difference(locked_orgs)
 
-    # set a*b and a'*b'
-    locked_and_adjusted_orgs = locked_orgs.intersection(adjusted_orgs)
-
     # a+o and b+o should be o
     locked_orgs_or_orgs = self.orgs.union(locked_orgs)
-    adjusted_orgs_or_orgs = self.orgs.union(adjusted_orgs)
 
     total_popularity = sum(popularity.values())
 
-    # an item can be only a or b, so a*b should be empty
-    if locked_and_adjusted_orgs:
-      raise Error("Cannot have an org locked and adjusted")
-
     # a+o should be o, testing length is enough though
     if len(locked_orgs_or_orgs) != len(self.orgs):
       raise Error("Unknown org as locked slot")
 
-    # same for b+o
-    if len(adjusted_orgs_or_orgs) != len(self.orgs):
-      raise Error("Unknown org as adjusted slot")
-
-    self.adjusted_orgs = adjusted_orgs
     self.unlocked_orgs = unlocked_orgs
     self.locked_orgs = locked_orgs
     self.popularity = popularity
@@ -147,7 +131,7 @@
     slots = int(math.floor(float(slots)))
     slots = min(slots, self.max_slots_per_org)
     slots = max(slots, self.min_slots_per_org)
-    slots = min(slots, self.mentors[org])
+    slots = min(slots, self.max[org])
 
     return slots
 
--- a/app/soc/views/models/program.py	Wed Apr 08 22:20:00 2009 +0000
+++ b/app/soc/views/models/program.py	Wed Apr 08 22:20:33 2009 +0000
@@ -302,27 +302,26 @@
       from_json = simplejson.loads(result)
 
       locked_slots = dicts.groupDictBy(from_json, 'locked', 'slots')
-      adjusted_slots = dicts.groupDictBy(from_json, 'adjustment')
 
     orgs = {}
     applications = {}
-    mentors = {}
+    max = {}
 
     for org in organizations:
       orgs[org.link_id] = org
       applications[org.link_id] = org.nr_applications
-      mentors[org.link_id] = org.nr_mentors
+      max[org.link_id] = min(org.nr_mentors, org.slots_desired)
 
     # TODO: Use configuration variables here
-    max_slots_per_org = 40
+    max_slots_per_org = 50
     min_slots_per_org = 2
     iterative = False
 
-    allocator = allocations.Allocator(orgs.keys(), applications, mentors,
+    allocator = allocations.Allocator(orgs.keys(), applications, max,
                                       program_slots, max_slots_per_org,
                                       min_slots_per_org, iterative)
 
-    result = allocator.allocate(locked_slots, adjusted_slots)
+    result = allocator.allocate(locked_slots)
 
     data = []
 
--- a/tests/app/soc/logic/test_allocations.py	Wed Apr 08 22:20:00 2009 +0000
+++ b/tests/app/soc/logic/test_allocations.py	Wed Apr 08 22:20:33 2009 +0000
@@ -91,59 +91,30 @@
 
     locked_slots = {}
     adjusted_slots = {}
-    self.allocater.allocate(locked_slots, adjusted_slots)
+    self.allocater.allocate(locked_slots)
 
   def testLockedSlotsAllocation(self):
     """Test that an allocation with an org locked does not crash.
     """
 
     locked_slots = {'melange': 3}
-    adjusted_slots = {}
-    self.allocater.allocate(locked_slots, adjusted_slots)
-
-  def testAdjustedSlotsAllocation(self):
-    """Test that an allocation with an org adjusted does not crash.
-    """
-
-    locked_slots = {}
-    adjusted_slots = {'google': -1}
-    self.allocater.allocate(locked_slots, adjusted_slots)
+    self.allocater.allocate(locked_slots)
 
-  def testInvalidSlotsAllocation(self):
-    """Test that an allocation with an org locked and adjusted errors out.
-    """
-
-    locked_slots = {'git': 1}
-    adjusted_slots = {'git': 1}
-    self.failUnlessRaises(allocations.Error, self.allocater.allocate,
-                          locked_slots, adjusted_slots)
-
-  def testNonExistantOrgAllocation1(self):
+  def testNonExistantOrgAllocation(self):
     """Test that locking a non-existing org errors out.
     """
 
     locked_slots = {'gnome': 1}
-    adjusted_slots = {}
     self.failUnlessRaises(allocations.Error, self.allocater.allocate,
-                          locked_slots, adjusted_slots)
-
-  def testNonExistantOrgAllocation2(self):
-    """Test that adjusting a non-existing org errors out.
-    """
-
-    locked_slots = {}
-    adjusted_slots = {'gnome': 1}
-    self.failUnlessRaises(allocations.Error, self.allocater.allocate,
-                          locked_slots, adjusted_slots)
+                          locked_slots)
 
   def testInitialAllocationBelowMaxSlots(self):
     """Test that the initial allocation is below the max slot count.
     """
 
     locked_slots = {}
-    adjusted_slots = {}
 
-    result = self.allocater.allocate(locked_slots, adjusted_slots)
+    result = self.allocater.allocate(locked_slots)
     self.failIf(sum(result.values()) > self.slots)
 
   def testLockedAllocationCorrect(self):
@@ -151,9 +122,8 @@
     """
 
     locked_slots = {'git': 6}
-    adjusted_slots = {}
 
-    result = self.allocater.allocate(locked_slots, adjusted_slots)
+    result = self.allocater.allocate(locked_slots)
 
     expected = 6
     actual = result['git']
@@ -165,26 +135,10 @@
     """
 
     locked_slots = {'git': 20}
-    adjusted_slots = {}
 
-    result = self.allocater.allocate(locked_slots, adjusted_slots)
+    result = self.allocater.allocate(locked_slots)
 
     expected = 6
     actual = result['git']
 
     self.failUnlessEqual(expected, actual)
-
-  def testAdjustedAllocationCorrect(self):
-    """Test that locking an allocation assigns the org the allocation.
-    """
-
-    locked_slots = {}
-    adjusted_slots = {'gcc': 10}
-
-    with_adjusting = self.allocater.allocate(locked_slots, adjusted_slots)
-    without_adjusting = self.allocater.allocate(locked_slots, {})
-
-    expected = without_adjusting['gcc'] + 10
-    actual = with_adjusting['gcc']
-
-    self.failIf(actual < expected, "%d < %d" % (actual, expected))