<commit_before>//This function is going to take an input of all classes in a semester and all classes taken so far
// and choose x classes to
// attend and return the scheduled classes with these added.
function course(level,courseName,courseNumber, creditHours)
{
    this.courseName = name;
    this.level = level;
    this.courseNumber = courseNumber;
    this.creditHours = creditHours;
    //All of these can be undefined. If a variable is undefined, it is considered to mean
    //Any course of that level. This can be used for the requirements var
}

function restriction(dayOrNight, maxHours){
    this.dayOrNight = dayOrNight;
    this.maxHours = maxHours;
}

function scheduleSemesterClasses(courseLimit, availableCourses, availableStartingIndex, coursesTaken, takenStartingIndex){
    var takenIndex = takenStartingIndex;
    var outList = [];
    for(var availableIndex = availableStartingIndex; availableIndex < availableCourses.length; availableIndex++){
        while( takenIndex < coursesTaken.length && availableCourses[availableIndex].courseNumber > coursesTaken[takenIndex].courseNumber){ // make sure that we are comparing the closest higher course taken next
            takenIndex++;
        }
        if((takenIndex >= coursesTaken.length || coursesTaken.length == 0 || coursesTaken[takenIndex].courseNumber != availableCourses[availableIndex].courseNumber) && courseLimit == 1){
            //if this course hasn't been taken
            outList.push([availableCourses[availableIndex]])
        }else if(takenIndex >= coursesTaken.length || coursesTaken[takenIndex].courseNumber != availableCourses[availableIndex].courseNumber){
            outList = outList.concat(permutate(availableCourses[availableIndex], scheduleSemesterClasses(courseLimit-1, availableCourses, availableIndex+1, coursesTaken, takenIndex)));
        }
    }

    return outList;
}

function permutate(courseToPerm, listToPerm){
    //courseToPerm is an int
    //listToPerm is an Array of Arrays of ints
    var outList = [];
    for(var x =0; x < listToPerm.length; x++){
        outList.push([courseToPerm].concat(listToPerm[x]));
    }

    return outList;
}

//This is the main function of the program
function scheduleAll(totalCourses, coursesPerSemester, coursesAvailable, requirementsIn){

    var requirements = new Object();
    requirements = requirementsIn;
    if(requirements.useTest == true){
        //setting the test. This might not work, but there is basic usage here for all options
        requirements.reqCourse = ["4250","5130"];
        requirements.reqCourse.sort();
        requirements.preReqs = [["4010","5010"]];
        requirements.greaterThan= [[6000, 1], [5000, 6]];
        requirements.coursesPerSemester = [2,1,3];
        requirements.semesterLimit = 10;
        requirements.waived = ["4010"];
        requirements.startDate = [2014, "Fall"];
requirements.preferences = [0, -1];
        requirements.reqCoursePerSemester = [["4250"],["5130"]];
        requirements.minCoursesBase = 3; //No less than 3 courses per semester
        requirements.minCoursesPerSemester = [1,2,3]; // No less than 1 course in the 1st semester Both of these do not count for the final semester
        requirements.restrictCourseBySemester = [[],["4250","5130"], ["4010"]]
    }

    return scheduleAllRecursive(totalCourses, coursesPerSemester, coursesAvailable, [], 0, requirements);
}

