From 39d6705d6d082b8b8481d83795ca3d90612e68ab Mon Sep 17 00:00:00 2001 From: josephcc Date: Wed, 29 Jun 2016 15:52:49 -0700 Subject: [PATCH 01/30] client api for disabling idle monitor --- client/ts_client.coffee | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/ts_client.coffee b/client/ts_client.coffee index 1991a18..f78ef0c 100644 --- a/client/ts_client.coffee +++ b/client/ts_client.coffee @@ -19,12 +19,15 @@ safeStartMonitor = (threshold, idleOnBlur) -> idleComp = null -TurkServer.enableIdleMonitor = (threshold, idleOnBlur) -> +TurkServer.disableIdleMonitor = () -> if idleComp? # If monitor is already started, stop it before trying new settings idleComp.stop() UserStatus.stopMonitor() if Deps.nonreactive -> UserStatus.isMonitoring() +TurkServer.enableIdleMonitor = (threshold, idleOnBlur) -> + TurkServer.disableIdleMonitor() + idleComp = Deps.autorun -> if TurkServer.inExperiment() safeStartMonitor(threshold, idleOnBlur) From c7f891a42cef51d33c8d06def3f4f348c1fe8afe Mon Sep 17 00:00:00 2001 From: Andrew Mao Date: Fri, 1 Jul 2016 16:32:25 -0400 Subject: [PATCH 02/30] rewrite idle monitor API in JS and add docs --- client/client_api.js | 63 +++++++++++++++++++++++++++++++++++++++++ client/ts_client.coffee | 27 ------------------ 2 files changed, 63 insertions(+), 27 deletions(-) diff --git a/client/client_api.js b/client/client_api.js index 5efffd1..b8d7be9 100644 --- a/client/client_api.js +++ b/client/client_api.js @@ -90,6 +90,69 @@ TurkServer.currentRound = function() { return RoundTimers.findOne({}, { sort: {index: -1} } ); }; +// Called to start the monitor with given settings when in experiment +// Similar to usage in user-status demo: +// https://github.com/mizzao/meteor-user-status +function safeStartMonitor(threshold, idleOnBlur) { + // We run this in an autorun block because it may fail on startup if time + // is not synced. As soon as it succeeds, we are done. + // See https://github.com/mizzao/meteor-user-status/blob/master/monitor.coffee + const settings = { threshold, idleOnBlur }; + + Tracker.autorun((c) => { + try { + UserStatus.startMonitor(settings); + c.stop(); + console.log("Idle monitor started with ", settings); + } catch (e) {} + }); +}; + +function stopMonitor() { + if (Deps.nonreactive(UserStatus.isMonitoring)) { + UserStatus.stopMonitor(); + } +} + +// This Tracker Computation starts and stops idle monitoring as the user +// enters/exits an experiment +let idleComp = null; + +/** + * @summary Stop idle monitoring, if it's currently enabled. + * @locus Client + */ +TurkServer.disableIdleMonitor = function() { + if (idleComp != null) { + idleComp.stop(); + stopMonitor(); + } +}; + +/** + * @summary Start idle monitoring on the client with specific settings, + * automatically activating and deactivating as the user enters experiment + * instances. + * + * See {@link https://github.com/mizzao/meteor-user-status} for detailed + * meanings of the parameters. + * + * @locus Client + * @param threshold Time of inaction before a user is considered inactive. + * @param idleOnBlur Whether to count window blurs as inactivity. + */ +TurkServer.enableIdleMonitor = function(threshold, idleOnBlur) { + // If monitor is already started, stop it before trying new settings + TurkServer.disableIdleMonitor(); + + idleComp = Deps.autorun(() => { + if (TurkServer.inExperiment()) { // This is reactive + safeStartMonitor(threshold, idleOnBlur); + } else { + stopMonitor(); + } + }); +}; /* * Currently internal functions diff --git a/client/ts_client.coffee b/client/ts_client.coffee index f78ef0c..05b9799 100644 --- a/client/ts_client.coffee +++ b/client/ts_client.coffee @@ -7,33 +7,6 @@ TurkServer.batch = -> else return Batches.findOne() -# Called to start the monitor with given settings when in experiment -# Similar to usage in user-status demo -safeStartMonitor = (threshold, idleOnBlur) -> - Deps.autorun (c) -> - try - settings = {threshold, idleOnBlur} - UserStatus.startMonitor(settings) - c.stop() - console.log "Idle monitor started with ", settings - -idleComp = null - -TurkServer.disableIdleMonitor = () -> - if idleComp? - # If monitor is already started, stop it before trying new settings - idleComp.stop() - UserStatus.stopMonitor() if Deps.nonreactive -> UserStatus.isMonitoring() - -TurkServer.enableIdleMonitor = (threshold, idleOnBlur) -> - TurkServer.disableIdleMonitor() - - idleComp = Deps.autorun -> - if TurkServer.inExperiment() - safeStartMonitor(threshold, idleOnBlur) - else - UserStatus.stopMonitor() if Deps.nonreactive -> UserStatus.isMonitoring() - ### Reactive computations ### From 5883051a20c9e370999847918af8060585f0744b Mon Sep 17 00:00:00 2001 From: Elliot Salisbury Date: Tue, 5 Jul 2016 15:04:10 -0700 Subject: [PATCH 03/30] instance initialize handlers run AFTER assignments are added --- server/assigners.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/assigners.js b/server/assigners.js index 93b9cf3..05dae1e 100644 --- a/server/assigners.js +++ b/server/assigners.js @@ -30,12 +30,12 @@ class Assigner { */ assignToNewInstance(assts, treatments) { this.lobby.pluckUsers(_.pluck(assts, "userId")); - + const instance = this.batch.createInstance(treatments); - instance.setup(); for (let asst of assts) { instance.addAssignment(asst); } + instance.setup(); return instance; } From 2c6e373e92e73036584eb8c39271f6eb9d97ab52 Mon Sep 17 00:00:00 2001 From: Elliot Salisbury Date: Mon, 11 Jul 2016 14:05:52 -0700 Subject: [PATCH 04/30] can now get the treatment names from assignment objects serverside --- server/assignment.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/assignment.js b/server/assignment.js index cf784bf..8b106e5 100644 --- a/server/assignment.js +++ b/server/assignment.js @@ -169,6 +169,13 @@ class Assignment { }); } } + /** + * @summary Retrieve the set of treatments that were added to this assignment. + * @returns {Array} Array of Treatment names. + */ + getTreatments() { + return this._data().treatments; + } /** * @summary Send this user to the exit survey. User must be in the lobby. From 6cf9aa87064fa0359c998936f21a8014837c6f82 Mon Sep 17 00:00:00 2001 From: Elliot Salisbury Date: Mon, 18 Jul 2016 15:07:34 -0700 Subject: [PATCH 05/30] if no treatments return an empty array --- server/assignment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/assignment.js b/server/assignment.js index 8b106e5..43c5887 100644 --- a/server/assignment.js +++ b/server/assignment.js @@ -174,7 +174,7 @@ class Assignment { * @returns {Array} Array of Treatment names. */ getTreatments() { - return this._data().treatments; + return this._data().treatments || []; } /** From 9ccd002d0f35270eb3a8c779206d85ea1934bbed Mon Sep 17 00:00:00 2001 From: Elliot Salisbury Date: Mon, 1 Aug 2016 15:32:44 -0700 Subject: [PATCH 06/30] adding a one way mirror button to the admin interface --- admin/util.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/util.html b/admin/util.html index 5f60acf..588c862 100644 --- a/admin/util.html +++ b/admin/util.html @@ -24,7 +24,7 @@