Skip to content

Commit c338d8b

Browse files
Added normalize column and checkbox in UI
1 parent d924c80 commit c338d8b

File tree

3 files changed

+66
-78
lines changed

3 files changed

+66
-78
lines changed

lms/djangoapps/courseware/grades.py

Lines changed: 49 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -382,85 +382,64 @@ def _grade(student, request, course, keep_raw_scores, field_data_cache, scores_c
382382
# TODO This block is causing extra savepoints to be fired that are empty because no queries are executed
383383
# during the loop. When refactoring this code please keep this outer_atomic call in mind and ensure we
384384
# are not making unnecessary database queries.
385-
should_grade_section = any(
386-
descriptor.always_recalculate_grades for descriptor in section['xmoduledescriptors']
387-
)
388385

389-
# If there are no problems that always have to be regraded, check to
390-
# see if any of our locations are in the scores from the submissions
391-
# API. If scores exist, we have to calculate grades for this section.
392-
if not should_grade_section:
393-
should_grade_section = any(
394-
descriptor.location.to_deprecated_string() in submissions_scores
395-
for descriptor in section['xmoduledescriptors']
386+
# If we haven't seen a single problem in the section, we don't have
387+
# to grade it at all! We can assume 0%
388+
scores = []
389+
390+
def create_module(descriptor):
391+
"""creates an XModule instance given a descriptor"""
392+
# TODO: We need the request to pass into here. If we could forego that, our arguments
393+
# would be simpler
394+
return get_module_for_descriptor(
395+
student, request, descriptor, field_data_cache, course.id, course=course
396396
)
397397

398-
if not should_grade_section:
399-
should_grade_section = any(
400-
descriptor.location in scores_client
401-
for descriptor in section['xmoduledescriptors']
398+
descendants = yield_dynamic_descriptor_descendants(section_descriptor, student.id, create_module)
399+
for module_descriptor in descendants:
400+
user_access = has_access(
401+
student, 'load', module_descriptor, module_descriptor.location.course_key
402402
)
403+
if not user_access:
404+
continue
403405

404-
# If we haven't seen a single problem in the section, we don't have
405-
# to grade it at all! We can assume 0%
406-
if should_grade_section:
407-
scores = []
408-
409-
def create_module(descriptor):
410-
'''creates an XModule instance given a descriptor'''
411-
# TODO: We need the request to pass into here. If we could forego that, our arguments
412-
# would be simpler
413-
return get_module_for_descriptor(
414-
student, request, descriptor, field_data_cache, course.id, course=course
415-
)
406+
(correct, total) = get_score(
407+
student,
408+
module_descriptor,
409+
create_module,
410+
scores_client,
411+
submissions_scores,
412+
max_scores_cache,
413+
)
414+
if correct is None and total is None:
415+
continue
416416

417-
descendants = yield_dynamic_descriptor_descendants(section_descriptor, student.id, create_module)
418-
for module_descriptor in descendants:
419-
user_access = has_access(
420-
student, 'load', module_descriptor, module_descriptor.location.course_key
421-
)
422-
if not user_access:
423-
continue
424-
425-
(correct, total) = get_score(
426-
student,
427-
module_descriptor,
428-
create_module,
429-
scores_client,
430-
submissions_scores,
431-
max_scores_cache,
432-
)
433-
if correct is None and total is None:
434-
continue
435-
436-
if settings.GENERATE_PROFILE_SCORES: # for debugging!
437-
if total > 1:
438-
correct = random.randrange(max(total - 2, 1), total + 1)
439-
else:
440-
correct = total
441-
442-
graded = module_descriptor.graded
443-
if not total > 0:
444-
# We simply cannot grade a problem that is 12/0, because we might need it as a percentage
445-
graded = False
446-
447-
scores.append(
448-
Score(
449-
correct,
450-
total,
451-
graded,
452-
module_descriptor.display_name_with_default,
453-
module_descriptor.location
454-
)
417+
if settings.GENERATE_PROFILE_SCORES: # for debugging!
418+
if total > 1:
419+
correct = random.randrange(max(total - 2, 1), total + 1)
420+
else:
421+
correct = total
422+
423+
graded = module_descriptor.graded
424+
if not total > 0:
425+
# We simply cannot grade a problem that is 12/0, because we might need it as a percentage
426+
graded = False
427+
428+
scores.append(
429+
Score(
430+
correct,
431+
total,
432+
graded,
433+
module_descriptor.display_name_with_default,
434+
module_descriptor.location
455435
)
436+
)
456437

457-
__, graded_total = graders.aggregate_scores(scores, section_name)
458-
if keep_raw_scores:
459-
raw_scores += scores
460-
else:
461-
graded_total = Score(0.0, 1.0, True, section_name, None)
438+
__, graded_total = graders.aggregate_scores(scores, section_name)
439+
if keep_raw_scores:
440+
raw_scores += scores
462441

463-
#Add the graded total to totaled_scores
442+
# Add the graded total to totaled_scores
464443
if graded_total.possible > 0:
465444
format_scores.append(graded_total)
466445
else:

lms/djangoapps/instructor/views/legacy.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ def domatch(student):
238238
elif action in ['Display grades for assignment', 'Export grades for assignment to remote gradebook',
239239
'Export CSV file of grades for assignment']:
240240

241+
normalize_grades_enable = 1 if request.POST.get('normalize_grades', None) else 0
241242
log.debug(action)
242243
datatable = {}
243244
aname = request.POST.get('assignment_name', '')
@@ -249,23 +250,26 @@ def domatch(student):
249250
course,
250251
get_grades=True,
251252
use_offline=use_offline,
252-
get_score_max=True
253+
get_score_max=False if normalize_grades_enable == 1 else True
253254
)
254255
if aname not in allgrades['assignments']:
255256
msg += "<font color='red'>{text}</font>".format(
256257
text=_("Invalid assignment name '{name}'").format(name=aname)
257258
)
258259
else:
259260
aidx = allgrades['assignments'].index(aname)
260-
datatable = {'header': [_('External email'), aname, _('max_pts')]}
261+
datatable = {'header': [_('External email'), aname, _('max_pts'), _('normalize')]}
261262
ddata = []
262263
# do one by one in case there is a student who has only partial grades
263264
for student in allgrades['students']:
264265
if len(student.grades) >= aidx and student.grades[aidx] is not None:
265266
ddata.append(
266-
[student.email,
267-
student.grades[aidx][0],
268-
student.grades[aidx][1]]
267+
[
268+
student.email,
269+
student.grades[aidx][0],
270+
student.grades[aidx][1],
271+
normalize_grades_enable
272+
],
269273
)
270274
else:
271275
log.debug(u'No grade for assignment %(idx)s (%(name)s) for student %(email)s', {
@@ -745,15 +749,18 @@ def get_student_grade_summary_data(
745749
if get_score_max is True:
746750
add_grade(score.section, score.earned, score.possible)
747751
else:
748-
add_grade(score.section, score.earned)
752+
add_grade(score.section, (score.earned / score.possible), 1)
749753
else:
750754
category_cnts = Counter()
751755
for grade_item in gradeset['section_breakdown']:
752756
category = grade_item['category']
753757
try:
754758
earned = gradeset['totaled_scores'][category][category_cnts[category]].earned
755759
possible = gradeset['totaled_scores'][category][category_cnts[category]].possible
756-
add_grade(grade_item['label'], earned, possible=possible)
760+
if get_score_max is True:
761+
add_grade(grade_item['label'], earned, possible=possible)
762+
else:
763+
add_grade(grade_item['label'], grade_item['percent'], possible=1)
757764
except (IndexError, KeyError):
758765
add_grade(grade_item['label'], grade_item['percent'])
759766
category_cnts[category] += 1

lms/templates/courseware/legacy_instructor_dashboard.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ <h3>${_("Export grades to remote gradebook")}</h3>
240240
<br/>
241241
<br/>
242242
</li>
243-
<li>${_("Assignment name:")} <input type="text" name="assignment_name" size=40 >
243+
<li>${_("Assignment name:")} <input type="text" name="assignment_name" size=40 > <input
244+
type="checkbox" name="normalize_grades" id="normalize_grades" checked="checked" /> <label style="display:inline"
245+
for="normalize_grades">${_("Normalize Grades")}</label>
244246
<br/>
245247
<br/>
246248
<input type="submit" name="action" value="Display grades for assignment">

0 commit comments

Comments
 (0)