private async Task<float> GetAverageForType(ApplicationUser student, IEnumerable<WorkItem> workItems, WorkItemType type, GradeDistribution distribution) { var scoreUnitManager = new ScoreUnitManager(_db); var workItemsForType = workItems.Where(wi => wi.Type == type); var PointsForType = MaxPointsForType(type, distribution); // If no WorkItem for the type, return total for that type if(workItemsForType.Count() == 0) { return PointsForType; } bool hasGradedScoreUnit = false; float studentsScores = 0.0f; float total = 0.0f; foreach(var workItem in workItemsForType) { var scoreUnit = await scoreUnitManager.GetStudentScoreUnit(workItem, student); if(scoreUnit != null && scoreUnit.Grade.HasValue) { hasGradedScoreUnit = true; studentsScores += scoreUnit.Grade.Value; total += workItem.MaxPoints; } } // If no ScoreUnit has been graded, return the total for that type if(!hasGradedScoreUnit) { return PointsForType; } return (studentsScores / total) * PointsForType; }
/// <summary> /// Creates a new default ScoreUnitsController /// </summary> public ScoreUnitsController() { _db = new ApplicationDbContext(); _userManager = new ApplicationUserManager(new UserStore<ApplicationUser>(_db)); _scoreUnitManager = new ScoreUnitManager(_db); }