Python comes to rescue again — Electives Allocation

This is a python program for automating — Electives Allocation , based on the time students filled a Google Form. If you want to see the code directly, skip the Background .

Background : I was ready to go to college for one last semester. Since the pressure of getting a job was already over , I was looking forward to enjoy the last leg of my college life.

My college NIT Trichy offers three electives for the last term. After 3.5 years of intense subjects like Digital Signal Processing,Analog electronics and Wireless Communication, eveyone wanted to take a ‘chill’ elective like Marketing or Finance. Alas, the electives had a cap- very few seats were available for the easy courses where professors were gracious with good grades and granting attendance. So to solve this, the class monitors would release a Google form at a said time and we had to fill it. The electives were allocated in ‘preferential time based order’ for the 105 students in my class.

There lied the catch. Everyone had different interpretations of what it meant . When you are allocating three electives in this order, would it mean that the frst one to fill would get all the electives of his/her choosing and the next ones who are a millisecond late would have to put up with all the difficult subjects for the next 5 months? Or would everyone’s first choice would be considered before going to the second choice?The ambiguity remained till the day of choosing.

Everone wanted to get the best electives and were coming up with different strategies — copy pasting roll number to save time on typing, and of course trying to get the Class Rep’s send you the form first. If you had ever booked a Tatkal Ticket on IRCTC (Indian Railway Site), you would understand the frenzy we were in. I had made sure I reached Trichy (from Chennai) before the time the form was released and also triple checked my data connection, courtesy the unreliable hostel Wifi. So just as I was filling, my omnipresent bad luck caused the internet to become slow.Minutes later,The spreadsheet which contained the responses of the form was forwarded. As I watched horrified, I wasn’t allocated even one of my choices while those milliseconds faster than me were given 2 of theirs. Many like me were stranded in the same way and a WhatsApp War ensued in the class group between the two sides for seven hours straight.

https://medium.com/media/3ed77b757e1d363dfb3816b649607d5d/href

Finally some of us were given one of our choices as it was the ‘fair’ way — which again led to a debate on what was ‘Fair’. This led me to think, there must be some solution to solve without ideologies clash and ambiguity. So the best way was to come up with a software to automate the entire process.

The first step would be to create a google form :

Create the form as given in the picture. The names should match in both the form and code . For your own electives , make sure the changes are reflected in the code. Also make sure the options are selected to limit responses to one per colum and mark response required for the questions.

Use the form to gather responses from the students. We’ll be releasing form at a said time and the class would fill it.

Google form lets us view the responses in google spreadsheets. It comes with the timestamp of each form filling, so that’s how we know who filled at what time. We’ll download the responses in the spreadsheet (.xlsx) format and save it in the same folder where are python script is to be . Let us name the spreadsheet as Responses.xlsx .

I learned Python recently and wanted to put it into some use. So here is a solution I came up with. I tried using all the concepts I learned — strings, for loops , lists , dictionaries , plotting , writing into files and working with modules. You can learn from resources like codeacademy and this link.

I configured python by downloading Anaconda distribution . It comes with most of the modules installed. The modules required are xlrd , re, matplotlib.

Save the below code in a file code.py . Understand the code and make changes as you want — you could change the course names , how much electives are to be alloted for each student .

https://medium.com/media/a72c1b6aef11906ca251051b97c674b9/href

Run the code from the anaconda command line with the command

python -m code.py

You can use an IDE like PyCharm if you are more comfortable with it . The code asks you to enter the student capacity of each elective. I entered the following

Music : 5

Finance: 10

VLSI: 15

Satellite Communication: 20

Marketing: 8.

Outputs are stored in results.txt and plots are also generated. The resulting plots are

The result.txt file contains

Final Allocation.
Music allocation is {108114001, 108114004, 108114006, 108114105, 108114010}
Marketing allocation is {108114062, 108114063, 108114032, 108114001, 108114002, 108114004, 108114005, 108114045}
Finance allocation is {108114050, 1081140100, 108114021, 108114023, 108114063, 108114005, 108114103, 108114105, 108114010, 108114015}
VLSI allocation is {108114050, 1081140100, 108114021, 108114023, 108114062, 108114063, 108114032, 108114066, 108114005, 108114006, 108114007, 108114103, 108114075, 108114045, 108114015}
Satellite_communication allocation is {1081140100, 108114023, 108114062, 108114032, 108114066, 108114007, 108114075, 108114045}

So yes, we have written a code to automate the process of electives allocation . I used the concept that starting from the most popular courses, the students are allotted based on who have that course as first priority on the order of who filled it first .If there are seats left after first priorty is over, the students who chose it as second priority would be alloted. It goes till all students are alloted three courses . The fastest one wins here.

Comment your ideas on how this could be solved.


Python comes to rescue again — Electives Allocation was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: