public void SaveGradeScale()
        {
            try
            {
                PagedViewModelWithPopups popupHost;

                if (ShowSaveScalePopupInSeparatePopupPane)
                {
                    // We'll show on a popup layer a level higher, so that the current content is still visible
                    popupHost = MainScreenViewModel.GetPopupViewModelHost();
                }
                else
                {
                    popupHost = GetPopupViewModelHost();
                }

                popupHost.ShowPopup(new SaveGradeScaleViewModel(popupHost, MainScreenViewModel, new SaveGradeScaleViewModel.Parameter()
                {
                    Name    = "",
                    OnSaved = delegate
                    {
                        var dontWait = ReloadSavedGradeScalesPicker();
                    },
                    Scales = GradeScales.ToArray()
                }));
            }

            catch (Exception ex)
            {
                TelemetryExtension.Current?.TrackException(ex);
            }
        }
        private void UpdateSelectedSavedGradeScale()
        {
            try
            {
                var scales = SavedGradeScales;

                if (scales == null)
                {
                    return;
                }

                GradeScale[] curr = GradeScales.ToArray();

                var matching = scales.Where(i => i.GradeScales != null).FirstOrDefault(i => i.GradeScales.SequenceEqual(curr));

                // If no match, we use the Custom (not saved) last item
                if (matching == null)
                {
                    matching = scales.Last();
                }

                if (SelectedSavedGradeScale == matching)
                {
                    return;
                }

                SetSelectedGradeScaleWithoutChangingExistingScales(matching);
            }

            catch { }
        }
Пример #3
0
        protected override BaseItem serialize()
        {
            Class into = new Class()
            {
                CourseNumber             = CourseNumber,
                GradeScales              = GradeScales?.ToArray(),
                ShouldAverageGradeTotals = ShouldAverageGradeTotals,
                Credits           = Credits,
                Position          = Position,
                Color             = Color.FromArgb(255, RawColor[0], RawColor[1], RawColor[2]).ToString(),
                DoesRoundGradesUp = DoesRoundGradesUp
            };

            base.serialize(into);

            return(into);
        }
        private void OnSelectedSavedGradeScaleChanged()
        {
            SavedGradeScale savedScale = SelectedSavedGradeScale;

            if (savedScale == null || savedScale.GradeScales == null)
            {
                return;
            }

            foreach (var s in GradeScales)
            {
                s.PropertyChanged -= GradeScale_PropertyChanged;
            }
            GradeScales.Clear();
            GradeScales.AddRange(savedScale.GradeScales.Select(i => new GradeScale(i.StartGrade, i.GPA)));
            foreach (var s in GradeScales)
            {
                s.PropertyChanged += GradeScale_PropertyChanged;
            }
        }
        public async void Save()
        {
            try
            {
                if (!AreScalesValid())
                {
                    await new PortableMessageDialog(PowerPlannerResources.GetString("String_InvalidGradeScalesMessageBody"), PowerPlannerResources.GetString("String_InvalidGradeScalesMessageHeader")).ShowAsync();
                    return;
                }

                GradeScale[] newScales = GradeScales.ToArray();

                DataChanges changes = new DataChanges();

                // Class changes
                {
                    var c = new DataItemClass()
                    {
                        Identifier = Class.Identifier
                    };

                    c.SetGradeScales(newScales);

                    changes.Add(c);
                }

                TryStartDataOperationAndThenNavigate(delegate
                {
                    return(PowerPlannerApp.Current.SaveChanges(changes));
                }, delegate
                {
                    this.RemoveViewModel();
                });
            }

            catch (Exception ex)
            {
                TelemetryExtension.Current?.TrackException(ex);
                await new PortableMessageDialog("Error encountered while saving. Your error report has been sent to the developer.", "Error").ShowAsync();
            }
        }
Пример #6
0
        protected override void deserialize(BaseItem item, List <PropertyNames> changedProperties)
        {
            Class c     = item as Class;
            Color color = ColorTranslator.FromHtml(c.Color);

            byte[] rawColor = new byte[]
            {
                color.R, color.G, color.B
            };

            if (changedProperties != null)
            {
                if (CourseNumber != c.CourseNumber)
                {
                    changedProperties.Add(PropertyNames.CourseNumber);
                }

                if ((GradeScales == null && c.GradeScales != null) ||
                    (GradeScales != null && c.GradeScales == null) ||
                    (GradeScales != null && c.GradeScales != null && !GradeScales.SequenceEqual(c.GradeScales)))
                {
                    changedProperties.Add(PropertyNames.GradeScales);
                }

                if (ShouldAverageGradeTotals != c.ShouldAverageGradeTotals)
                {
                    changedProperties.Add(PropertyNames.ShouldAverageGradeTotals);
                }

                if (Credits != c.Credits)
                {
                    changedProperties.Add(PropertyNames.Credits);
                }

                if (Position != c.Position)
                {
                    changedProperties.Add(PropertyNames.Position);
                }

                if (!RawColor.SequenceEqual(rawColor))
                {
                    changedProperties.Add(PropertyNames.Color);
                }

                if (DoesRoundGradesUp != c.DoesRoundGradesUp)
                {
                    changedProperties.Add(PropertyNames.DoesRoundGradesUp);
                }
            }

            CourseNumber             = c.CourseNumber;
            GradeScales              = c.GradeScales;
            ShouldAverageGradeTotals = c.ShouldAverageGradeTotals;
            Credits  = c.Credits;
            Position = c.Position;

            RawColor = rawColor;

            DoesRoundGradesUp = c.DoesRoundGradesUp;

            base.deserialize(c, changedProperties);
        }
