Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grade predictor as a library feature #16

Open
VinayGupta23 opened this issue Feb 6, 2016 · 0 comments
Open

Grade predictor as a library feature #16

VinayGupta23 opened this issue Feb 6, 2016 · 0 comments
Assignees

Comments

@VinayGupta23
Copy link
Owner

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants