/// <summary> /// Converts to <see cref="GradingPercentage"/> object from specified file /// </summary> /// <param name="filename">The filename</param> /// <returns>The <see cref="GradingPercentage"/> object converted from file</returns> private GradingPercentage GetGradingFromXml(string filename) { // Create result object to return at the end var result = new GradingPercentage { // Set default values Name = Path.GetFileNameWithoutExtension(filename), IsMarkAIncluded = false, }; // Get the list of mark nodes var markNodeList = GetNodeListByNameFromFile(filename, "Mark"); // Loop each node for mark info foreach (XmlNode node in markNodeList) { // Get mark attributes var mark = (Marks)Enum.Parse(typeof(Marks), node.ChildNodes.Item(0).InnerText); var topLimit = int.Parse(node.ChildNodes.Item(1).InnerText); var bottomLimit = int.Parse(node.ChildNodes.Item(2).InnerText); // Add them to result object result.UpdateMark(mark, topLimit, bottomLimit); // Check if mark A should be included if (mark == Marks.A) { result.IsMarkAIncluded = true; } } // Finally return the result object return(result); }
/// <summary> /// Converts values in points to percentage values /// </summary> /// <returns>New grading with value in percentage</returns> public static GradingPercentage ConvertToPercentage(this GradingPoints Grades) { var result = new GradingPercentage(); var bottom = 0; var top = 0; var maxPoints = 0; if (Grades.IsMarkAIncluded) { maxPoints = Grades.MarkA.TopLimit; top = PointsToPercent(Grades.MarkA.TopLimit, maxPoints); bottom = PointsToPercent(Grades.MarkA.BottomLimit, maxPoints); result.UpdateMark(Marks.A, top, bottom); result.IsMarkAIncluded = true; } else { result.IsMarkAIncluded = false; maxPoints = Grades.MarkB.TopLimit; } top = PointsToPercent(Grades.MarkB.TopLimit, maxPoints); bottom = PointsToPercent(Grades.MarkB.BottomLimit, maxPoints); result.UpdateMark(Marks.B, top, bottom); top = bottom - 1; bottom = PointsToPercent(Grades.MarkC.BottomLimit, maxPoints); result.UpdateMark(Marks.C, top, bottom); top = bottom - 1; bottom = PointsToPercent(Grades.MarkD.BottomLimit, maxPoints); result.UpdateMark(Marks.D, top, bottom); top = bottom - 1; bottom = PointsToPercent(Grades.MarkE.BottomLimit, maxPoints); result.UpdateMark(Marks.E, top, bottom); top = bottom - 1; bottom = PointsToPercent(Grades.MarkF.BottomLimit, maxPoints); result.UpdateMark(Marks.F, top, bottom); return(result); }