function scheduleAllRecursive(totalCourses, coursesPerSemester, coursesAvailable, coursesTaken, currentSemesterIndex, requirements){
    var courseNumberAvailableList = [];
    var courseNumberTakenList = [];
    var seasonList = ["Spring", "Fall"];
    var startDate = [2014, "Fall"];
    if(requirements.startDate != undefined){
        startDate = requirements.startDate;
    }
    var numberOfCoursesToTake = totalCourses;
    var minNumberOfCoursesToTake = 0;

    if(requirements.minCoursesBase != undefined){
        minNumberOfCoursesToTake = requirements.minCoursesBase-1;
    }

    if(requirements.minCoursesPerSemester != undefined && requirements.minCoursesPerSemester[currentSemesterIndex] != undefined){
        minNumberOfCoursesToTake = requirements.minCoursesPerSemester[currentSemesterIndex]-1;
    }

    var potentialSolutions = [];
    potentialSolutions.push([]);

    if(requirements.semesterLimit != undefined && currentSemesterIndex >= requirements.semesterLimit){
        return []; //Do not continue down this branch if we are searching past the semester limit
    }

    if(requirements.waived != undefined && currentSemesterIndex == 0){
        coursesTaken = coursesTaken.concat(numberListToBlankCourseList(requirements.waived));
        numberOfCoursesToTake = numberOfCoursesToTake + requirements.waived.length;
    }

    var semesterIndex = currentSemesterIndex;
    var courseLimitCurrentSemester = coursesPerSemester;

    //--------------------------------------------------------------------------------------------
    //Set unavailable courses. The prereqs aren't filled or you just cant take them this semester
    var unavailableCourses = [];
    unavailableCourses = unavailableCourses.concat(doesntCompletePreReqs(coursesTaken,requirements));

    if(requirements.restrictCourseBySemester != undefined && requirements.restrictCourseBySemester[currentSemesterIndex] != undefined){
     unavailableCourses = unavailableCourses.concat(numberListToBlankCourseList(requirements.restrictCourseBySemester[currentSemesterIndex]));
    }

    //--------------------------------------------------------------------------------------------



    //Set the course upper and lower limits for classes this semester
    //----------------------------------------------------------------------------------------------
    if(requirements.coursesPerSemester != undefined && requirements.coursesPerSemester[currentSemesterIndex] != undefined){
        courseLimitCurrentSemester = requirements.coursesPerSemester[currentSemesterIndex];
    }

    if(coursesTaken.length > 0 && numberOfCoursesToTake-coursesTaken[0].length < courseLimitCurrentSemester){
        courseLimitCurrentSemester = numberOfCoursesToTake-coursesTaken[0].length;
    }


    if(minNumberOfCoursesToTake >= courseLimitCurrentSemester){
        minNumberOfCoursesToTake = courseLimitCurrentSemester-1;
    }
    //----------------------------------------------------------------------------------------------


    //set coursesAvailable list
    courseNumberAvailableList = getCoursesAvailableThisSemester(coursesAvailable, startDate, semesterIndex, seasonList, requirements.preferences);


    if(courseNumberAvailableList.length == 0){
        console.log("Hitting the end of the schedule data. Result will be bound to the dataset.");
    }


    var takenAndNoPreReq =[];
    if(unavailableCourses.length > 0 ){
        takenAndNoPreReq = coursesTaken.concat(unavailableCourses);
        takenAndNoPreReq.sort(function(a,b){
            return parseCourseNumber(a.courseNumber) - parseCourseNumber(b.courseNumber);
        });
    }else{
        takenAndNoPreReq = coursesTaken;
    }

    var solutionPermutationsForIndexY = [];
    for(var numberOfCoursesIndex = courseLimitCurrentSemester; numberOfCoursesIndex > minNumberOfCoursesToTake; numberOfCoursesIndex--){
        var semesterPermOfSameLength = scheduleSemesterClasses(numberOfCoursesIndex, courseNumberAvailableList, 0 , takenAndNoPreReq, 0);
        if(requirements.reqCoursePerSemester != undefined && requirements.reqCoursePerSemester[currentSemesterIndex] != undefined){
            semesterPermOfSameLength = filterRequirements(semesterPermOfSameLength, requirements.reqCoursePerSemester[currentSemesterIndex], semesterPermOfSameLength[0].length);
        }
        solutionPermutationsForIndexY = solutionPermutationsForIndexY.concat(combineTakenAndNew(coursesTaken,semesterPermOfSameLength));
    }
    //FILTER FOR REQ'S HERE ( if solutionPermutationsForIndexY has anything left in it, break, we have a solution)
    //solutionPermutationsForIndexY = filterSemesterRequirements(solutionPermutationsForIndexY, requirements);

    var filteredSolution = filterCurrentBranch(solutionPermutationsForIndexY, requirements, numberOfCoursesToTake); // This is going to return an array of length 2;<commit_msg>New fix on req sorting<commit_after>//This function is going to take an input of all classes in a semester and all classes taken so far
// and choose x classes to
// attend and return the scheduled classes with these added.
function course(level,courseName,courseNumber, creditHours)
{
    this.courseName = name;
    this.level = level;
    this.courseNumber = courseNumber;
    this.creditHours = creditHours;
    //All of these can be undefined. If a variable is undefined, it is considered to mean
    //Any course of that level. This can be used for the requirements var
}

function restriction(dayOrNight, maxHours){
    this.dayOrNight = dayOrNight;
    this.maxHours = maxHours;
}

function scheduleSemesterClasses(courseLimit, availableCourses, availableStartingIndex, coursesTaken, takenStartingIndex){
    var takenIndex = takenStartingIndex;
    var outList = [];
    for(var availableIndex = availableStartingIndex; availableIndex < availableCourses.length; availableIndex++){
        while( takenIndex < coursesTaken.length && availableCourses[availableIndex].courseNumber > coursesTaken[takenIndex].courseNumber){ // make sure that we are comparing the closest higher course taken next
            takenIndex++;
        }
        if((takenIndex >= coursesTaken.length || coursesTaken.length == 0 || coursesTaken[takenIndex].courseNumber != availableCourses[availableIndex].courseNumber) && courseLimit == 1){
            //if this course hasn't been taken
            outList.push([availableCourses[availableIndex]])
        }else if(takenIndex >= coursesTaken.length || coursesTaken[takenIndex].courseNumber != availableCourses[availableIndex].courseNumber){
            outList = outList.concat(permutate(availableCourses[availableIndex], scheduleSemesterClasses(courseLimit-1, availableCourses, availableIndex+1, coursesTaken, takenIndex)));
        }
    }

    return outList;
}

function permutate(courseToPerm, listToPerm){
    //courseToPerm is an int
    //listToPerm is an Array of Arrays of ints
    var outList = [];
    for(var x =0; x < listToPerm.length; x++){
        outList.push([courseToPerm].concat(listToPerm[x]));
    }

    return outList;
}

//This is the main function of the program
function scheduleAll(totalCourses, coursesPerSemester, coursesAvailable, requirementsIn){

    var requirements = new Object();
    requirements = requirementsIn;
    if(requirements.useTest == true){
        //setting the test. This might not work, but there is basic usage here for all options
        requirements.reqCourse = ["4250","5130"];
        requirements.reqCourse.sort();
        requirements.preReqs = [["4010","5010"]];
        requirements.greaterThan= [[6000, 1], [5000, 6]];
        requirements.coursesPerSemester = [2,1,3];
        requirements.semesterLimit = 10;
        requirements.waived = ["4010"];
        requirements.startDate = [2014, "Fall"];
requirements.preferences = [0, -1];
        requirements.reqCoursePerSemester = [["4250"],["5130"]];
        requirements.minCoursesBase = 3; //No less than 3 courses per semester
        requirements.minCoursesPerSemester = [1,2,3]; // No less than 1 course in the 1st semester Both of these do not count for the final semester
        requirements.restrictCourseBySemester = [[],["4250","5130"], ["4010"]]
    }

    return scheduleAllRecursive(totalCourses, coursesPerSemester, coursesAvailable, [], 0, requirements);
}

function scheduleAllRecursive(totalCourses, coursesPerSemester, coursesAvailable, coursesTaken, currentSemesterIndex, requirements){
    var courseNumberAvailableList = [];
    var courseNumberTakenList = [];
    var seasonList = ["Spring", "Fall"];
    var startDate = [2014, "Fall"];
    if(requirements.startDate != undefined){
        startDate = requirements.startDate;
    }
    var numberOfCoursesToTake = totalCourses;
    var minNumberOfCoursesToTake = 0;

    if(requirements.minCoursesBase != undefined){
        minNumberOfCoursesToTake = requirements.minCoursesBase-1;
    }

    if(requirements.minCoursesPerSemester != undefined && requirements.minCoursesPerSemester[currentSemesterIndex] != undefined){
        minNumberOfCoursesToTake = requirements.minCoursesPerSemester[currentSemesterIndex]-1;
    }

    var potentialSolutions = [];
    potentialSolutions.push([]);

    if(requirements.semesterLimit != undefined && currentSemesterIndex >= requirements.semesterLimit){
        return []; //Do not continue down this branch if we are searching past the semester limit
    }

    if(requirements.waived != undefined && currentSemesterIndex == 0){
        coursesTaken = coursesTaken.concat(numberListToBlankCourseList(requirements.waived));
        numberOfCoursesToTake = numberOfCoursesToTake + requirements.waived.length;
    }

    var semesterIndex = currentSemesterIndex;
    var courseLimitCurrentSemester = coursesPerSemester;

    //--------------------------------------------------------------------------------------------
    //Set unavailable courses. The prereqs aren't filled or you just cant take them this semester
    var unavailableCourses = [];
    unavailableCourses = unavailableCourses.concat(doesntCompletePreReqs(coursesTaken,requirements));

    if(requirements.restrictCourseBySemester != undefined && requirements.restrictCourseBySemester[currentSemesterIndex] != undefined){
     unavailableCourses = unavailableCourses.concat(numberListToBlankCourseList(requirements.restrictCourseBySemester[currentSemesterIndex]));
    }

    //--------------------------------------------------------------------------------------------



    //Set the course upper and lower limits for classes this semester
    //----------------------------------------------------------------------------------------------
    if(requirements.coursesPerSemester != undefined && requirements.coursesPerSemester[currentSemesterIndex] != undefined){
        courseLimitCurrentSemester = requirements.coursesPerSemester[currentSemesterIndex];
    }

    if(coursesTaken.length > 0 && numberOfCoursesToTake-coursesTaken[0].length < courseLimitCurrentSemester){
        courseLimitCurrentSemester = numberOfCoursesToTake-coursesTaken[0].length;
    }


    if(minNumberOfCoursesToTake >= courseLimitCurrentSemester){
        minNumberOfCoursesToTake = courseLimitCurrentSemester-1;
    }
    //----------------------------------------------------------------------------------------------


    //set coursesAvailable list
    courseNumberAvailableList = getCoursesAvailableThisSemester(coursesAvailable, startDate, semesterIndex, seasonList, requirements.preferences);


    if(courseNumberAvailableList.length == 0){
        console.log("Hitting the end of the schedule data. Result will be bound to the dataset.");
    }


    var takenAndNoPreReq =[];
    if(unavailableCourses.length > 0 ){
        takenAndNoPreReq = coursesTaken.concat(unavailableCourses);
        takenAndNoPreReq.sort(function(a,b){
            return parseCourseNumber(a.courseNumber) - parseCourseNumber(b.courseNumber);
        });
    }else{
        takenAndNoPreReq = coursesTaken;
    }
    //Semester scheduler assumes sorted inputs
    takenAndNoPreReq = takenAndNoPreReq.sort(function(a,b){
            return parseCourseNumber(a.courseNumber) - parseCourseNumber(b.courseNumber);
        });


    var solutionPermutationsForIndexY = [];
    for(var numberOfCoursesIndex = courseLimitCurrentSemester; numberOfCoursesIndex > minNumberOfCoursesToTake; numberOfCoursesIndex--){
        var semesterPermOfSameLength = scheduleSemesterClasses(numberOfCoursesIndex, courseNumberAvailableList, 0 , takenAndNoPreReq, 0);
        if(requirements.reqCoursePerSemester != undefined && requirements.reqCoursePerSemester[currentSemesterIndex] != undefined){
            semesterPermOfSameLength = filterRequirements(semesterPermOfSameLength, requirements.reqCoursePerSemester[currentSemesterIndex], semesterPermOfSameLength[0].length);
        }
        solutionPermutationsForIndexY = solutionPermutationsForIndexY.concat(combineTakenAndNew(coursesTaken,semesterPermOfSameLength));
    }
    //FILTER FOR REQ'S HERE ( if solutionPermutationsForIndexY has anything left in it, break, we have a solution)
    //solutionPermutationsForIndexY = filterSemesterRequirements(solutionPermutationsForIndexY, requirements);

    var filteredSolution = filterCurrentBranch(solutionPermutationsForIndexY, requirements, numberOfCoursesToTake); // This is going to return an array of length 2;
{'fraction_non_alphanumeric': 0.1321486075496452, 'fraction_numerical': 0.01097262806368895, 'mean_word_length': 3.4565506245017272, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6243712', 'n_tokens_mistral': 4508, 'n_tokens_neox': 4252, 'n_words': 1005}