You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@senssoft.apache.org by ms...@apache.org on 2017/07/21 21:13:00 UTC

incubator-senssoft-useralejs git commit: SENSSOFT-192: Added basic interval logging on a subset of events.

Repository: incubator-senssoft-useralejs
Updated Branches:
  refs/heads/SENSSOFT-192 [created] 4b6c51cc1


SENSSOFT-192: Added basic interval logging on a subset of events.


Project: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/commit/4b6c51cc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/tree/4b6c51cc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/diff/4b6c51cc

Branch: refs/heads/SENSSOFT-192
Commit: 4b6c51cc1f5047c43a12524e39d79bff85b89dc7
Parents: c8ad449
Author: msbeard <ms...@apache.org>
Authored: Fri Jul 21 17:12:49 2017 -0400
Committer: msbeard <ms...@apache.org>
Committed: Fri Jul 21 17:12:49 2017 -0400

----------------------------------------------------------------------
 package.json          |  2 +-
 src/attachHandlers.js | 11 +++++++
 src/packageLogs.js    | 72 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 84 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/blob/4b6c51cc/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 7875ca1..ff4f7e2 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "useralejs",
-  "version": "0.1.0",
+  "version": "0.2.0",
   "description": "Javascript Client for UserAle",
   "main": "build/userale.js",
   "scripts": {

http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/blob/4b6c51cc/src/attachHandlers.js
----------------------------------------------------------------------
diff --git a/src/attachHandlers.js b/src/attachHandlers.js
index 14f8525..70f3793 100644
--- a/src/attachHandlers.js
+++ b/src/attachHandlers.js
@@ -16,8 +16,10 @@
  */
 
 import { packageLog } from './packageLogs.js';
+import { packageIntervalLog } from './packageLogs';
 
 var events;
+var intervalEvents;
 var bufferBools;
 var bufferedEvents;
 var windowEvents;
@@ -56,6 +58,9 @@ export function defineDetails(config) {
     'resize' : function() { return { 'width' : window.outerWidth, 'height' : window.outerHeight }; }
   };
 
+  //@todo: Investigate drag events and their behavior
+  intervalEvents = ['click', 'focus', 'blur', 'input', 'change', 'mouseover', 'submit'];
+
   windowEvents = ['load', 'blur', 'focus'];
 }
 
@@ -73,6 +78,12 @@ export function attachHandlers(config) {
     }, true);
   });
 
+  intervalEvents.forEach(function(ev) {
+    document.addEventListener(ev, function(e) {
+        packageIntervalLog(e);
+    }, true);
+  });
+
   Object.keys(bufferedEvents).forEach(function(ev) {
     bufferBools[ev] = true;
 

http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/blob/4b6c51cc/src/packageLogs.js
----------------------------------------------------------------------
diff --git a/src/packageLogs.js b/src/packageLogs.js
index 9fa1156..74d0e8c 100644
--- a/src/packageLogs.js
+++ b/src/packageLogs.js
@@ -18,6 +18,15 @@
 var logs;
 var config;
 
+// Interval Logging Globals
+var intervalID;
+var intervalType;
+var intervalPath;
+var intervalTimer;
+var intervalCounter;
+var intervalLog;
+
+
 /**
  * Assigns the config and log container to be used by the logging functions.
  * @param  {Array} newLogs   Log container.
@@ -26,6 +35,12 @@ var config;
 export function initPackager(newLogs, newConfig) {
   logs = newLogs;
   config = newConfig;
+  intervalID = null;
+  intervalType = null;
+  intervalPath = null;
+  intervalTimer = null;
+  intervalCounter = 0;
+  intervalLog = null;
 }
 
 /**
@@ -50,6 +65,7 @@ export function packageLog(e, detailFcn) {
     'clientTime' : Math.floor((e.timeStamp && e.timeStamp > 0) ? config.time(e.timeStamp) : Date.now()),
     'location' : getLocation(e),
     'type' : e.type,
+    'logType': 'raw',
     'userAction' : true,
     'details' : details,
     'userId' : config.userId,
@@ -64,6 +80,62 @@ export function packageLog(e, detailFcn) {
 }
 
 /**
+ * Track intervals and gather details about it.
+ * @param {Object} e
+ * @return boolean
+ */
+export function packageIntervalLog(e) {
+    var target = getSelector(e.target);
+    var path = buildPath(e);
+    var type = e.type;
+    var timestamp = Math.floor((e.timeStamp && e.timeStamp > 0) ? config.time(e.timeStamp) : Date.now());
+
+    // Init - this should only happen once on initialization
+    if (intervalID == null) {
+        intervalID = target;
+        intervalType = type;
+        intervalPath = path;
+        intervalTimer = timestamp;
+        intervalCounter = 0;
+    }
+
+    if (intervalID !== target || intervalType !== type) {
+        // When to create log? On transition end
+        // @todo Possible for intervalLog to not be pushed in the event the interval never ends...
+        intervalLog = {
+            'target': intervalID,
+            'path': intervalPath,
+            'count': intervalCounter,
+            'duration': timestamp - intervalTimer,  // microseconds
+            'location': null,
+            'type': intervalType,
+            'logType': 'interval',
+            'userAction': false,
+            'userId': config.userId,
+            'toolVersion': config.version,
+            'toolName': config.toolName,
+            'useraleVersion': config.useraleVersion
+        };
+
+        logs.push(intervalLog);
+
+        // Reset
+        intervalID = target;
+        intervalType = type;
+        intervalPath = path;
+        intervalTimer = timestamp;
+        intervalCounter = 0;
+    }
+
+    // Interval is still occuring, just update counter
+    if (intervalID == target && intervalType == type) {
+        intervalCounter = intervalCounter + 1;
+    }
+
+    return true;
+}
+
+/**
  * Extracts coordinate information from the event
  * depending on a few browser quirks.
  * @param  {Object} e The event to extract coordinate information from.