Ejemplo n.º 1
0
 public StudentPreferenceViewModel(StudentPreference m)
 {
     GaTechId = m.GaTechId;
 }
Ejemplo n.º 2
0
        public HttpResponseMessage StudentPreference(StudentPreference studentPreference)
        {
            using (var ctx = new ApplicationDbContext())
            {
                ctx.StudentPreferences.Where(m => m.GaTechId == studentPreference.GaTechId && m.IsActive).ToList().ForEach(m => m.IsActive = false);

                var ids = studentPreference.Courses.Select(n => n.ID);

                var completed = ctx.CompletedCourses.Where(m => m.GaTechId == studentPreference.GaTechId).Select(m => m.Course_ID);

                studentPreference.Courses = ctx.Courses.Where(m => ids.Contains(m.ID) && !completed.Contains(m.ID)).ToList();

                foreach (var course in studentPreference.Courses)
                {
                    foreach (var prereq in ctx.Courses.Single(m => m.ID == course.ID).Prerequisites)
                    {
                        if (!studentPreference.Courses.Select(m => m.ID).Contains(prereq.ID) && !completed.Contains(prereq.ID))
                        {
                            return Request.CreateErrorResponse(HttpStatusCode.Conflict, String.Format("Missing prerequisite course {0} for {1}", prereq.Number, course.Number));
                       }
                    }
                }

                if (ctx.Students.SingleOrDefault(m => m.GaTechId == studentPreference.GaTechId) == null)
                    ctx.Students.Add(new Student() { GaTechId = studentPreference.GaTechId });

                ctx.StudentPreferences.Add(studentPreference);

                ctx.SaveChanges();

                return Request.CreateResponse(HttpStatusCode.OK);
            }
        }
        /// <summary>
        /// The writeResults class writes the Course Optimization run to the database.  The class takes in the optimization model, all students, all courses, 
        /// all semesters, all course/semster offerings, the dB context, the optimization variable (total slack for overbooked students across all course/
        /// semester offerings, and the RunName provided to the Optimization engine.  
        /// </summary>
        /// <param name="GRBModelData"></param>
        /// <param name="students"></param>
        /// <param name="courses"></param>
        /// <param name="sems"></param>
        /// <param name="crssems"></param>
        /// <param name="ctx"></param>
        /// <param name="ObjectiveValue"></param>
        /// <param name="RunName"></param>
        private static void writeResults(GRBVar[,,] GRBModelData, StudentPreference[] students, Course[] courses, Semester[] sems, CourseSemester[] crssems, ApplicationDbContext ctx, int ObjectiveValue, string RunName)
        {
            Recommendation rec = new Recommendation() { Name = RunName };
            rec.Records = new List<RecommendationRecord>();
            rec.StudentPreferences = students;
            rec.CourseSemesters = crssems;

            rec.MissingSeats = ObjectiveValue;
            for (int i = 0; i < students.Length; i++)
            {
                for (int j = 0; j < courses.Length; j++)
                {
                    for (int k = 0; k < sems.Length; k++)
                    {
                        try
                        {
                            if (GRBModelData[i, j, k].Get(GRB.DoubleAttr.X) == 1)
                                rec.Records.Add(new RecommendationRecord() { StudentPreference = students[i], CourseSemester = crssems.Single(m => m.Course == courses[j] && m.Semester == sems[k]) });
                        }
                        catch (GRBException e)
                        {
                        }
                    }
                }
            }
            ctx.Recommendations.Add(rec);
            ctx.SaveChanges();
        }