01: /**********************************************************************************
02: *
03: * $Id: CourseGrade.java 21419 2007-02-14 00:11:49Z ray@media.berkeley.edu $
04: *
05: ***********************************************************************************
06: *
07: * Copyright (c) 2005 The Regents of the University of California, The MIT Corporation
08: *
09: * Licensed under the Educational Community License, Version 1.0 (the "License");
10: * you may not use this file except in compliance with the License.
11: * You may obtain a copy of the License at
12: *
13: * http://www.opensource.org/licenses/ecl1.php
14: *
15: * Unless required by applicable law or agreed to in writing, software
16: * distributed under the License is distributed on an "AS IS" BASIS,
17: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18: * See the License for the specific language governing permissions and
19: * limitations under the License.
20: *
21: **********************************************************************************/package org.sakaiproject.tool.gradebook;
22:
23: import java.util.Collection;
24:
25: /**
26: * A CourseGrade is a GradableObject that represents the overall course grade
27: * in a gradebook.
28: *
29: * @author <a href="mailto:jholtzman@berkeley.edu">Josh Holtzman </a>
30: */
31: public class CourseGrade extends GradableObject {
32: // Should only be used to fill in the DB column.
33: private static final String COURSE_GRADE_NAME = "Course Grade";
34:
35: public static String SORT_BY_OVERRIDE_GRADE = "override";
36: public static String SORT_BY_CALCULATED_GRADE = "autoCalc";
37: public static String SORT_BY_POINTS_EARNED = "pointsEarned";
38:
39: public CourseGrade() {
40: setName(COURSE_GRADE_NAME);
41: }
42:
43: /**
44: * @see org.sakaiproject.tool.gradebook.GradableObject#isCourseGrade()
45: */
46: public boolean isCourseGrade() {
47: return true;
48: }
49:
50: //// Bean getters and setters ////
51:
52: /**
53: * Calculate the mean course grade (whether entered or calulated) as a
54: * percentage for all enrollments, counting null grades as zero, but leaving
55: * students who've explicitly been given non-percentage-valued manual-only
56: * course grades (such as "I" for incomplete) out of the calculation.
57: */
58: public void calculateStatistics(
59: Collection<CourseGradeRecord> gradeRecords,
60: int numEnrollments) {
61: // Ungraded but enrolled students count as if they have 0% in the course.
62: int numScored = numEnrollments - gradeRecords.size();
63: double total = 0;
64:
65: for (CourseGradeRecord record : gradeRecords) {
66: Double score = record.getGradeAsPercentage();
67:
68: // Skip manual-only course grades.
69: if ((record.getEnteredGrade() != null) && (score == null)) {
70: continue;
71: }
72:
73: if (score != null) {
74: total += score.doubleValue();
75: }
76: numScored++;
77: }
78: if (numScored == 0) {
79: mean = null;
80: } else {
81: mean = new Double(total / numScored);
82: }
83: }
84: }
|