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
91cb371d
Commit
91cb371d
authored
Dec 19, 2014
by
Braden MacDonald
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Emit per-student library content events to the tracking log for analytics
parent
e4ea28f7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
4 deletions
+30
-4
common/lib/xmodule/xmodule/library_content_module.py
+30
-4
No files found.
common/lib/xmodule/xmodule/library_content_module.py
View file @
91cb371d
...
...
@@ -221,24 +221,50 @@ class LibraryContentModule(LibraryContentFields, XModule, StudioEditableModule):
# Already done:
return
self
.
_selected_set
# pylint: disable=access-member-before-definition
# Determine which of our children we will show:
jsonify_block_keys
=
lambda
keys
:
[
unicode
(
self
.
location
.
course_key
.
make_usage_key
(
*
key
))
for
key
in
keys
]
selected
=
set
(
tuple
(
k
)
for
k
in
self
.
selected
)
# set of (block_type, block_id) tuples
valid_block_keys
=
set
([(
c
.
block_type
,
c
.
block_id
)
for
c
in
self
.
children
])
# pylint: disable=no-member
# Remove any selected blocks that are no longer valid:
selected
-=
(
selected
-
valid_block_keys
)
invalid_block_keys
=
(
selected
-
valid_block_keys
)
if
invalid_block_keys
:
selected
-=
invalid_block_keys
# Publish an event for analytics purposes:
self
.
runtime
.
publish
(
self
,
"edx.librarycontentblock.content.removed"
,
{
"location"
:
unicode
(
self
.
location
),
"blocks"
:
jsonify_block_keys
(
invalid_block_keys
),
"reason"
:
"invalid"
,
# Deleted from library or library being used has changed
})
# If max_count has been decreased, we may have to drop some previously selected blocks:
overlimit_block_keys
=
set
()
while
len
(
selected
)
>
self
.
max_count
:
selected
.
pop
()
overlimit_block_keys
.
add
(
selected
.
pop
())
if
overlimit_block_keys
:
# Publish an event for analytics purposes:
self
.
runtime
.
publish
(
self
,
"edx.librarycontentblock.content.removed"
,
{
"location"
:
unicode
(
self
.
location
),
"blocks"
:
jsonify_block_keys
(
overlimit_block_keys
),
"reason"
:
"overlimit"
,
})
# Do we have enough blocks now?
num_to_add
=
self
.
max_count
-
len
(
selected
)
if
num_to_add
>
0
:
added_block_keys
=
None
# We need to select [more] blocks to display to this user:
pool
=
valid_block_keys
-
selected
if
self
.
mode
==
"random"
:
pool
=
valid_block_keys
-
selected
num_to_add
=
min
(
len
(
pool
),
num_to_add
)
selected
|
=
set
(
random
.
sample
(
pool
,
num_to_add
))
added_block_keys
=
set
(
random
.
sample
(
pool
,
num_to_add
))
# We now have the correct n random children to show for this user.
else
:
raise
NotImplementedError
(
"Unsupported mode."
)
selected
|=
added_block_keys
if
added_block_keys
:
# Publish an event for analytics purposes:
self
.
runtime
.
publish
(
self
,
"edx.librarycontentblock.content.assigned"
,
{
"location"
:
unicode
(
self
.
location
),
"added"
:
jsonify_block_keys
(
added_block_keys
),
"result"
:
jsonify_block_keys
(
selected
),
})
# Save our selections to the user state, to ensure consistency:
self
.
selected
=
list
(
selected
)
# TODO: this doesn't save from the LMS "Progress" page.
# Cache the results
...
...
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