VinayGupta23 / VITacademics_Windows

The VITacademics app for the Windows platform.
GNU General Public License v3.0
7 stars 5 forks source link

Grade predictor as a library feature #16

Open VinayGupta23 opened 8 years ago

VinayGupta23 commented 8 years ago

In the file Grade.cs, add a method for grade prediction using the complete grades list.

Class: AcademicHistory For the function, Return expected: GPA, CGPA, Credits completed, total credits (after prediction) Input arguments: List of pairs of (course and grade), current AcademicHistory.

Incorporate all cases such as arrear, re-registration etc. Refer to the code snippet below for suggestions:

private async void CalculateButton_Click(object sender, RoutedEventArgs e)
        {

            double weighedSum = 0;
            ushort normalisingCredits = 0;
            ushort creditsEarnedNow = 0;

            foreach (CourseGradePair cgPair in CourseGradePairs)
            {
                if (!char.IsLetter(cgPair.Grade))
                {
                    // throw exception instead for invalid arguments
                    await new MessageDialog("Please enter grade predictions for all courses to calculate the GPA.", "Missing Inputs").ShowAsync();
                    return;
                }

                if (cgPair.Grade == 'N')
                    continue;
                normalisingCredits += cgPair.Credits;
                if (cgPair.Grade == 'F')
                    continue;
                weighedSum += cgPair.Credits * GetGradePoint(cgPair.Grade);
                creditsEarnedNow += cgPair.Credits;
            }

            ushort creditsRegisteredNow = UserManager.CurrentUser.CoursesMetadata.TotalCredits;
            ushort creditsEarned = GradeHistory.CreditsEarned;
            ushort creditsRegistered = GradeHistory.CreditsRegistered;
            double gpa = weighedSum / normalisingCredits;
            double cgpa = (weighedSum + GradeHistory.Cgpa * creditsRegistered) / (creditsRegistered + creditsRegisteredNow);

            PredictedGpa = gpa.ToString("F2");
            PredictedCgpa = cgpa.ToString("F2");
            PredictedCredits = new ushort[4] { creditsEarnedNow,
                                               creditsRegisteredNow,
                                               (ushort)(creditsEarned + creditsEarnedNow),
                                               (ushort)(creditsRegistered + creditsRegisteredNow) };
        }

        private ushort GetGradePoint(char grade)
        {
            switch(grade)
            {
                case 'S': return 10;
                case 'A': return 9;
                case 'B': return 8;
                case 'C': return 7;
                case 'D': return 6;
                case 'E': return 5;
                default: return 0;
            }
        }

P.S. This code has a few bugs, but anyways can implement this for a first try perhaps.

Also, adhere to the naming conventions as described here!