Skip to content
jhughes edited this page Apr 3, 2013 · 1 revision

Here's how courses are laid out. Each arrow represents a belongs_to relationship.

#!ruby
Semesters -> Courses -> Sections -> Meetings
               \-> Groups ->/

So WTF are groups? Groups are precalculated sets of sections! Each section only belongs to a single group, and can only be scheduled with other sections of the same group. When registering for a course, all your sections must be from the same group, and you must have 1 section from each required section type.

Here's a made up class and its sections:

--BS 125--
A1  - LEC
D1A - DIS
D2A - DIS
L1A - LAB
L2A - LAB

To register for this course you'll have to choose a lecture, discussion, and lab. Simple. Oh wait fuck

--BS 125--
A1  - LEC
D1A - DIS
D2A - DIS
L1A - LAB
L2A - LAB
B1  - LEC
L1B - LBD
L2B - LBD

To register now, you must pick either group A or B. Group A requires the same shit as above, while group B requires a lecture and a lab-discussion combination section. You cannot mix and match between groups A and B.

So my grouping algorithm takes a single section, generates a "group key" (A or B for the above class) for each section, and uses the key to group each section with its friends. Currently this is all precomputed and stored in a table for quick retrieval.

Using Groups

You can make use of the sections_hash and sections_array functions to divide the sections for you.

The hash will divide sections into <section_type, list> entries

The array will divide sections into lists of sections of the same type

#!ruby
Course.get_by_whatever("BS 125").groups
    [<Group id:1, key:"A", course_id:1>, <Group id:2, key:"B", course_id:1>]

Group.first.sections
    [A1, D1A, D2A, L1A, L2A] #(pretend these are real sections)

Group.first.sections_hash
    {"LEC"=>[A1], "DIS"=>[D1A, D2A], "LAB"=>[L1A, L2A]} #(pretend these are real sections)

Group.first.sections_array
    [[A1], [D1A, D2A], [L1A, L2A]] #(pretend these are real sections)

These are handy because you know that you need 1 section from each list to register for a class

Key Generation

The keying algorithm has to be able to handle all the inconsistencies of the school's shitty data when it tries to figure out which sections go together. When I made the algorithm I examined all of the courses and looked for patterns. Right now the algorithm can properly group most courses, but some of the oddballs won't be handled.

Take this course for example:

--BS 225--
ABC - LEC
1   - LEC
ASS - LBD
FUK - LEC
5HT - LAB
XX  - DIS

There's no fucking way to group this shit. Fuck you Tim. Some courses actually look similar to this. I just gave up and ended up manually configuring this shit, but it's just not maintainable -- honestly nothing is -- but it would be better to hard-code it into a script and document it so we can check the same shitty courses again in future years.

Clone this wiki locally