User analytics: do smaller refactoring and add comments

This refers to issue #596.
User analytics: make event retrieving method more readable

This refers to issue #596.
User analytics: make code more robust

This commit introduces a Bout class to the useranalytics module. It keeps track
of all events within one bout. Based on this, the logic for creating bouts is
made simpler and more scalable.

This refers to issue #594 and issue #596.