Пример #1
0
        //function to autoPopulationulate the HASS requirement set
        public static void FillHass(RequirementSetModel hassReqSet, List<CourseModel> coursesTaken)
        {
            var humDepts = new List<string>
            {
                "IHSS",
                "ARTS",
                "LANG",
                "LITR",
                "COMM",
                "WRIT",
                "STSH",
                "PHIL"
            };
            var ssciDepts = new List<string>
            {
                "COGS",
                "STSS",
                "ECON",
                "PSYC",
                "IHSS",
            };

            //create sorted lists of humanities and ssci courses
            //sorted with highest code first
            var humCourses = new SortedDictionary<int, List<CourseModel>>();
            var ssciCourses = new SortedDictionary<int, List<CourseModel>>();

            foreach (var courseTaken in coursesTaken)
            {
                if (humDepts.Contains(courseTaken.DepartmentCode))
                {
                    var courseNum = CourseNumToInt(courseTaken.CourseNumber);
                    if (humCourses.ContainsKey(courseNum))
                    {
                        humCourses[courseNum].Add(courseTaken);
                    }
                    else
                    {
                        var tempCourse = new List<CourseModel>
                        {
                            courseTaken,
                        };
                        humCourses[courseNum] = tempCourse;
                    }
                }
                else if (ssciDepts.Contains(courseTaken.DepartmentCode))
                {
                    var courseNum = CourseNumToInt(courseTaken.CourseNumber);
                    if (ssciCourses.ContainsKey(courseNum))
                    {
                        ssciCourses[courseNum].Add(courseTaken);
                    }
                    else
                    {
                        var tempCourse = new List<CourseModel>
                        {
                            courseTaken,
                        };
                        ssciCourses[courseNum] = tempCourse;
                    }
                }
            }

            //alternate between adding hum and ssci to HASS
            //until full (or run out of courses, caught below)
            while (!hassReqSet.IsFulfilled())
            {
                if (humCourses.Count > 0)
                {
                    //find the largest course number (last b/c ascending order)
                    var maxCourseList = humCourses.Last().Value;
                    if (maxCourseList.Count == 1)
                    {
                        if (hassReqSet.CanApplyCourse(maxCourseList[0]))
                        {
                            hassReqSet.ApplyCourse(maxCourseList[0]);
                            maxCourseList[0].RequirementSetName = "HASS";
                        }
                        //remove the key from the list of remaining courses
                        humCourses.Remove(humCourses.Last().Key);
                    }
                    else
                    {
                        //apply the first course in the list
                        if (hassReqSet.CanApplyCourse(maxCourseList[0]))
                        {
                            hassReqSet.ApplyCourse(maxCourseList[0]);
                            maxCourseList[0].RequirementSetName = "HASS";
                        }
                        //remove the course from list of remaining courses
                        humCourses.Last().Value.Remove(maxCourseList[0]);
                    }
                }
                if (ssciCourses.Count > 0)
                {
                    //find the largest course number (last b/c ascending order)
                    var maxCourseList = ssciCourses.Last().Value;
                    if (maxCourseList.Count == 1)
                    {
                        if (hassReqSet.CanApplyCourse(maxCourseList[0]))
                        {
                            hassReqSet.ApplyCourse(maxCourseList[0]);
                            maxCourseList[0].RequirementSetName = "HASS";
                        }
                        //remove the key from the list of remaining courses
                        ssciCourses.Remove(ssciCourses.Last().Key);
                    }
                    else
                    {
                        //apply the first course in the list
                        if (hassReqSet.CanApplyCourse(maxCourseList[0]))
                        {
                            hassReqSet.ApplyCourse(maxCourseList[0]);
                            maxCourseList[0].RequirementSetName = "HASS";
                        }
                        //remove the course from list of remaining courses
                        ssciCourses.Last().Value.Remove(maxCourseList[0]);
                    }
                }

                //no more courses to add, you're done
                if ((humCourses.Count == 0 && ssciCourses.Count == 0) || hassReqSet.IsFulfilled())
                {
                    return;
                }
            }
        }
Пример #2
0
 /// <summary>
 ///     Apply a course to a requirement set for a user
 /// </summary>
 /// <param name="username">Username of user to move course for</param>
 /// <param name="course">CourseModel to move</param>
 /// <param name="requirementSet">RequirementSetModel to move course into</param>
 /// <returns>Success status of move</returns>
 public static bool ApplyCourse(string username, CourseModel course, RequirementSetModel requirementSet)
 {
     return requirementSet.CanApplyCourse(course) && EntitiesHelper.ApplyCourse(username, course, requirementSet);
 }