Skip to content

Commit

Permalink
Added normalize column and checkbox in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
amir-qayyum-khan committed Feb 4, 2016
1 parent d924c80 commit c338d8b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 78 deletions.
119 changes: 49 additions & 70 deletions lms/djangoapps/courseware/grades.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,85 +382,64 @@ def _grade(student, request, course, keep_raw_scores, field_data_cache, scores_c
# TODO This block is causing extra savepoints to be fired that are empty because no queries are executed
# during the loop. When refactoring this code please keep this outer_atomic call in mind and ensure we
# are not making unnecessary database queries.
should_grade_section = any(
descriptor.always_recalculate_grades for descriptor in section['xmoduledescriptors']
)

# If there are no problems that always have to be regraded, check to
# see if any of our locations are in the scores from the submissions
# API. If scores exist, we have to calculate grades for this section.
if not should_grade_section:
should_grade_section = any(
descriptor.location.to_deprecated_string() in submissions_scores
for descriptor in section['xmoduledescriptors']
# If we haven't seen a single problem in the section, we don't have
# to grade it at all! We can assume 0%
scores = []

def create_module(descriptor):
"""creates an XModule instance given a descriptor"""
# TODO: We need the request to pass into here. If we could forego that, our arguments
# would be simpler
return get_module_for_descriptor(
student, request, descriptor, field_data_cache, course.id, course=course
)

if not should_grade_section:
should_grade_section = any(
descriptor.location in scores_client
for descriptor in section['xmoduledescriptors']
descendants = yield_dynamic_descriptor_descendants(section_descriptor, student.id, create_module)
for module_descriptor in descendants:
user_access = has_access(
student, 'load', module_descriptor, module_descriptor.location.course_key
)
if not user_access:
continue

# If we haven't seen a single problem in the section, we don't have
# to grade it at all! We can assume 0%
if should_grade_section:
scores = []

def create_module(descriptor):
'''creates an XModule instance given a descriptor'''
# TODO: We need the request to pass into here. If we could forego that, our arguments
# would be simpler
return get_module_for_descriptor(
student, request, descriptor, field_data_cache, course.id, course=course
)
(correct, total) = get_score(
student,
module_descriptor,
create_module,
scores_client,
submissions_scores,
max_scores_cache,
)
if correct is None and total is None:
continue

descendants = yield_dynamic_descriptor_descendants(section_descriptor, student.id, create_module)
for module_descriptor in descendants:
user_access = has_access(
student, 'load', module_descriptor, module_descriptor.location.course_key
)
if not user_access:
continue

(correct, total) = get_score(
student,
module_descriptor,
create_module,
scores_client,
submissions_scores,
max_scores_cache,
)
if correct is None and total is None:
continue

if settings.GENERATE_PROFILE_SCORES: # for debugging!
if total > 1:
correct = random.randrange(max(total - 2, 1), total + 1)
else:
correct = total

graded = module_descriptor.graded
if not total > 0:
# We simply cannot grade a problem that is 12/0, because we might need it as a percentage
graded = False

scores.append(
Score(
correct,
total,
graded,
module_descriptor.display_name_with_default,
module_descriptor.location
)
if settings.GENERATE_PROFILE_SCORES: # for debugging!
if total > 1:
correct = random.randrange(max(total - 2, 1), total + 1)
else:
correct = total

graded = module_descriptor.graded
if not total > 0:
# We simply cannot grade a problem that is 12/0, because we might need it as a percentage
graded = False

scores.append(
Score(
correct,
total,
graded,
module_descriptor.display_name_with_default,
module_descriptor.location
)
)

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

#Add the graded total to totaled_scores
# Add the graded total to totaled_scores
if graded_total.possible > 0:
format_scores.append(graded_total)
else:
Expand Down
21 changes: 14 additions & 7 deletions lms/djangoapps/instructor/views/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,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 @@ -249,23 +250,26 @@ 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 @@ -745,15 +749,18 @@ def get_student_grade_summary_data(
if get_score_max is True:
add_grade(score.section, score.earned, score.possible)
else:
add_grade(score.section, score.earned)
add_grade(score.section, (score.earned / score.possible), 1)
else:
category_cnts = Counter()
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)
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'])
category_cnts[category] += 1
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 @@ -240,7 +240,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 c338d8b

Please sign in to comment.