Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
5b461129
Commit
5b461129
authored
Mar 12, 2012
by
Bridger Maxwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small refactor on the grades. Also made the gradebook render a graph for each student
--HG-- branch : bridger-grades
parent
12c3c4cc
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
19 deletions
+44
-19
courseware/grades.py
+44
-19
No files found.
courseware/grades.py
View file @
5b461129
import
courseware.content_parser
as
content_parser
import
courseware.modules
import
logging
import
logging
import
random
import
urllib
import
urllib
from
lxml
import
etree
import
courseware.content_parser
as
content_parser
from
models
import
StudentModule
from
django.conf
import
settings
from
django.conf
import
settings
import
courseware.modules
from
lxml
import
etree
from
models
import
StudentModule
from
student.models
import
UserProfile
from
student.models
import
UserProfile
log
=
logging
.
getLogger
(
"mitx.courseware"
)
log
=
logging
.
getLogger
(
"mitx.courseware"
)
...
@@ -44,6 +44,17 @@ def get_grade(user, problem, cache):
...
@@ -44,6 +44,17 @@ def get_grade(user, problem, cache):
return
(
correct
,
total
)
return
(
correct
,
total
)
def
grade_sheet
(
student
):
def
grade_sheet
(
student
):
"""
This pulls a summary of all problems in the course. It returns a dictionary with two datastructures:
- courseware_summary is a summary of all sections with problems in the course. It is organized as an array of chapters,
each containing an array of sections, each containing an array of scores. This contains information for graded and ungraded
problems, and is good for displaying a course summary with due dates, etc.
- grade_summary is a summary of how the final grade breaks down. It is an array of "sections". Each section can either be
a conglomerate of scores (like labs or homeworks) which has subscores and a totalscore, or a section can be all from one assignment
(such as a midterm or final) and only has a totalscore. Each section has a weight that shows how it contributes to the total grade.
"""
dom
=
content_parser
.
course_file
(
student
)
dom
=
content_parser
.
course_file
(
student
)
course
=
dom
.
xpath
(
'//course/@name'
)[
0
]
course
=
dom
.
xpath
(
'//course/@name'
)[
0
]
xmlChapters
=
dom
.
xpath
(
'//course[@name=$course]/chapter'
,
course
=
course
)
xmlChapters
=
dom
.
xpath
(
'//course[@name=$course]/chapter'
,
course
=
course
)
...
@@ -54,7 +65,7 @@ def grade_sheet(student):
...
@@ -54,7 +65,7 @@ def grade_sheet(student):
response_by_id
[
response
.
module_id
]
=
response
response_by_id
[
response
.
module_id
]
=
response
total_scores
=
{}
total
ed
_scores
=
{}
chapters
=
[]
chapters
=
[]
for
c
in
xmlChapters
:
for
c
in
xmlChapters
:
sections
=
[]
sections
=
[]
...
@@ -93,13 +104,13 @@ def grade_sheet(student):
...
@@ -93,13 +104,13 @@ def grade_sheet(student):
graded_total
=
(
sum
([
score
[
0
]
for
score
in
scores
if
score
[
2
]]),
graded_total
=
(
sum
([
score
[
0
]
for
score
in
scores
if
score
[
2
]]),
sum
([
score
[
1
]
for
score
in
scores
if
score
[
2
]]))
sum
([
score
[
1
]
for
score
in
scores
if
score
[
2
]]))
#Add the graded total to total_scores
#Add the graded total to total
ed
_scores
format
=
s
.
get
(
'format'
)
if
s
.
get
(
'format'
)
else
""
format
=
s
.
get
(
'format'
)
if
s
.
get
(
'format'
)
else
""
subtitle
=
s
.
get
(
'subtitle'
)
if
s
.
get
(
'subtitle'
)
else
format
subtitle
=
s
.
get
(
'subtitle'
)
if
s
.
get
(
'subtitle'
)
else
format
if
format
and
graded_total
[
1
]
>
0
:
if
format
and
graded_total
[
1
]
>
0
:
format_scores
=
total
_scores
[
format
]
if
format
in
total
_scores
else
[]
format_scores
=
total
ed_scores
[
format
]
if
format
in
totaled
_scores
else
[]
format_scores
.
append
(
graded_total
+
(
s
.
get
(
"name"
),)
)
format_scores
.
append
(
graded_total
+
(
s
.
get
(
"name"
),)
)
total_scores
[
format
]
=
format_scores
total
ed
_scores
[
format
]
=
format_scores
score
=
{
'section'
:
s
.
get
(
"name"
),
score
=
{
'section'
:
s
.
get
(
"name"
),
'scores'
:
scores
,
'scores'
:
scores
,
...
@@ -116,6 +127,19 @@ def grade_sheet(student):
...
@@ -116,6 +127,19 @@ def grade_sheet(student):
'sections'
:
sections
,})
'sections'
:
sections
,})
grade_summary
=
grade_summary_6002x
(
totaled_scores
)
return
{
'courseware_summary'
:
chapters
,
'grade_summary'
:
grade_summary
}
def
grade_summary_6002x
(
totaled_scores
):
"""
This function takes the a dictionary of (graded) section scores, and applies the course grading rules to create
the grade_summary. For 6.002x this means homeworks and labs all have equal weight, with the lowest 2 of each
being dropped. There is one midterm and one final.
"""
def
totalWithDrops
(
scores
,
drop_count
):
def
totalWithDrops
(
scores
,
drop_count
):
#Note that this key will sort the list descending
#Note that this key will sort the list descending
sorted_scores
=
sorted
(
enumerate
(
scores
),
key
=
lambda
x
:
-
x
[
1
][
'percentage'
]
)
sorted_scores
=
sorted
(
enumerate
(
scores
),
key
=
lambda
x
:
-
x
[
1
][
'percentage'
]
)
...
@@ -131,7 +155,7 @@ def grade_sheet(student):
...
@@ -131,7 +155,7 @@ def grade_sheet(student):
return
aggregate_score
,
dropped_indices
return
aggregate_score
,
dropped_indices
#Figure the homework scores
#Figure the homework scores
homework_scores
=
total
_scores
[
'Homework'
]
if
'Homework'
in
total
_scores
else
[]
homework_scores
=
total
ed_scores
[
'Homework'
]
if
'Homework'
in
totaled
_scores
else
[]
homework_percentages
=
[]
homework_percentages
=
[]
for
i
in
range
(
12
):
for
i
in
range
(
12
):
if
i
<
len
(
homework_scores
):
if
i
<
len
(
homework_scores
):
...
@@ -153,7 +177,7 @@ def grade_sheet(student):
...
@@ -153,7 +177,7 @@ def grade_sheet(student):
homework_total
,
homework_dropped_indices
=
totalWithDrops
(
homework_percentages
,
2
)
homework_total
,
homework_dropped_indices
=
totalWithDrops
(
homework_percentages
,
2
)
#Figure the lab scores
#Figure the lab scores
lab_scores
=
total
_scores
[
'Lab'
]
if
'Lab'
in
total
_scores
else
[]
lab_scores
=
total
ed_scores
[
'Lab'
]
if
'Lab'
in
totaled
_scores
else
[]
lab_percentages
=
[]
lab_percentages
=
[]
log
.
debug
(
"lab_scores: {0}"
.
format
(
lab_scores
))
log
.
debug
(
"lab_scores: {0}"
.
format
(
lab_scores
))
for
i
in
range
(
12
):
for
i
in
range
(
12
):
...
@@ -196,7 +220,8 @@ def grade_sheet(student):
...
@@ -196,7 +220,8 @@ def grade_sheet(student):
'category'
:
'Homework'
,
'category'
:
'Homework'
,
'subscores'
:
homework_percentages
,
'subscores'
:
homework_percentages
,
'dropped_indices'
:
homework_dropped_indices
,
'dropped_indices'
:
homework_dropped_indices
,
'totalscore'
:
{
'score'
:
homework_total
,
'summary'
:
"Homework Average - {0:.0
%
}"
.
format
(
homework_total
)},
'totalscore'
:
homework_total
,
'totalscore_summary'
:
"Homework Average - {0:.0
%
}"
.
format
(
homework_total
),
'totallabel'
:
'HW Avg'
,
'totallabel'
:
'HW Avg'
,
'weight'
:
0.15
,
'weight'
:
0.15
,
},
},
...
@@ -204,25 +229,25 @@ def grade_sheet(student):
...
@@ -204,25 +229,25 @@ def grade_sheet(student):
'category'
:
'Labs'
,
'category'
:
'Labs'
,
'subscores'
:
lab_percentages
,
'subscores'
:
lab_percentages
,
'dropped_indices'
:
lab_dropped_indices
,
'dropped_indices'
:
lab_dropped_indices
,
'totalscore'
:
{
'score'
:
lab_total
,
'summary'
:
"Lab Average - {0:.0
%
}"
.
format
(
lab_total
)},
'totalscore'
:
lab_total
,
'totalscore_summary'
:
"Lab Average - {0:.0
%
}"
.
format
(
lab_total
),
'totallabel'
:
'Lab Avg'
,
'totallabel'
:
'Lab Avg'
,
'weight'
:
0.15
,
'weight'
:
0.15
,
},
},
{
{
'category'
:
'Midterm'
,
'category'
:
'Midterm'
,
'totalscore'
:
{
'score'
:
midterm_percentage
,
'summary'
:
"Midterm - {0:.0
%
} ({1}/{2})"
.
format
(
midterm_percentage
,
midterm_score
[
0
],
midterm_score
[
1
])},
'totalscore'
:
midterm_percentage
,
'totalscore_summary'
:
"Midterm - {0:.0
%
} ({1}/{2})"
.
format
(
midterm_percentage
,
midterm_score
[
0
],
midterm_score
[
1
]),
'totallabel'
:
'Midterm'
,
'totallabel'
:
'Midterm'
,
'weight'
:
0.30
,
'weight'
:
0.30
,
},
},
{
{
'category'
:
'Final'
,
'category'
:
'Final'
,
'totalscore'
:
{
'score'
:
final_percentage
,
'summary'
:
"Final - {0:.0
%
} ({1}/{2})"
.
format
(
final_percentage
,
final_score
[
0
],
final_score
[
1
])},
'totalscore'
:
final_percentage
,
'totalscore_summary'
:
"Final - {0:.0
%
} ({1}/{2})"
.
format
(
final_percentage
,
final_score
[
0
],
final_score
[
1
]),
'totallabel'
:
'Final'
,
'totallabel'
:
'Final'
,
'weight'
:
0.40
,
'weight'
:
0.40
,
}
}
]
]
return
{
'grade_summary'
:
grade_summary
,
return
grade_summary
'chapters'
:
chapters
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment