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
cc4df3c5
Commit
cc4df3c5
authored
Dec 19, 2014
by
Braden MacDonald
Committed by
Zia Fazal
Apr 07, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Emit per-student library content events to the tracking log for analytics
parent
7ab63ca7
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 @
cc4df3c5
...
@@ -221,24 +221,50 @@ class LibraryContentModule(LibraryContentFields, XModule, StudioEditableModule):
...
@@ -221,24 +221,50 @@ class LibraryContentModule(LibraryContentFields, XModule, StudioEditableModule):
# Already done:
# Already done:
return
self
.
_selected_set
# pylint: disable=access-member-before-definition
return
self
.
_selected_set
# pylint: disable=access-member-before-definition
# Determine which of our children we will show:
# 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
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
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:
# 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:
# 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
:
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?
# Do we have enough blocks now?
num_to_add
=
self
.
max_count
-
len
(
selected
)
num_to_add
=
self
.
max_count
-
len
(
selected
)
if
num_to_add
>
0
:
if
num_to_add
>
0
:
added_block_keys
=
None
# We need to select [more] blocks to display to this user:
# We need to select [more] blocks to display to this user:
pool
=
valid_block_keys
-
selected
if
self
.
mode
==
"random"
:
if
self
.
mode
==
"random"
:
pool
=
valid_block_keys
-
selected
num_to_add
=
min
(
len
(
pool
),
num_to_add
)
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.
# We now have the correct n random children to show for this user.
else
:
else
:
raise
NotImplementedError
(
"Unsupported mode."
)
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:
# Save our selections to the user state, to ensure consistency:
self
.
selected
=
list
(
selected
)
# TODO: this doesn't save from the LMS "Progress" page.
self
.
selected
=
list
(
selected
)
# TODO: this doesn't save from the LMS "Progress" page.
# Cache the results
# 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