Commit 3c569066 authored by Chris Reffett's avatar Chris Reffett
Browse files

Re-hack the trajectory generator

parent 8583365b
from mainapp.models import Course # import more from mainapp.models import Course, Semester, Trajectory # import more
### common functionality ### common functionality
...@@ -109,6 +109,7 @@ def requirementsFulfilled(taken, program): ...@@ -109,6 +109,7 @@ def requirementsFulfilled(taken, program):
# this should return true or false # this should return true or false
return fulfilled return fulfilled
#def alreadyTaken(): #def alreadyTaken():
# """ return all of the courses that a student has already taken so far # """ return all of the courses that a student has already taken so far
# in the trajectory """ # in the trajectory """
...@@ -121,7 +122,7 @@ def remainingReqCourses(taken, programCourses): ...@@ -121,7 +122,7 @@ def remainingReqCourses(taken, programCourses):
taken = set(taken) taken = set(taken)
programCourses = set(programCourses) programCourses = set(programCourses)
remainingReqCourses = taken.intersection(programCourses) remainingReqCourses = programCourses.difference(taken)
return remainingReqCourses return remainingReqCourses
...@@ -133,8 +134,8 @@ def nextCourses(remainingReqCourses, taken): ...@@ -133,8 +134,8 @@ def nextCourses(remainingReqCourses, taken):
reqs = set() reqs = set()
for prereq in course.preq: for prereq in course.preq:
reqs.add(prereq) reqs.add(prereq)
for coreq in course.coreq: #for coreq in course.coreq:
reqs.add(coreq) # reqs.add(coreq)
for req in reqs: for req in reqs:
if req in taken: if req in taken:
nextcourses.append(course) nextcourses.append(course)
...@@ -176,6 +177,40 @@ def enoughCredits(previousCourses, numRequired): ...@@ -176,6 +177,40 @@ def enoughCredits(previousCourses, numRequired):
return enoughcredits return enoughcredits
def genTrajectories(taken, programs, user):
tj = Trajectory(user=user, semesters=[])
taken = set(taken)
sem = Semester(number=0, user=user, courses=taken,
programs=programs)
tj.semesters.append(sem)
programCourses = []
for program in programs:
programcourses+=programCourses(program)
remainingCourses=remainingReqCourses(taken, programCourses)
while True:
availableCourses=nextCourses(remainingCourses, taken)
semclasses=[]
for i in xrange(5):
doneclass = availableCourses.pop()
semclasses.append(doneclass)
taken.add(doneclass)
newsem = Semester(number=sem.number+1, user=user, courses=semclasses,
programs=programs)
tj.semesters.append(sem)
sem = newsem
failed=False
for program in programs:
if requirementsFulfilled(program, taken) != program.requirements:
failed=True
if not failed:
break
return tj
'''def generatedTrajectory(taken, programs, user): '''def generatedTrajectory(taken, programs, user):
tj = Trajectory(user=user, semesters=[]) tj = Trajectory(user=user, semesters=[])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment