/// <summary> /// Fetches all student grades within an assignment group /// </summary> /// <param name="ssn"></param> /// <param name="assignmentGroupID"></param> /// <returns></returns> public StudentGradeDTO GetStudentGradesInGroup(string ssn, int assignmentGroupID) { // Fetching the student StudentDTO student = _persons.GetStudentBySSN(ssn).GetStudentDTO(); // Fetching the course //CourseInstance course = _courseInstances.GetCourseInstanceByID(courseInstanceID); // Fetching the assignment group AssignmentGroupDTO assignmentGroup = _assignmentGroups.GetAssignmentGroupByID(assignmentGroupID).GetAssignmentGroupDTO(); // Fetching the assignments in the group List <AssignmentDTO> assignments = _assignments.GetGroupAssignments(assignmentGroupID); List <GradeDTO> gradesDTO = (from a in assignments join g in _grades.All().ToList() on a.ID equals g.AssignmentID where student.SSN == g.StudentSSN select new GradeDTO { AssignmentID = g.AssignmentID, GradeValue = g.GradeValue, StudentID = student.ID, AssignmentName = a.Name, StudentSSN = ssn }).ToList(); return(new StudentGradeDTO { Student = student, StudentGrades = gradesDTO }); }
public void CalculateEarnedGroupPercentage() { // Arrange: AssignmentGroupDTO group = new AssignmentGroupDTO { Name = "Hat Hut", CourseInstanceID = 1, Weight = 30, GradedAssignments = 2 }; List <GradeDTO> gradeList = new List <GradeDTO>(); gradeList.Add(new GradeDTO { GradeValue = 10 }); gradeList.Add(new GradeDTO { GradeValue = 0 }); // Act: double groupGrade = _service.CalculateEarnedGroupPercentage(group, gradeList); // Assert: Assert.AreEqual(30 / 2.0 * 0.1, groupGrade); }
/// <summary> /// Fetches a single assignment group by ID /// </summary> /// <param name="assignmentGroupID"></param> /// <returns></returns> public AssignmentGroupDTO GetAssignmentGroup(int assignmentGroupID) { AssignmentGroup result = _assignmentGroups.GetAssignmentGroupByID(assignmentGroupID); AssignmentGroupDTO transObject = result.GetAssignmentGroupDTO(); transObject.Assignments = GetAssignmentsInGroup(assignmentGroupID); return(transObject); }
public void GetAssignmentGroup() { // Arrange: int courseInstanceID = 1; // Act: AssignmentGroupDTO group = _service.GetAssignmentGroup(courseInstanceID); // Assert: Assert.AreEqual("Generic Group 1", group.Name); }
/// <summary> /// Calculates the grade earned in a given group relative to 100% /// </summary> public double CalculateEarnedGroupPercentage(AssignmentGroupDTO group, List <GradeDTO> earnedGrades) { // Sorting the grades List <GradeDTO> sortedGrades = earnedGrades.OrderByDescending(o => o.GradeValue).ToList(); double gradeValues = 0; // Checking the number of graded assignments int graded = (sortedGrades.Count > group.GradedAssignments) ? group.GradedAssignments : sortedGrades.Count; // Going through each group for (int index = 0; index < graded; index++) { gradeValues += (group.Weight * 0.01 / graded) * sortedGrades[index].GradeValue; } return(gradeValues); }
public void AddAssignmentGroup() { // Arrange: AddAssignmentGroupViewModel groupModel = new AddAssignmentGroupViewModel { GradedAssignments = 5, Name = "Another generic group", Weight = 10 }; int courseInstanceID = 1; // Act: AssignmentGroupDTO newGroup = _service.AddAssignmentGroup(courseInstanceID, groupModel); // Assert: Assert.AreEqual(groupModel.Name, newGroup.Name); Assert.AreEqual(groupModel.GradedAssignments, newGroup.GradedAssignments); Assert.AreEqual(groupModel.Weight, newGroup.Weight); }
/// <summary> /// Adds an assignment group to a course instance /// </summary> /// <param name="courseInstanceID"></param> /// <param name="groupData"></param> /// <returns></returns> public AssignmentGroupDTO AddAssignmentGroup(int courseInstanceID, AddAssignmentGroupViewModel groupData) { groupData.ValidateAssignmentGroupVM(); // Fetching the course (throws an error if not found) CourseInstance course = _courseInstances.GetCourseInstanceByID(courseInstanceID); // Fetching the assignments in the group List <AssignmentGroupDTO> courseAssignmentGroups = GetAssignmentGroups(courseInstanceID); // Adding the new group's weight to the list double totalWeight = courseAssignmentGroups.CalculateAssignmentGroupWeight() + groupData.Weight; // Illegal if new group weight goes above the maximum if (totalWeight > 100) { throw new CoursesAPIException(ErrorCodes.ILLEGAL_ASSIGNMENT_GROUP_WEIGHT); } // New group to add AssignmentGroup newGroup = new AssignmentGroup { CourseInstanceID = courseInstanceID, Name = groupData.Name, GradedAssignments = groupData.GradedAssignments, Weight = groupData.Weight }; _assignmentGroups.Add(newGroup); _uow.Save(); AssignmentGroupDTO groupDTO = newGroup.GetAssignmentGroupDTO(); return(groupDTO); }