Пример #7
0
        private void CalculateInternal()
        {
            double totalGrade = 0, totalWeight = 0;

            // GRADE CALCULATION:
            //
            // WEIGHT VALUE  * PERCENT        = FINAL PERCENT (totalGrade is the sum of these percents)
            // 15            * 97%            = 14.55%
            // 30            * 90%            = 27%
            // 55            * 93%            = 51.15%
            // -----------------------------------------------
            // GRADE = (14.55% + 27% + 51.15%) / WEIGHT VALUE TOTAL = 92.7%
            //
            //
            // ALTERNATIVELY:
            //
            // GRADE = SUM(WEIGHT PERCENT * WEIGHT AMOUNT) / WEIGHT AMOUNT TOTAL
            //       = totalGrade                          / totalWeight;

            foreach (WeightCategoryWin w in WeightCategories)
            {
                if (this.ShouldAverageGradeTotals)
                {
                    if (w.WeightAchievedAveraged != PowerPlannerSending.Grade.UNGRADED)
                    {
                        totalGrade  += w.WeightAchievedAveraged;
                        totalWeight += w.WeightValue;
                    }
                }

                else
                {
                    if (w.WeightAchievedSummed != PowerPlannerSending.Grade.UNGRADED)
                    {
                        totalGrade  += w.WeightAchievedSummed;
                        totalWeight += w.WeightValue;
                    }
                }
            }

            //if there was actually a grade
            if (totalWeight != 0)
            {
                this.Grade = totalGrade / totalWeight;
            }
            else
            {
                this.Grade = 1;
            }



            //if they have a custom grade scale
            if (this.GradeScales != null && this.GradeScales.Length != 0)
            {
                //if the grade percents are rounded up
                if (this.DoesRoundGradesUp)
                {
                    int roundedGrade = (int)MyMath.Round(Grade * 100);

                    for (int i = 0; i < GradeScales.Length; i++)
                    {
                        if (roundedGrade >= (GradeScales[i]).StartGrade)
                        {
                            //GradeLetter = (GradeScales[i]).LetterGrade;
                            GPA = (GradeScales[i]).GPA;
                            return;
                        }
                    }
                }

                else
                {
                    for (int i = 0; i < GradeScales.Length; i++)
                    {
                        if (Grade * 100 >= (GradeScales[i]).StartGrade)
                        {
                            //GradeLetter = (GradeScales[i]).LetterGrade;
                            GPA = (GradeScales[i]).GPA;
                            return;
                        }
                    }
                }

                //GradeLetter = GradeScales.Last().LetterGrade;
                GPA = GradeScales.Last().GPA;
            }

            //use default grade scale
            else
            {
                int roundedGrade = MyMath.Round(Grade * 100);

                if (roundedGrade >= 97)
                {
                    GradeLetter = "A+";
                }
                else if (roundedGrade >= 93)
                {
                    GradeLetter = "A";
                }
                else if (roundedGrade >= 90)
                {
                    GradeLetter = "A-";
                }
                else if (roundedGrade >= 87)
                {
                    GradeLetter = "B+";
                }
                else if (roundedGrade >= 83)
                {
                    GradeLetter = "B";
                }
                else if (roundedGrade >= 80)
                {
                    GradeLetter = "B-";
                }
                else if (roundedGrade >= 77)
                {
                    GradeLetter = "C+";
                }
                else if (roundedGrade >= 73)
                {
                    GradeLetter = "C";
                }
                else if (roundedGrade >= 70)
                {
                    GradeLetter = "C-";
                }
                else if (roundedGrade >= 67)
                {
                    GradeLetter = "D+";
                }
                else if (roundedGrade >= 63)
                {
                    GradeLetter = "D";
                }
                else if (roundedGrade >= 60)
                {
                    GradeLetter = "D-";
                }
                else
                {
                    GradeLetter = "F";
                }

                if (roundedGrade >= 90)
                {
                    GPA = 4;
                }
                else if (roundedGrade >= 80)
                {
                    GPA = 3;
                }
                else if (roundedGrade >= 70)
                {
                    GPA = 2;
                }
                else if (roundedGrade >= 60)
                {
                    GPA = 1;
                }
                else
                {
                    GPA = 0;
                }
            }
        }
 public void RemoveGradeScale(GradeScale scale)
 {
     scale.PropertyChanged -= GradeScale_PropertyChanged;
     GradeScales.Remove(scale);
     UpdateSelectedSavedGradeScale();
 }
 public void AddGradeScale()
 {
     GradeScales.Add(new GradeScale());
     GradeScales.Last().PropertyChanged += GradeScale_PropertyChanged;
     UpdateSelectedSavedGradeScale();
 }