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
234fb813
Commit
234fb813
authored
Sep 20, 2012
by
Bridger Maxwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed grades.grade to use new xmodule API. Now properly explores descriptor tree.
parent
28826b8a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
20 deletions
+38
-20
lms/djangoapps/courseware/grades.py
+38
-20
No files found.
lms/djangoapps/courseware/grades.py
View file @
234fb813
...
@@ -27,6 +27,30 @@ def yield_module_descendents(module):
...
@@ -27,6 +27,30 @@ def yield_module_descendents(module):
stack
.
extend
(
next_module
.
get_display_items
()
)
stack
.
extend
(
next_module
.
get_display_items
()
)
yield
next_module
yield
next_module
def
yield_dynamic_descriptor_descendents
(
descriptor
,
module_creator
):
"""
This returns all of the descendants of a descriptor. If the descriptor
has dynamic children, the module will be created using module_creator
and the children (as descriptors) of that module will be returned.
"""
def
get_dynamic_descriptor_children
(
descriptor
):
if
descriptor
.
has_dynamic_children
():
module
=
module_creator
(
descriptor
)
children_locations
=
module
.
get_children_locations
()
return
[
descriptor
.
system
.
load_item
(
child_location
)
for
child_location
in
child_locations
]
else
:
return
descriptor
.
get_children
()
stack
=
get_dynamic_descriptor_children
(
descriptor
)
stack
.
reverse
()
while
len
(
stack
)
>
0
:
next_descriptor
=
stack
.
pop
()
stack
.
extend
(
get_dynamic_descriptor_children
(
next_descriptor
)
)
yield
next_descriptor
def
yield_problems
(
request
,
course
,
student
):
def
yield_problems
(
request
,
course
,
student
):
"""
"""
Return an iterator over capa_modules that this student has
Return an iterator over capa_modules that this student has
...
@@ -128,7 +152,7 @@ def grade(student, request, course, student_module_cache=None, keep_raw_scores=F
...
@@ -128,7 +152,7 @@ def grade(student, request, course, student_module_cache=None, keep_raw_scores=F
section_name
=
section_descriptor
.
metadata
.
get
(
'display_name'
)
section_name
=
section_descriptor
.
metadata
.
get
(
'display_name'
)
should_grade_section
=
False
should_grade_section
=
False
# 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 we haven't seen a single problem in the section, we don't have to grade it at all! We can assume 0%
for
moduledescriptor
in
section
[
'xmoduledescriptors'
]:
for
moduledescriptor
in
section
[
'xmoduledescriptors'
]:
if
student_module_cache
.
lookup
(
if
student_module_cache
.
lookup
(
course
.
id
,
moduledescriptor
.
category
,
moduledescriptor
.
location
.
url
()):
course
.
id
,
moduledescriptor
.
category
,
moduledescriptor
.
location
.
url
()):
...
@@ -137,23 +161,16 @@ def grade(student, request, course, student_module_cache=None, keep_raw_scores=F
...
@@ -137,23 +161,16 @@ def grade(student, request, course, student_module_cache=None, keep_raw_scores=F
if
should_grade_section
:
if
should_grade_section
:
scores
=
[]
scores
=
[]
# TODO: We need the request to pass into here. If we could forgo that, our arguments
# would be simpler
section_module
=
get_module
(
student
,
request
,
section_descriptor
.
location
,
student_module_cache
,
course
.
id
)
if
section_module
is
None
:
# student doesn't have access to this module, or something else
# went wrong.
continue
#TODO: This won't get all problems, will it? They could be hidden in a sub-child. What is a better
def
create_module
(
descriptor
):
# way of getting all of the children as descriptors?
# TODO: We need the request to pass into here. If we could forgo that, our arguments
module_locations
=
section_module
.
definition
.
get
(
'children'
,
[])
# would be simpler
for
module_location
in
module_locations
:
return
get_module
(
student
,
request
,
descriptor
.
location
,
module_descriptor
=
section_module
.
descriptor
.
system
.
load_item
(
module_location
)
student_module_cache
,
course
.
id
)
(
correct
,
total
)
=
get_score
(
course
.
id
,
student
,
module_descriptor
,
section_module
.
system
,
student_module_cache
)
for
module_descriptor
in
yield_dynamic_descriptor_descendents
(
section_descriptor
,
create_module
):
(
correct
,
total
)
=
get_score
(
course
.
id
,
student
,
module_descriptor
,
create_module
,
student_module_cache
)
if
correct
is
None
and
total
is
None
:
if
correct
is
None
and
total
is
None
:
continue
continue
...
@@ -277,7 +294,8 @@ def progress_summary(student, request, course, grader, student_module_cache):
...
@@ -277,7 +294,8 @@ def progress_summary(student, request, course, grader, student_module_cache):
module_descriptor
=
course
.
system
.
load_item
(
module_location
)
module_descriptor
=
course
.
system
.
load_item
(
module_location
)
course_id
=
course
.
id
course_id
=
course
.
id
(
correct
,
total
)
=
get_score
(
course_id
,
student
,
module_descriptor
,
section_module
.
system
,
student_module_cache
)
module_creator
=
lambda
decriptor
:
section_module
.
system
.
get_module
(
descriptor
.
location
)
(
correct
,
total
)
=
get_score
(
course_id
,
student
,
module_descriptor
,
module_creator
,
student_module_cache
)
if
correct
is
None
and
total
is
None
:
if
correct
is
None
and
total
is
None
:
continue
continue
...
@@ -306,7 +324,7 @@ def progress_summary(student, request, course, grader, student_module_cache):
...
@@ -306,7 +324,7 @@ def progress_summary(student, request, course, grader, student_module_cache):
return
chapters
return
chapters
def
get_score
(
course_id
,
user
,
problem_descriptor
,
xmodule_system
,
student_module_cache
):
def
get_score
(
course_id
,
user
,
problem_descriptor
,
module_creator
,
student_module_cache
):
"""
"""
Return the score for a user on a problem, as a tuple (correct, total).
Return the score for a user on a problem, as a tuple (correct, total).
...
@@ -326,7 +344,7 @@ def get_score(course_id, user, problem_descriptor, xmodule_system, student_modul
...
@@ -326,7 +344,7 @@ def get_score(course_id, user, problem_descriptor, xmodule_system, student_modul
if
not
instance_module
:
if
not
instance_module
:
# If the problem was not in the cache, we need to instantiate the problem.
# If the problem was not in the cache, we need to instantiate the problem.
# Otherwise, the max score (cached in instance_module) won't be available
# Otherwise, the max score (cached in instance_module) won't be available
problem
=
xmodule_system
.
get_module
(
problem_descriptor
.
location
)
problem
=
module_creator
(
problem_descriptor
)
instance_module
=
get_instance_module
(
course_id
,
user
,
problem
,
student_module_cache
)
instance_module
=
get_instance_module
(
course_id
,
user
,
problem
,
student_module_cache
)
# If this problem is ungraded/ungradable, bail
# If this problem is ungraded/ungradable, bail
...
...
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