learningequality/ka-lite — pull request #564 by bcipolli (2013-08-25 21:02:36+00:00)
Title: IDOC: Track teacher activity (login time and # reports viewed)

This is dependent on #550 and #562 (to avoid merge conflicts).

Summary:
I set out to address #549 (tracking teacher usage). In doing so, I found a bug in UserLog code that can cause tracking total login time unreliable. I also had to update 3 queries to fully allow logging user activity of more than a single type.

Issues:
* NNU needs to be able to track basic metrics of teacher activity in KA Lite, to examine *teacher* engagement with student performance. We have no recorded metrics for teachers.
* UserLog attempts to be efficient by setting a max # of log entries. However, if this is set lower than the max # of concurrent users, then a log will be deleted before it is completed. This will cause the total time of that activity to be lost (but the fact that that activity happened will be recorded). So the # of logins will be right, but the total login time can be lost if the # of max log entries is not set high enough.

Changes:
* Add a new "activity" type (coachreports) to the existing activity type ("login") that is recorded.
* Add triggers to record that activity type (in the tabular_view views code directly), and in the api call for the others.
* Add code in the same place to trigger an update on the teacher's login activity--so we record the total time between first and last coach reports during a login session (and call that teacher "login time")
* Update code to query the "current user log" based not just on username, but also on activity type, so that UserLog of different activity types can be started/updated/ended independently. This was never necessary before, because there was only 1 activity type ("login")
* change `USER_LOG_MAX_ENTRIES` to `USER_LOG_MAX_ENTRIES_PER_USER`, such that there are no concurrency issues. Note that this constant name is a misnomer--we now keep up to `USER_LOG_MAX_ENTRIES_PER_USER` per user AND activity_type, meaning that up to 2*`USER_LOG_MAX_ENTRIES_PER_USER` can be stored (activity_type=login, coachreport)
* Updated facility_usage control panel view, so that it only displays student information
* Made a simple function to test if UserLog functionality is enabled or not (to avoid referencing internal constants outside main/models.py)

Future:
* Add views / reports for viewing teacher data.

Tests:
* Tested UserLog extensively across multiple users (but not simultaneous logins)
* Tested same actions with UserLog disabled.
* Tested control panel reports