/// <summary>
        /// Gets the success objectives relevant to the current search criteria.
        /// </summary>
        public SuccessObjective[] getRelevantSuccessObjectives(SuccessMap successMap)
        {
            if (this.successMap != successMap)
            {
                init(successMap);
            }

            if (needsUpdate)
            {
                //No classifier filter, only check for search value
                if (ClassifierFilter == SuccessMapSearchFilters.ALL)
                {
                    relevantSuccessObjectives = filteredObjectives[TypeFilter].FindAll(objective =>
                                                                                       objective.Name.Contains(Search)
                                                                                       );
                }
                else //Classifier filter active
                {
                    relevantSuccessObjectives = filteredObjectives[TypeFilter].FindAll(objective =>
                                                                                       objective.Classifier != null &&
                                                                                       objective.Classifier.Classifier == ClassifierFilter &&
                                                                                       objective.Name.Contains(Search)
                                                                                       );
                }
            }

            return(relevantSuccessObjectives.ToArray());
        }
        /// <summary>
        /// Gets a SuccessMap for the given Program.
        /// </summary>
        /// <param name="program">The Program to retrieve a SuccessMap for.</param>
        public Task <SuccessMap> getSuccessMapAsync(Program program)
        {
            //Can't retrieve success map without knowing the program to retrieve from (eventually)
            if (program == null)
            {
                return(null);
            }

            //Return program success map if already retrieved
            //Don't refresh due to low frequency of change
            if (program.successMap != null)
            {
                return(Task.FromResult(program.successMap));
            }

            DatabaseSelect dbSelect        = new DatabaseSelect();
            DataTable      successMapTable = dbSelect.SelectSuccessMap(program.ID);

            //Make sure a success map was retrieved
            if (successMapTable != null && successMapTable.Rows.Count > 0)
            {
                SuccessMap successMap = DataInterpreter.getSuccessMap(successMapTable.Rows[0]);
                program.successMap = successMap;
                return(Task.FromResult(successMap));
            }
            else
            {
                return(null);
            }
        }
Example #3
0
        public static SuccessMap getSuccessMap(DataRow data)
        {
            int    ID   = (int)data["SMID"];
            string name = data["SMName"].ToString();

            SuccessMap successMap = new SuccessMap(ID, name);

            populateSuccessMap(ref successMap);

            return(successMap);
        }
        /// <summary>
        /// Initializes based on the given success map.
        /// </summary>
        private void init(SuccessMap successMap)
        {
            this.successMap = successMap;

            relevantSuccessObjectives = new List <SuccessObjective>();

            filteredObjectives = new Dictionary <string, List <SuccessObjective> >();
            filteredObjectives[SuccessMapSearchFilters.GOAL_AREAS]         = new List <SuccessObjective>();
            filteredObjectives[SuccessMapSearchFilters.PROGRAM_CORE]       = new List <SuccessObjective>();
            filteredObjectives[SuccessMapSearchFilters.ELECTIVES]          = new List <SuccessObjective>();
            filteredObjectives[SuccessMapSearchFilters.SUCCESS_ACTIVITIES] = new List <SuccessObjective>();
            filteredObjectives[SuccessMapSearchFilters.ALL] = new List <SuccessObjective>(successMap.AllSuccessObjectives);

            //Index success objectives according to filter options for quicker searching later
            foreach (SuccessObjective objective in successMap.AllSuccessObjectives)
            {
                if (objective is Course)
                {
                    Course course = (Course)objective;
                    switch (course.Type)
                    {
                    case CourseType.GoalArea:
                        filteredObjectives[SuccessMapSearchFilters.GOAL_AREAS].Add(objective);
                        break;

                    case CourseType.ProgramCore:
                        filteredObjectives[SuccessMapSearchFilters.PROGRAM_CORE].Add(objective);
                        break;

                    case CourseType.Elective:
                        filteredObjectives[SuccessMapSearchFilters.ELECTIVES].Add(objective);
                        break;
                    }
                }
                else if (objective is SuccessActivity)
                {
                    filteredObjectives[SuccessMapSearchFilters.SUCCESS_ACTIVITIES].Add(objective);
                }
            }

            reset();

            needsUpdate = true;
        }
