Example #1
0
        /// <summary>
        ///  Calculates the degree result based on the results from each relevant academic year.
        ///  <para>
        ///   This function DOES NOT interpolate missing results.
        ///  </para>
        /// </summary>
        /// <returns>Member of Course.Degree enum</returns>
        public static Course.Degree Degree(List <Tuple <double, double> > yearTwo, List <Tuple <double, double> > yearThree)
        {
            double weightTwo   = yearTwo.Select((Tuple <double, double> i) => i.Item2).Sum();
            double weightThree = yearThree.Select((Tuple <double, double> i) => i.Item2).Sum();

            if ((weightTwo < 1) || (weightThree < 1))
            {
                throw new InvalidParameterException();
            }

            // Rescale if weight < 120
            if (weightTwo < 120)
            {
                yearTwo = CourseCalculationHelper.Rescale(yearTwo, 120);
            }
            if (weightThree < 120)
            {
                yearThree = CourseCalculationHelper.Rescale(yearThree, 120);
            }

            // Replicate modules for each 15 credits
            yearTwo   = CourseCalculationHelper.WeightReplicatedValues(15, yearTwo).Item2;
            yearThree = CourseCalculationHelper.WeightReplicatedValues(15, yearThree).Item2;

            yearThree.Sort(CourseCalculationHelper.ValueWeightTupleSort);
            yearTwo.Add(yearThree[yearThree.Count - 1]);
            yearTwo.Sort(CourseCalculationHelper.ValueWeightTupleSort);

            // Get best 105 credits
            yearTwo   = CourseCalculationHelper.GetApproximateWeight(yearTwo, 105).Item2;
            yearThree = CourseCalculationHelper.GetApproximateWeight(yearThree, 105).Item2;

            double bestLevelSix     = yearThree.Average((Tuple <double, double> i) => i.Item1);
            double bestLevelFiveSix = yearTwo.Average((Tuple <double, double> i) => i.Item1);

            if ((bestLevelSix < 30) || (bestLevelFiveSix < 30))
            {
                return(Course.Degree.Fail);
            }
            if (bestLevelSix >= 70)
            {
                if (bestLevelFiveSix >= 60)
                {
                    return(Course.Degree.FirstClass);
                }
                if (bestLevelFiveSix >= 50)
                {
                    return(Course.Degree.UpperSecondClass);
                }
                if (bestLevelFiveSix >= 40)
                {
                    return(Course.Degree.SecondClass);
                }
                else
                {
                    return(Course.Degree.ThirdClass);
                }
            }
            if (bestLevelSix >= 60)
            {
                if (bestLevelFiveSix >= 50)
                {
                    return(Course.Degree.UpperSecondClass);
                }
                if (bestLevelFiveSix >= 40)
                {
                    return(Course.Degree.SecondClass);
                }
                else
                {
                    return(Course.Degree.ThirdClass);
                }
            }
            if (bestLevelSix >= 50)
            {
                if (bestLevelFiveSix >= 40)
                {
                    return(Course.Degree.SecondClass);
                }
                else
                {
                    return(Course.Degree.ThirdClass);
                }
            }
            if (bestLevelSix >= 40)
            {
                return(Course.Degree.ThirdClass);
            }

            return(Course.Degree.Unknown);
        }