Skip to content

Commit

Permalink
Added normalize column and checkbox in UI and fixed grade max point i…
Browse files Browse the repository at this point in the history
…ssue using gradebook summery
  • Loading branch information
amir-qayyum-khan committed Feb 10, 2016
1 parent fb9fcf2 commit a72a8dd
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
6 changes: 3 additions & 3 deletions common/lib/xmodule/xmodule/graders.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Score = namedtuple("Score", "earned possible graded section module_id")


def aggregate_scores(scores, section_name="summary"):
def aggregate_scores(scores, section_name="summary", section_location=None):
"""
scores: A list of Score objects
returns: A tuple (all_total, graded_total).
Expand All @@ -32,15 +32,15 @@ def aggregate_scores(scores, section_name="summary"):
total_possible,
False,
section_name,
None
section_location
)
#selecting only graded things
graded_total = Score(
total_correct_graded,
total_possible_graded,
True,
section_name,
None
section_location
)

return all_total, graded_total
Expand Down
9 changes: 7 additions & 2 deletions lms/djangoapps/courseware/grades.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ def create_module(descriptor):

(correct, total) = get_score(
course.id, student, module_descriptor, create_module, scores_cache=submissions_scores

)
if correct is None and total is None:
continue
Expand All @@ -256,11 +257,15 @@ def create_module(descriptor):
)
)

_, graded_total = graders.aggregate_scores(scores, section_name)
_, graded_total = graders.aggregate_scores(
scores,
section_name,
section_location=section_descriptor.location
)
if keep_raw_scores:
raw_scores += scores
else:
graded_total = Score(0.0, 1.0, True, section_name, None)
graded_total = Score(0.0, 1.0, True, section_name, section_descriptor.location)

#Add the graded total to totaled_scores
if graded_total.possible > 0:
Expand Down
35 changes: 24 additions & 11 deletions lms/djangoapps/instructor/views/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
from courseware import grades
from courseware.access import has_access
from courseware.courses import get_course_with_access, get_cms_course_link
from courseware.models import StudentModule
from django_comment_common.models import FORUM_ROLE_ADMINISTRATOR
from django_comment_client.utils import has_forum_access
from instructor.offline_gradecalc import student_grades, offline_grades_available
Expand Down Expand Up @@ -235,6 +234,7 @@ def domatch(student):
elif action in ['Display grades for assignment', 'Export grades for assignment to remote gradebook',
'Export CSV file of grades for assignment']:

normalize_grades_enable = 1 if request.POST.get('normalize_grades', None) else 0
log.debug(action)
datatable = {}
aname = request.POST.get('assignment_name', '')
Expand All @@ -246,23 +246,27 @@ def domatch(student):
course,
get_grades=True,
use_offline=use_offline,
get_score_max=True
get_score_max=False if normalize_grades_enable == 1 else True
)

if aname not in allgrades['assignments']:
msg += "<font color='red'>{text}</font>".format(
text=_("Invalid assignment name '{name}'").format(name=aname)
)
else:
aidx = allgrades['assignments'].index(aname)
datatable = {'header': [_('External email'), aname, _('max_pts')]}
datatable = {'header': [_('External email'), aname, _('max_pts'), _('normalize')]}
ddata = []
# do one by one in case there is a student who has only partial grades
for student in allgrades['students']:
if len(student.grades) >= aidx and student.grades[aidx] is not None:
ddata.append(
[student.email,
student.grades[aidx][0],
student.grades[aidx][1]]
[
student.email,
student.grades[aidx][0],
student.grades[aidx][1],
normalize_grades_enable
],
)
else:
log.debug(u'No grade for assignment %(idx)s (%(name)s) for student %(email)s', {
Expand Down Expand Up @@ -720,7 +724,10 @@ def get_graded_components(self):
return self.components.keys()


def get_student_grade_summary_data(request, course, get_grades=True, get_raw_scores=False, use_offline=False):
def get_student_grade_summary_data(
request, course, get_grades=True, get_raw_scores=False,
use_offline=False, get_score_max=False
):
"""
Return data arrays with student identity and grades for specified course.
Expand Down Expand Up @@ -767,14 +774,20 @@ def get_student_grade_summary_data(request, course, get_grades=True, get_raw_sco
add_grade(score.section, getattr(score, 'earned', score[0]))
else:
category_cnts = Counter()
progress_summary = grades._progress_summary(student, request, course)
for grade_item in gradeset['section_breakdown']:
category = grade_item['category']
try:
earned = gradeset['totaled_scores'][category][category_cnts[category]].earned
possible = gradeset['totaled_scores'][category][category_cnts[category]].possible
add_grade(grade_item['label'], earned, possible=possible)
location = gradeset['totaled_scores'][category][category_cnts[category]].module_id
earned, possible = progress_summary.score_for_module(location)
if get_score_max is True:
add_grade(grade_item['label'], earned, possible=possible)
else:
add_grade(grade_item['label'], grade_item['percent'], possible=1)
except (IndexError, KeyError):
add_grade(grade_item['label'], grade_item['percent'])
# if exercise is in 'section_breakdown' dict but not in 'totaled_scores' because either
# student has not attempted it or it is not grade able.
add_grade(grade_item['label'], grade_item['percent'], possible=1)
category_cnts[category] += 1
student.grades = gtab.get_grade(student.id)

Expand Down
4 changes: 3 additions & 1 deletion lms/templates/courseware/legacy_instructor_dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ <h3>${_("Export grades to remote gradebook")}</h3>
<br/>
<br/>
</li>
<li>${_("Assignment name:")} <input type="text" name="assignment_name" size=40 >
<li>${_("Assignment name:")} <input type="text" name="assignment_name" size=40 > <input
type="checkbox" name="normalize_grades" id="normalize_grades" checked="checked" /> <label style="display:inline"
for="normalize_grades">${_("Normalize Grades")}</label>
<br/>
<br/>
<input type="submit" name="action" value="Display grades for assignment">
Expand Down

0 comments on commit a72a8dd

Please sign in to comment.