Example #5
0
        //Populates the given success map with the required data.
        private static void populateSuccessMap(ref SuccessMap successMap)
        {
            DatabaseSelect dbSelect = new DatabaseSelect();

            DataTable objectiveMappingsTable = dbSelect.SelectSuccessObjMapSuccessMap(successMap.ID);

            //The success map has success objectives
            if (objectiveMappingsTable != null && objectiveMappingsTable.Rows.Count > 0)
            {
                Dictionary <int, SuccessCategory>            categories  = new Dictionary <int, SuccessCategory>();
                Dictionary <int, SuccessObjectiveClassifier> classifiers = new Dictionary <int, SuccessObjectiveClassifier>();
                Dictionary <int, Semester>   semesters   = new Dictionary <int, Semester>();
                Dictionary <int, SchoolYear> schoolYears = new Dictionary <int, SchoolYear>();

                foreach (DataRow mappingData in objectiveMappingsTable.Rows)
                {
                    string objectiveID = mappingData["ObjID"].ToString();
                    int    semesterID  = (int)mappingData["SemesterID"];
                    int    categoryID  = (int)mappingData["CategoryID"];
                    int    weight      = (int)mappingData["Weight"];

                    //Classifier optional
                    int classifierID;
                    try
                    {
                        classifierID = (int)mappingData["ClassificationID"];

                        //Get success objective classifier if it doesn't already exist
                        if (!classifiers.ContainsKey(classifierID))
                        {
                            DataTable classifierTable = dbSelect.SelectClassifier(classifierID);
                            if (classifierTable != null && classifierTable.Rows.Count > 0) //Classifier exists
                            {
                                classifiers.Add(classifierID, getSuccessObjectiveClassifier(classifierTable.Rows[0]));
                            }
                        }
                    }
                    catch
                    {
                        classifierID = default;
                        Console.WriteLine("Classifier ID not provided for objective: " + objectiveID);
                    }

                    SuccessObjective successObjective = null;

                    //Get success objective
                    DataTable objectiveTable = dbSelect.SelectObjective(objectiveID);
                    if (objectiveTable != null && objectiveTable.Rows.Count > 0) //Objective exists
                    {
                        //Check if objective has a classifier
                        SuccessObjectiveClassifier classifier = classifierID != default ? classifiers[classifierID] : null;
                        successObjective = getSuccessObjective(objectiveTable.Rows[0], weight, classifier);
                    }
                    else
                    {
                        Console.WriteLine("Could not retrieve success objective with ID: " + objectiveID);
                    }

                    //Get success category if it doesn't already exist
                    if (!categories.ContainsKey(categoryID))
                    {
                        DataTable categoryTable = dbSelect.SelectCategory(categoryID);
                        if (categoryTable != null && categoryTable.Rows.Count > 0) //Category exists
                        {
                            categories.Add(categoryID, getSuccessCategory(categoryTable.Rows[0]));
                        }
                        else
                        {
                            Console.WriteLine("Could not retrieve success category with ID: " + categoryID);
                        }
                    }

                    //Get semester if it doesn't already exist
                    if (!semesters.ContainsKey(semesterID))
                    {
                        DataTable semesterTable = dbSelect.SelectSemester(semesterID);
                        if (semesterTable != null && semesterTable.Rows.Count > 0) //Semester exists
                        {
                            int year;
                            semesters.Add(semesterID, getSemester(semesterTable.Rows[0], out year));

                            //Get year if it doesn't already exist
                            if (!schoolYears.ContainsKey(year))
                            {
                                DataTable yearTable = dbSelect.SelectYear(year);
                                if (yearTable != null && yearTable.Rows.Count > 0) //Year exists
                                {
                                    schoolYears.Add(year, getSchoolYear(yearTable.Rows[0]));
                                }
                                else
                                {
                                    Console.WriteLine("Could not retrieve school year with ID: " + year);
                                }
                            }

                            //Add semester to year
                            Semester   semester   = semesters[semesterID];
                            SchoolYear schoolYear = schoolYears[year];
                            semester.SchoolYear = schoolYear;

                            //Associate semester with school year
                            string lowerCaseName = semester.Name.ToLower();
                            if (lowerCaseName.Contains("fall"))
                            {
                                schoolYear.Fall = semester;
                            }
                            else if (lowerCaseName.Contains("spring"))
                            {
                                schoolYear.Spring = semester;
                            }
                            else if (lowerCaseName.Contains("summer"))
                            {
                                schoolYear.Summer = semester;
                            }
                        }
                    }

                    SuccessCategory category          = categories[categoryID];
                    Semester        objectiveSemester = semesters[semesterID];

                    //Add success objective to the success map if all the required data is present
                    if (successObjective != null && category != null && objectiveSemester != null)
                    {
                        successMap.addSuccessObjective(category, objectiveSemester, successObjective);
                    }
                    else
                    {
                        Console.WriteLine("Could not add success objective to success map, missing required data.");
                    }
                }

                //Add classifiers to success map
                successMap.addSuccessObjectiveClassifiers(classifiers.Values);
            }
        }