Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added normalize column to export grade book to remote gradebook #190

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 6 additions & 3 deletions lms/djangoapps/courseware/grades.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import random
import logging

from contextlib import contextmanager
from django.conf import settings
from django.test.client import RequestFactory
from django.core.cache import cache
Expand Down Expand Up @@ -454,11 +453,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
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ def get_expected_grade_data(
],
'data': [
[
1, u'u1', u'username', u'[email protected]', '', 0.0, 0, 0, 0, 0, 0, 0, 0, 0,
1, u'u1', u'username', u'[email protected]', '', (0.0, 1.0), 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
],
[
2, u'u2', u'username', u'[email protected]', '', 0.3333333333333333, 0, 0, 0,
2, u'u2', u'username', u'[email protected]', '', (1.0, 3.0), 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0.03333333333333333, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0
]
Expand Down
45 changes: 36 additions & 9 deletions lms/djangoapps/instructor/views/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import requests
import urllib

from collections import defaultdict, OrderedDict
from collections import defaultdict, OrderedDict, Counter
from markupsafe import escape
from requests.status_codes import codes
from StringIO import StringIO
Expand All @@ -36,7 +36,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 @@ -238,25 +237,41 @@ 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', '')
if not aname:
msg += "<font color='red'>{text}</font>".format(text=_("Please enter an assignment name"))
else:
allgrades = get_student_grade_summary_data(request, course, get_grades=True, use_offline=use_offline)
allgrades = get_student_grade_summary_data(
request,
course,
get_grades=True,
use_offline=use_offline,
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]}
datatable = {'header': [_('External email'), aname, _('max_pts'), _('normalize')]}
ddata = []
for student in allgrades['students']: # do one by one in case there is a student who has only partial grades
try:
ddata.append([student.email, student.grades[aidx]])
except IndexError:
# 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],
normalize_grades_enable
],
)
else:
log.debug(u'No grade for assignment %(idx)s (%(name)s) for student %(email)s', {
"idx": aidx,
"name": aname,
Expand Down Expand Up @@ -736,8 +751,20 @@ def get_student_grade_summary_data(
else:
add_grade(score.section, score.earned)
else:
category_cnts = Counter()
progress_summary = grades._progress_summary(student, request, course)
for grade_item in gradeset['section_breakdown']:
add_grade(grade_item['label'], grade_item['percent'])
category = grade_item['category']
try:
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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pdpinch @pwilkins

except (IndexError, KeyError):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment explaining when you expect to hit this exception

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually it was @pwilkins work (try, catch). I havent changed it much. I am just loading max points from progress_summery.

@pwilkins can you explain me why you used this try catch statement?

cc @pdpinch

add_grade(grade_item['label'], grade_item['percent'])
category_cnts[category] += 1
student.grades = gtab.get_grade(student.id)

data.append(datarow)
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