/// <summary> /// Tries to get the success objectives for a given Success Category. /// </summary> /// <param name="successCategory">Success category to search.</param> /// <param name="objectives">Success objectives found in the search.</param> /// <returns>True if success objectives are found, false otherwise.</returns> public bool tryGetSuccessObjectivesByCategory(SuccessCategory successCategory, out SuccessObjective[] objectives) { if (successCategory != null) { //Objectives found in search List <SuccessObjective> results = new List <SuccessObjective>(); foreach (KeyValuePair <Tuple <SuccessCategory, Semester>, List <SuccessObjective> > objectiveCell in successObjectives) { //Objective cell pertains to the category being searched if (objectiveCell.Key.Item1 == successCategory) { results.AddRange(objectiveCell.Value); } } //Found at least one objective if (results.Count > 0) { objectives = results.ToArray(); return(true); } } objectives = null; return(false); }
/// <summary> /// Adds a success objective to the given SuccessCategory and Semester. /// </summary> /// <param name="successCategory">Success category the objective is in.</param> /// <param name="semester">School semester the objective is in.</param> /// <param name="successObjective">The success objective to add.</param> public void addSuccessObjective(SuccessCategory successCategory, Semester semester, SuccessObjective successObjective) { if (successCategory != null && semester != null && successObjective != null) { //Category not already in the success map, add it if (!successCategories.Contains(successCategory)) { successCategories.Add(successCategory); } //Semester SchoolYear not already in the success map, add it if (!schoolYears.Contains(semester.SchoolYear)) { schoolYears.Add(semester.SchoolYear); } var key = new Tuple <SuccessCategory, Semester>(successCategory, semester); //Key does not exist, create it and instantiate objectives list if (!successObjectives.ContainsKey(key)) { successObjectives.Add(key, new List <SuccessObjective>()); } //Store success objective in collections successObjectives[key].Add(successObjective); allSuccessObjectives.Add(successObjective); } }
/// <summary> /// Adds a success category to the success map. /// </summary> public void addSuccessCategory(SuccessCategory successCategory) { if (successCategory != null) { successCategories.Add(successCategory); } }
/// <summary> /// Adds success objectives to the given SuccessCategory and Semester. /// </summary> /// <param name="successCategory">Success category the objective is in.</param> /// <param name="semester">School semester the objective is in.</param> /// <param name="successObjectives">The success objectives to add.</param> public void addSuccessObjectives(SuccessCategory successCategory, Semester semester, ICollection <SuccessObjective> successObjectives) { if (successCategory != null && semester != null && successObjectives != null) { foreach (SuccessObjective objective in successObjectives) { addSuccessObjective(successCategory, semester, objective); } } }
/// <summary> /// Removes a success objective from the given SuccessCategory and Semester. /// </summary> /// <param name="successCategory">Success category the objective is in.</param> /// <param name="semester">School semester the objective is in.</param> /// <param name="successObjective">The success objective to remove.</param> public bool removeSuccessObjective(SuccessCategory successCategory, Semester semester, SuccessObjective successObjective) { var key = new Tuple <SuccessCategory, Semester>(successCategory, semester); //Key does not exist if (!successObjectives.ContainsKey(key)) { return(false); } //Remove the successObjective from collections allSuccessObjectives.Remove(successObjective); return(successObjectives[key].Remove(successObjective)); }
/// <summary> /// Tries to get the success objectives for the given category and semester. /// </summary> /// <param name="successCategory">Success category to search.</param> /// <param name="semester">Semester to search.</param> /// <param name="objectives">Success objectives found in the search.</param> /// <returns>True if success objectives are found, false otherwise.</returns> public bool tryGetSuccessObjectives(SuccessCategory successCategory, Semester semester, out SuccessObjective[] objectives) { if (successCategory != null && semester != null) { var key = new Tuple <SuccessCategory, Semester>(successCategory, semester); //Key exists if (successObjectives.ContainsKey(key)) { objectives = successObjectives[key].ToArray(); return(true); } } objectives = null; return(false); }
//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); } }
/// <summary> /// Tries to get the student's progress in the given success category as a percentage between 0 and 100. /// </summary> /// <param name="category">Success category to get the progress for.</param> /// <param name="progress">Progress in the success category as a percentage between 0 and 100.</param> /// <returns>True if the category was found in this success map, false otherwise.</returns> public bool tryGetSuccessCategoryProgress(SuccessCategory category, out float progress) { if (category != null) { if (tryGetSuccessObjectivesByCategory(category, out SuccessObjective[] objectives))