def run(sD): #organize the course info for the user course1 = course.course(clean(sD[3]),sD[4],sD[5],sD[6]) course2 = course.course(clean(sD[7]).lower(),sD[8],sD[9],sD[10]) course3 = course.course(clean(sD[11]).lower(),sD[12],sD[13],sD[14]) course4 = course.course(clean(sD[15]).lower(),sD[16],sD[17],sD[18]) courses = [course1,course2,course3,course4] sem = semester.semester(courses) #get the data from the database students = data_parser.getStudents() courseData = data_parser.getCourses() concentrations = data_parser.getConcentrations() #run the algorithm alg = algorithm.algorithm(sem,sD[0],sD[1],sD[2], sD[19],sD[20],sD[21], students, courseData, concentrations) recs = alg.values() #get a sorted list of the courses by their weights keys = sorted(recs.keys(), reverse=True) #number of courses to return numWanted = 10 totalRecs = 0 #list of recommended courses recList = [] #loop through rec dictionary to get courses for key in keys: if (totalRecs >= numWanted): break else: #check for length in case >1 course has the same value length = len(recs[key]) for i in range(0, length): if (totalRecs >= numWanted): break else: recList.append(recs[key][i]) totalRecs += 1 return recList
def getStudents() : students = [] dump = [] #open the file with open("sample_students.txt") as file: for line in file: currentline = (line.rstrip("\n")).split(","), dump.append(currentline) # go over the rows of the data dump for x in range(len(dump)): #if the current row's first term is 0, #it's a new student so create a new student object if (dump[x][0][0] == "0"): new_semesters = [] # variable to track when to stop adding data to the new student object y = 1 while ((x+y) < len(dump) and dump[x+y][0][0] != "0"): #variable to store courses curCourses = [] #loop over a semester for z in range(int((len(dump[x+y][0]) - 1) / 4)): curCourses.append(course.course(clean(dump[x+y][0][4 * z + 1]), int(dump[x+y][0][4 * z + 2]), int(dump[x+y][0][4 * z + 3]), int(dump[x+y][0][4 * z + 4]))) #add the semester into the array of semesters sem = semester.semester(curCourses) new_semesters.append(sem) y = y + 1 #create a new student object new_student = student.student(dump[x][0][2], new_semesters, dump[x][0][1], "") students.append(new_student) return students
#recList.append(newStuff[newKeys[totalRecs]]) numWanted = 3 for key in newKeys: if (totalRecs >= numWanted): break else: length = len(newStuff[key]) for i in range(0, length): if (totalRecs >= numWanted): break else: recList.append(newStuff[key][i]) totalRecs += 1 #print (recList) courses = ["a","b"] sem = semester.semester(courses) #print (sem.getCourses()) def clean(value): value = value.lower() value = value.replace(" ","") return value value = "A B" print(clean(value))