Skip to content

Commit

Permalink
SAK-29117 when viewing an individual student's course grade, differen…
Browse files Browse the repository at this point in the history
…t calculations were being done in the

getStudentCourseGradeRecord method than were being done in the All Grades page that uses getPointsEarnedCourseGradeRecords.
So this commit removes getStudentCourseGradeRecord because it is incorrect and stays consistent for the individual
student display by calling the same method getPointsEarnedCourseGradeRecords.
  • Loading branch information
ottenhoff committed Mar 4, 2015
1 parent 6c602da commit 5ab6fc6
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 683 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -707,30 +707,6 @@ public void saveGradeAndCommentForStudent(String gradebookUid, Long gradableObje
public void saveGradesAndComments(String gradebookUid, Long gradableObjectId, List<GradeDefinition> gradeDefList)
throws InvalidGradeException, GradebookNotFoundException, AssessmentNotFoundException;

/**
* Get fixed grades for students by using course grade scale.
* @param gradebookUid
* @return Map of enrollment displayId as key, grade as value
*
*/
public Map getFixedGrade(String gradebookUid);

/**
* Get fixed earned points for students by using course grade scale.
* @param gradebookUid
* @return Map of enrollment displayId as key, point as value string
*
*/
public Map getFixedPoint(String gradebookUid);

/**
* Get old earned points for students by using letter grade scale.
* @param gradebookUid
* @return Map of enrollment displayId as key, point as value string
*
*/
public Map getOldPoint(String gradebookUid);

/**
*
* @param gradebookUid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2087,356 +2087,6 @@ private Double convertInputGradeToPoints(int gradeEntryType, LetterGradePercentM

return convertedValue;
}

private List getTotalPointsEarnedInternalFixing(final Long gradebookId, final String studentId, final Session session, final Gradebook gradebook, final List categories, List<AssignmentGradeRecord> studentGradeRecs)
{
double totalPointsEarned = 0;
double literalTotalPointsEarned = 0;
Iterator scoresIter = session.createQuery(
"select agr.pointsEarned, asn from AssignmentGradeRecord agr, Assignment asn where agr.gradableObject=asn and agr.studentId=:student and asn.gradebook.id=:gbid and asn.removed=false and asn.pointsPossible > 0").
setParameter("student", studentId).
setParameter("gbid", gradebookId).
list().iterator();

List assgnsList = session.createQuery(
"from Assignment as asn where asn.gradebook.id=:gbid and asn.removed=false and asn.notCounted=false and asn.ungraded=false and asn.pointsPossible > 0").
setParameter("gbid", gradebookId).
list();

Map cateScoreMap = new HashMap();
Map cateTotalScoreMap = new HashMap();

Set assignmentsTaken = new HashSet();
while (scoresIter.hasNext()) {
Object[] returned = (Object[])scoresIter.next();
Double pointsEarned = (Double)returned[0];
Assignment go = (Assignment) returned[1];
if (go != null && go.isCounted() && pointsEarned != null) {
boolean skip = false;
for(AssignmentGradeRecord gr : studentGradeRecs){
if(gr.getAssignment().getId().equals(go.getId())){
if(gr.getDroppedFromGrade()){
skip = true;
}
break;
}
}
if(skip){
continue;
}

Double fixingPointsEarned = fixingPointsEarned(pointsEarned, go, gradebook);
if(gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_NO_CATEGORY)
{
totalPointsEarned += fixingPointsEarned.doubleValue();
literalTotalPointsEarned += fixingPointsEarned.doubleValue();
assignmentsTaken.add(go.getId());
}
else if(gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_ONLY_CATEGORY && go != null)
{
totalPointsEarned += fixingPointsEarned.doubleValue();
literalTotalPointsEarned += fixingPointsEarned.doubleValue();
assignmentsTaken.add(go.getId());
}
else if(gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_WEIGHTED_CATEGORY && go != null && categories != null)
{
for(int i=0; i<categories.size(); i++)
{
Category cate = (Category) categories.get(i);
if(cate != null && !cate.isRemoved() && go.getCategory() != null && cate.getId().equals(go.getCategory().getId()))
{
assignmentsTaken.add(go.getId());
literalTotalPointsEarned += fixingPointsEarned.doubleValue();
if(cateScoreMap.get(cate.getId()) != null)
{
cateScoreMap.put(cate.getId(), Double.valueOf(((Double)cateScoreMap.get(cate.getId())).doubleValue() + fixingPointsEarned.doubleValue()));
}
else
{
cateScoreMap.put(cate.getId(), Double.valueOf(fixingPointsEarned));
}
break;
}
}
}
}
}

if(gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_WEIGHTED_CATEGORY && categories != null)
{
Iterator assgnsIter = assgnsList.iterator();
while (assgnsIter.hasNext())
{
Assignment asgn = (Assignment)assgnsIter.next();
if(assignmentsTaken.contains(asgn.getId()))
{
for(int i=0; i<categories.size(); i++)
{
Category cate = (Category) categories.get(i);
if(cate != null && !cate.isRemoved() && asgn.getCategory() != null && cate.getId().equals(asgn.getCategory().getId()))
{
if(cateTotalScoreMap.get(cate.getId()) == null)
{
cateTotalScoreMap.put(cate.getId(), asgn.getPointsPossible());
}
else
{
cateTotalScoreMap.put(cate.getId(), Double.valueOf(((Double)cateTotalScoreMap.get(cate.getId())).doubleValue() + asgn.getPointsPossible().doubleValue()));
}
}
}
}
}
}

if(assignmentsTaken.isEmpty())
totalPointsEarned = -1;

if(gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_WEIGHTED_CATEGORY)
{
for(int i=0; i<categories.size(); i++)
{
Category cate = (Category) categories.get(i);
if(cate != null && !cate.isRemoved() && cateScoreMap.get(cate.getId()) != null && cateTotalScoreMap.get(cate.getId()) != null)
{
totalPointsEarned += ((Double)cateScoreMap.get(cate.getId())).doubleValue() * cate.getWeight().doubleValue() / ((Double)cateTotalScoreMap.get(cate.getId())).doubleValue();
}
}
}

if (log.isDebugEnabled()) log.debug("getTotalPointsEarnedInternal for studentId=" + studentId + " returning " + totalPointsEarned);
List returnList = new ArrayList();
returnList.add(Double.valueOf(totalPointsEarned));
returnList.add(Double.valueOf(literalTotalPointsEarned));
return returnList;
}

private Double fixingPointsEarned(Double pointsEarned, Assignment assignment, Gradebook gradebook)
{
Double pointPossible = assignment.getPointsPossible();
String letterGrade;
if(pointPossible != null && pointPossible.doubleValue() > 0)
{
LetterGradePercentMapping lgpm = getLetterGradePercentMapping(assignment.getGradebook());
letterGrade = lgpm.getGrade(calculateEquivalentPercent(pointPossible, pointsEarned));

GradeMapping gradeMap = gradebook.getSelectedGradeMapping();

if(gradeMap != null)
{
Double rightPercent = gradeMap.getValue(letterGrade);
//there could be no value in the grademap -SAK-22709
if (rightPercent == null)
{
log.warn("no value found in grademap for: " + letterGrade);
return null;
}
BigDecimal rightPercentBD = new BigDecimal(rightPercent);
BigDecimal pointPossibleBD = new BigDecimal(pointPossible);

return Double.valueOf(rightPercentBD.multiply(pointPossibleBD).divide(new BigDecimal(Double.valueOf("100.0"))).doubleValue());
}
}
return null;
}

public Map getFixedGrade(String gradebookUid)
{
HashMap returnMap = new HashMap();

try
{
Gradebook thisGradebook = getGradebook(gradebookUid);

List assignList = getAssignmentsCounted(thisGradebook.getId());
boolean nonAssignment = false;
if(assignList == null || assignList.size() < 1)
{
nonAssignment = true;
}

Long gradebookId = thisGradebook.getId();
CourseGrade courseGrade = getCourseGrade(gradebookId);

Map enrollmentMap;

Map viewableEnrollmentsMap = authz.findMatchingEnrollmentsForViewableCourseGrade(gradebookUid, thisGradebook.getCategory_type(), null, null);
enrollmentMap = new HashMap();

Map enrollmentMapUid = new HashMap();
for (Iterator iter = viewableEnrollmentsMap.keySet().iterator(); iter.hasNext(); )
{
EnrollmentRecord enr = (EnrollmentRecord)iter.next();
enrollmentMap.put(enr.getUser().getUserUid(), enr);
enrollmentMapUid.put(enr.getUser().getUserUid(), enr);
}
List gradeRecords = getPointsEarnedCourseGradeRecordsFixing(courseGrade, enrollmentMap.keySet());
for (Iterator iter = gradeRecords.iterator(); iter.hasNext(); )
{
CourseGradeRecord gradeRecord = (CourseGradeRecord)iter.next();

GradeMapping gradeMap= thisGradebook.getSelectedGradeMapping();

EnrollmentRecord enr = (EnrollmentRecord)enrollmentMapUid.get(gradeRecord.getStudentId());
if(enr != null)
{
if(!nonAssignment)
returnMap.put(enr.getUser().getDisplayId(), (String)gradeMap.getGrade(gradeRecord.getNonNullAutoCalculatedGrade()));
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
return returnMap;
}

public List getPointsEarnedCourseGradeRecordsFixing(final CourseGrade courseGrade, final Collection studentUids) {
HibernateCallback hc = new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException {
if(studentUids == null || studentUids.size() == 0) {
if(log.isInfoEnabled()) log.info("Returning no grade records for an empty collection of student UIDs");
return new ArrayList();
}

Query q = session.createQuery("from CourseGradeRecord as cgr where cgr.gradableObject.id=:gradableObjectId");
q.setLong("gradableObjectId", courseGrade.getId().longValue());
List records = filterAndPopulateCourseGradeRecordsByStudents(courseGrade, q.list(), studentUids);

Long gradebookId = courseGrade.getGradebook().getId();
Gradebook gradebook = getGradebook(gradebookId);
List cates = getCategories(gradebookId);
//double totalPointsPossible = getTotalPointsInternal(gradebookId, session);
//if(log.isDebugEnabled()) log.debug("Total points = " + totalPointsPossible);

// get all of the AssignmentGradeRecords here to avoid repeated db calls
Map<String, List<AssignmentGradeRecord>> gradeRecMap = getGradeRecordMapForStudents(session, gradebookId, studentUids);

// get all of the counted assignments
List<Assignment> countedAssigns = getCountedAssignments(session, gradebookId);

for(Iterator iter = records.iterator(); iter.hasNext();) {
CourseGradeRecord cgr = (CourseGradeRecord)iter.next();
List<AssignmentGradeRecord> studentGradeRecs = gradeRecMap.get(cgr.getStudentId());

applyDropScores(studentGradeRecs);
//double totalPointsEarned = getTotalPointsEarnedInternal(gradebookId, cgr.getStudentId(), session);
List totalEarned = getTotalPointsEarnedInternalFixing(gradebookId, cgr.getStudentId(), session, gradebook, cates, studentGradeRecs);
double totalPointsEarned = ((Double)totalEarned.get(0)).doubleValue();
double literalTotalPointsEarned = ((Double)totalEarned.get(1)).doubleValue();
double totalPointsPossible = getTotalPointsInternal(gradebook, cates, cgr.getStudentId(), studentGradeRecs, countedAssigns, false);
cgr.initNonpersistentFields(totalPointsPossible, totalPointsEarned, literalTotalPointsEarned);
if(log.isDebugEnabled()) log.debug("Points earned = " + cgr.getPointsEarned());
}

return records;
}
};
return (List)getHibernateTemplate().execute(hc);
}

public Map getFixedPoint(String gradebookUid)
{
HashMap returnMap = new HashMap();

try
{
Gradebook thisGradebook = getGradebook(gradebookUid);

List assignList = getAssignmentsCounted(thisGradebook.getId());
boolean nonAssignment = false;
if(assignList == null || assignList.size() < 1)
{
nonAssignment = true;
}

Long gradebookId = thisGradebook.getId();
CourseGrade courseGrade = getCourseGrade(gradebookId);

Map enrollmentMap;

Map viewableEnrollmentsMap = authz.findMatchingEnrollmentsForViewableCourseGrade(gradebookUid, thisGradebook.getCategory_type(), null, null);
enrollmentMap = new HashMap();

Map enrollmentMapUid = new HashMap();
for (Iterator iter = viewableEnrollmentsMap.keySet().iterator(); iter.hasNext(); )
{
EnrollmentRecord enr = (EnrollmentRecord)iter.next();
enrollmentMap.put(enr.getUser().getUserUid(), enr);
enrollmentMapUid.put(enr.getUser().getUserUid(), enr);
}
List gradeRecords = getPointsEarnedCourseGradeRecordsFixing(courseGrade, enrollmentMap.keySet());
for (Iterator iter = gradeRecords.iterator(); iter.hasNext(); )
{
CourseGradeRecord gradeRecord = (CourseGradeRecord)iter.next();

EnrollmentRecord enr = (EnrollmentRecord)enrollmentMapUid.get(gradeRecord.getStudentId());
if(enr != null)
{
if(!nonAssignment)
returnMap.put(enr.getUser().getDisplayId(), gradeRecord.getNonNullAutoCalculatedGrade().toString());
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
return returnMap;
}

public Map getOldPoint(String gradebookUid)
{
HashMap returnMap = new HashMap();

try
{
Gradebook thisGradebook = getGradebook(gradebookUid);

List assignList = getAssignmentsCounted(thisGradebook.getId());
boolean nonAssignment = false;
if(assignList == null || assignList.size() < 1)
{
nonAssignment = true;
}

Long gradebookId = thisGradebook.getId();
CourseGrade courseGrade = getCourseGrade(gradebookId);

Map enrollmentMap;

Map viewableEnrollmentsMap = authz.findMatchingEnrollmentsForViewableCourseGrade(gradebookUid, thisGradebook.getCategory_type(), null, null);
enrollmentMap = new HashMap();

Map enrollmentMapUid = new HashMap();
for (Iterator iter = viewableEnrollmentsMap.keySet().iterator(); iter.hasNext(); )
{
EnrollmentRecord enr = (EnrollmentRecord)iter.next();
enrollmentMap.put(enr.getUser().getUserUid(), enr);
enrollmentMapUid.put(enr.getUser().getUserUid(), enr);
}
List gradeRecords = getPointsEarnedCourseGradeRecords(courseGrade, enrollmentMap.keySet());
for (Iterator iter = gradeRecords.iterator(); iter.hasNext(); )
{
CourseGradeRecord gradeRecord = (CourseGradeRecord)iter.next();

GradeMapping gradeMap= thisGradebook.getSelectedGradeMapping();

EnrollmentRecord enr = (EnrollmentRecord)enrollmentMapUid.get(gradeRecord.getStudentId());
if(enr != null)
{
if(!nonAssignment)
returnMap.put(enr.getUser().getDisplayId(), gradeRecord.getNonNullAutoCalculatedGrade().toString());
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
return returnMap;
}

public int getGradeEntryType(String gradebookUid) {
if (gradebookUid == null) {
Expand Down
Loading

0 comments on commit 5ab6fc6

Please sign in to comment.