open-craft/edx-platform — pull request #26 by bradenmacdonald (2014-12-20 08:11:47+00:00)
Title: Content libraries analytics enhancements (SOL-121)

This implements support for analytics of content libraries, built to implement the ideas of Brian Wilson and Don Mitchell described on [the Confluence wiki page](https://openedx.atlassian.net/wiki/display/SOL/Content+Libraries) in the section near the top entitled "Analytics Considerations".

## New tracking events:
Two new events will appear in the tracking logs (see example below):

* `edx.librarycontentblock.content.assigned` - indicates that a student has been assigned their subset of blocks. Data includes:
- `location` The BlockUsageLocator of the LibraryContentModule emitting the event
- `added`: the BlockUsageLocator **and LibraryUsageLocator** of any newly-assigned blocks
- `result`: the complete set of blocks now assigned to this student. (will always equal `added` at first, but if `max_count` is increased, `added` may be different)
* `edx.librarycontentblock.content.removed` - indicates that a previously-assigned block is no longer being shown to this student. This should be very rare. Data includes:
- `location` The BlockUsageLocator of the LibraryContentModule emitting the event
- `blocks`: the BlockUsageLocator **and LibraryUsageLocator** of the blocks that were removed
- `reason`: Either `overlimit` (`max_count` was decreased by the course author) or `invalid` (Block was deleted from library or library setting was changed and no longer includes this block)

## Testing Notes
This builds on #25 which stores data in the modulestore differently than previous work on content libraries. If testing this PR or PR 25, **create a new library and a new course** and keep them separate from other content libraries and courses that may already exist on your system.

To test: As the vagrant user you can run `sudo tail -f /edx/var/log/tracking/tracking.log` to watch the tracking log. If you sign in to the LMS as a student and view a course containing a LibraryContent block, the first time that you view the courseware should result in an "edx.librarycontentblock.content.assigned" entry appearing in the logs. This entry should appear as below.

Also the Django admin interface at http://localhost:8000/admin/courseware/studentmodule/ is helpful for resetting the student state for your test student user.

## Example tracking log entry

```json
{
"username": "honor",
"event_type": "edx.librarycontentblock.content.assigned",
"context":{
"user_id":1,
"course_id":"course-v1:BradenX+OVRD_TEST+1",
"path":"/courses/course-v1:BradenX+OVRD_TEST+1/courseware/f61bfa6228e948f59ac1107f6077e00c/1aac970a9128469ea78c8ef1c1d0a965/"
},
"time":"2014-12-20T07:39:18.444373+00:00",
"event":{
"added":[
[
"block-v1:BradenX+OVRD_TEST+1+type@problem+block@68075f0ac45a26a249a8",
"lib-block-v1:BradenX+OVRD+type@problem+block@b4e944b353744fab8cf92e7308a7d27d"
]
],
"location":"block-v1:BradenX+OVRD_TEST+1+type@library_content+block@2e0b3f70b9e6471d8f741e545e0621f7",
"result":[
[
"block-v1:BradenX+OVRD_TEST+1+type@problem+block@68075f0ac45a26a249a8",
"lib-block-v1:BradenX+OVRD+type@problem+block@b4e944b353744fab8cf92e7308a7d27d"
]
]
},
}
```

## TODO:
* Tests - how should this be tested?
* When viewing the course "Progress" page, spurious `assigned` events are emitted, because the XBlock assigns children but isn't able to save its state to the database - so in the future, children will be re-assigned.