Exemplo n.º 1
0
        public void AutoPopulationTest1()
        {
            //make a mock requirement set
            var reqSets = new List<RequirementSetModel>();
            var csciSet = new RequirementSetModel();

            var csci4440 = new RequirementModel();
            csci4440.CourseFulfillments.Add(new CourseFulfillmentModel("CSCI", "4440"));
            var csci1Xxx = new RequirementModel();
            csci1Xxx.CourseFulfillments.Add(new CourseFulfillmentModel("CSCI", "1xxx"));

            csciSet.Requirements.Add(csci4440);
            csciSet.Requirements.Add(csci1Xxx);

            reqSets.Add(csciSet);

            //fill out courses
            var reader = new StreamReader(File.OpenRead(@"testParser.csv"));
            var input = "";
            while (!reader.EndOfStream)
            {
                input = input + reader.ReadLine() + "\n";
            }
            reader.Close();

            var courses = CsvParserHelper.Parse(input).ToList();

            AutoPopulationHelper.AutoPopulate(reqSets, courses);

            //check results
            Assert.IsTrue(csciSet.AppliedCourses.ElementAt(0).CourseNumber == "4440");
            Assert.IsTrue(csciSet.AppliedCourses.ElementAt(1).CourseNumber == "1100");
            Assert.IsTrue(courses.Count == 3);
        }
Exemplo n.º 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 for course 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)
        {
            using (var entities = GetEntityModel())
            {
                var user = entities.ApplicationUsers.FirstOrDefault(appuser => appuser.Username == username);
                if (user == null) return false;

                var report = user.CAPPReports.FirstOrDefault();
                if (report == null) return false;

                var dbset = report.RequirementSets.FirstOrDefault(set => set.Name == requirementSet.Name);
                if (dbset == null) return false;

                var newCourse =
                    entities.Courses.FirstOrDefault(c => c.CommunicationIntensive == course.CommIntensive &&
                                                         c.Credits == course.Credits &&
                                                         c.Department == course.DepartmentCode &&
                                                         Math.Abs(c.Grade - course.Grade) < 0.01 &&
                                                         c.Number == course.CourseNumber &&
                                                         c.PassNC == course.PassNoCredit &&
                                                         c.Semester == course.Semester &&
                                                         c.RequirementSet.CAPPReport.ApplicationUser
                                                             .Username == username);
                if (newCourse == null) return false;

                newCourse.RequirementSet = dbset;
                entities.SaveChanges();
                return true;
            }
        }
Exemplo n.º 3
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;
                }
            }
        }
Exemplo n.º 4
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);
 }