learning-unlimited/ESP-Website — pull request #327 by pricem (2012-04-05 06:25:10+00:00)
Title: Fast lottery assignment script

This is an attempt at rewriting the lottery assignment script for more consistent behavior and faster performance, inspired by Jordan and Alex Cole. Comments are requested over the next 2 days so we can decide whether to use this code or not for Stanford's lottery over the weekend.

The code does everything locally using numpy arrays. It performs internal consistency and lunch constraint checks, but may benefit from additional checks performed after save_assignments() is called to create StudentRegistrations in the database.

It makes use of a very helpful numpy.random.choice() function, which is unfortunately only available in the development version of numpy. To obtain it, try:
pip uninstall numpy
git clone git://github.com/numpy/numpy.git numpy
cd numpy
python setup.py install

Testing this code on a site with the MIT database would go something like this:
from esp.program.models import Program
from esp.program.controllers.lottery import LotteryAssignmentController
spark = Program.objects.get(id=75)
lac = LotteryAssignmentController(spark)
lac.compute_assignments()
print lac.compute_stats()
lac.save_assignments(debug_display=True)