learningequality/ka-lite — pull request #182 by bcipolli (2013-07-01 14:26:35+00:00)
Title: User activity logs: initial version

We have been requested to record user activity information for two purposes:
* To see a detailed log of when users are logging in (for instructors, short-term)
* To keep a summary log of user usage (for adminitrators and funding purposes, long-term; teachers, long-term)

To accomplish this, I've implemented the following:
* A new UserLog model. This is local to the device (never sync'd). General to record start, and stop events of any event type. Currently all user activity updates the same event type, creating a record of when the student logged in, last did any activity (watched a video, tried an exercise), and logged out. Currently, total time is from login time to the time of the last activity (not logout time)
* A new UserLogSummary model. This will be sync'd across devices, and is unique based on the device/user/activity/time_period. When UserLog objects are completed, their activity updates the corresponding UserLogSummary object.

To deal with database bloat, I've created the following configuration options:
* USER_LOG_MAX_RECORDS : maximum # of (local-only) records to keep (for reporting purposes) in the UserLog table. Default is 0 (which disables both the UserLog and UserLogSummary functions)
* USER_LOG_SUMMARY_FREQUENCY : how often to create new UserLogSummary entries per device/user. Configurable on the frequency type and quantity (i.e. 1 day, 1 week, [1,2,3,4,6] month(s), 1 year).

The current version is simplified:
* No cross-computer syncing (requires an extension of the safe cross-version syncing, by stamping models with a "version")
* No reports (waiting for the control_panel UI to be put into code review)

The current version has been tested manually on:
* Login/logout events
* Watching video events
* Trying exercises
* USER_LOG_MAX_RECORDS set to 0, 1 and higher
* USER_LOG_SUMMARY_FREQUENCY set to (1, "months")
by watching the debug logs, and verifying the objects in the table manually (via ./manage.py shell_plus)

Tiny passing changes included:
* Removing a duplicate definition of TEST_RUNNER in settings.py
* A failure to locate /favicon.ico on distributed servers