public CourseWhatIfDomainModel CalcWhatIfGrade(IEnumerable <EvaluationDomainModel> whatIfModels) { var evalSpells = whatIfModels.Select(w => new EvaluationConjureGradeResultModel { EvaluationId = w.Id, EvaluationName = w.Name, PointsEarned = w.PointsEarned, PointsPossibleOverall = w.TotalPointsPossible, WeightAmount = w.Weight }).ToList(); var evalWizard = new EvaluationWizard(); foreach (var spell in evalSpells) { evalWizard.Evaluation = spell; evalWizard.UpdateGradeOverAll(); spell.GradeOverallFriendly = evalWizard.Evaluation.GradeOverallFriendly; } var courseWizard = new CourseWizard(); ICourseResult courseSpell = null; if (evalSpells.Any(es => es.WeightAmount != 1)) { evalSpells = evalSpells.Select(e => new EvaluationConjureGradeResultModel { WeightAmount = e.WeightAmount, Weighted = true, PointsEarned = e.PointsEarned, PointsPossibleOverall = e.PointsPossibleOverall, EvaluationId = e.EvaluationId, EvaluationName = e.EvaluationName, GradeOverallFriendly = e.GradeOverallFriendly }).ToList(); courseSpell = new WeightedCourseResult { Evaluations = evalSpells.ToList() }; courseWizard.Course = courseSpell; courseWizard.UpdateGradeOverall(); courseWizard.UpdateAllGrades(); return(new CourseWhatIfDomainModel { WhatIfGrade = courseWizard.OverallGradeFriendly, WhatIfEvaluations = evalSpells.Select(e => new EvaluationWhatIfDomainModel { EvaluationId = (Guid)e.EvaluationId, EvaluationName = e.EvaluationName, WhatIfGrade = e.GradeOverallFriendly }).ToList() }); } else { courseSpell = new CourseResult { Evaluations = evalSpells.ToList() }; courseWizard.Course = courseSpell; courseWizard.UpdateGradeOverall(); return(new CourseWhatIfDomainModel { WhatIfGrade = courseWizard.OverallGradeFriendly, WhatIfEvaluations = evalSpells.Select(e => new EvaluationWhatIfDomainModel { EvaluationId = (Guid)e.EvaluationId, EvaluationName = e.EvaluationName, WhatIfGrade = e.GradeOverallFriendly }).ToList() }); } }
private void CalculateGrade(CourseEntity course) { var courseWizard = new CourseWizard(); var evalSpells = new List <EvaluationResult>(); var evals = EvaluationService.GetEvaluationsForCourse(course.Id); foreach (var eval in evals) { var castedEval = (EvaluationDomainModel)eval; var weighted = castedEval.Weight != 1; evalSpells.Add(new EvaluationResult { Weighted = weighted, WeightAmount = castedEval.Weight, PointsEarned = castedEval.PointsEarned, GradeToDateRaw = castedEval.CurrentPointsGrade, GradeOverallRaw = castedEval.FinalPointsGrade, PointsPossibleOverall = castedEval.TotalPointsPossible, PointsPossibleToDate = castedEval.CurrentPointsPossible }); } ICourseResult courseSpell = null; if (evalSpells.Any(es => es.Weighted)) { //foreach (var eval in evalSpells) //{ // eval.GradeOverallRaw = // MathApprentice.CalculateRawPercentage(eval.PointsEarned, eval.PointsPossibleOverall); // eval.GradeToDateRaw = // MathApprentice.CalculateRawPercentage(eval.PointsEarned, eval.PointsPossibleToDate); //} courseSpell = new WeightedCourseResult { Evaluations = evalSpells, }; courseWizard.Course = courseSpell; courseWizard.UpdateAllGrades(); var courseResult = (WeightedCourseResult)courseWizard.Course; course.CurrentPointsGrade = courseResult.GradeToDateRaw; course.FinalPointsGrade = courseResult.GradeOverallRaw; } else { courseSpell = new CourseResult { Evaluations = evalSpells }; courseWizard.Course = courseSpell; courseWizard.UpdateAllGrades(); var courseResult = (CourseResult)courseWizard.Course; course.PointsEarned = courseResult.PointsEarned; course.TotalPointsPossible = courseResult.PointsPossibleOverall; course.CurrentPointsPossible = courseResult.PointsPossibleToDate; course.CurrentPointsGrade = courseResult.GradeToDateRaw; course.FinalPointsGrade = courseResult.GradeOverallRaw; } }